diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 8c6951cf..438e44a2 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -568,6 +568,8 @@ "skipDuration_description": "sets the duration to skip when using the skip buttons on the player bar", "skipPlaylistPage": "skip playlist page", "skipPlaylistPage_description": "when navigating to a playlist, go to the playlist song list page instead of the default page", + "startMinimized": "start minimized", + "startMinimized_description": "start the application in system tray", "theme": "theme", "theme_description": "sets the theme to use for the application", "themeDark": "theme (dark)", diff --git a/src/main/main.ts b/src/main/main.ts index d87aaf36..107c6562 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -206,7 +206,7 @@ const createTray = () => { tray.setContextMenu(contextMenu); }; -const createWindow = async () => { +const createWindow = async (first = true) => { if (isDevelopment) { await installExtensions(); } @@ -350,13 +350,14 @@ const createWindow = async () => { mainWindow.loadURL(resolveHtmlPath('index.html')); + const startWindowMinimized = store.get('window_start_minimized', false) as boolean; + mainWindow.on('ready-to-show', () => { if (!mainWindow) { throw new Error('"mainWindow" is not defined'); } - if (process.env.START_MINIMIZED) { - mainWindow.minimize(); - } else { + + if (!first || !startWindowMinimized) { mainWindow.show(); createWinThumbarButtons(); } @@ -608,7 +609,11 @@ if (!singleInstance) { app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. - if (mainWindow === null) createWindow(); + if (mainWindow === null) createWindow(false); + else if (!mainWindow.isVisible()) { + mainWindow.show(); + createWinThumbarButtons(); + } }); }) .catch(console.log); diff --git a/src/renderer/features/settings/components/window/window-settings.tsx b/src/renderer/features/settings/components/window/window-settings.tsx index 899b328b..2b60be69 100644 --- a/src/renderer/features/settings/components/window/window-settings.tsx +++ b/src/renderer/features/settings/components/window/window-settings.tsx @@ -131,6 +131,31 @@ export const WindowSettings = () => { isHidden: !isElectron(), title: t('setting.exitToTray', { postProcess: 'sentenceCase' }), }, + { + control: ( + { + if (!e) return; + localSettings?.set('window_start_minimized', e.currentTarget.checked); + setSettings({ + window: { + ...settings, + startMinimized: e.currentTarget.checked, + }, + }); + }} + /> + ), + description: t('setting.startMinimized', { + context: 'description', + postProcess: 'sentenceCase', + }), + isHidden: !isElectron(), + title: t('setting.startMinimized', { postProcess: 'sentenceCase' }), + }, ]; return ; diff --git a/src/renderer/store/settings.store.ts b/src/renderer/store/settings.store.ts index bf475b19..1d5aed8c 100644 --- a/src/renderer/store/settings.store.ts +++ b/src/renderer/store/settings.store.ts @@ -267,6 +267,7 @@ export interface SettingsState { disableAutoUpdate: boolean; exitToTray: boolean; minimizeToTray: boolean; + startMinimized: boolean; windowBarStyle: Platform; }; } @@ -575,6 +576,7 @@ const initialState: SettingsState = { disableAutoUpdate: false, exitToTray: false, minimizeToTray: false, + startMinimized: false, windowBarStyle: platformDefaultWindowBarStyle, }, };