[enhancement]: Start minimized (#522)

* [enhancement]: support starting minimized

* show window when dock clicked macos
This commit is contained in:
Kendall Garner 2024-02-23 16:31:17 +00:00 committed by GitHub
parent 77fa723cf8
commit 5caf0d439f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 5 deletions

View File

@ -568,6 +568,8 @@
"skipDuration_description": "sets the duration to skip when using the skip buttons on the player bar", "skipDuration_description": "sets the duration to skip when using the skip buttons on the player bar",
"skipPlaylistPage": "skip playlist page", "skipPlaylistPage": "skip playlist page",
"skipPlaylistPage_description": "when navigating to a playlist, go to the playlist song list page instead of the default 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": "theme",
"theme_description": "sets the theme to use for the application", "theme_description": "sets the theme to use for the application",
"themeDark": "theme (dark)", "themeDark": "theme (dark)",

View File

@ -206,7 +206,7 @@ const createTray = () => {
tray.setContextMenu(contextMenu); tray.setContextMenu(contextMenu);
}; };
const createWindow = async () => { const createWindow = async (first = true) => {
if (isDevelopment) { if (isDevelopment) {
await installExtensions(); await installExtensions();
} }
@ -350,13 +350,14 @@ const createWindow = async () => {
mainWindow.loadURL(resolveHtmlPath('index.html')); mainWindow.loadURL(resolveHtmlPath('index.html'));
const startWindowMinimized = store.get('window_start_minimized', false) as boolean;
mainWindow.on('ready-to-show', () => { mainWindow.on('ready-to-show', () => {
if (!mainWindow) { if (!mainWindow) {
throw new Error('"mainWindow" is not defined'); throw new Error('"mainWindow" is not defined');
} }
if (process.env.START_MINIMIZED) {
mainWindow.minimize(); if (!first || !startWindowMinimized) {
} else {
mainWindow.show(); mainWindow.show();
createWinThumbarButtons(); createWinThumbarButtons();
} }
@ -608,7 +609,11 @@ if (!singleInstance) {
app.on('activate', () => { app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the // 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. // 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); .catch(console.log);

View File

@ -131,6 +131,31 @@ export const WindowSettings = () => {
isHidden: !isElectron(), isHidden: !isElectron(),
title: t('setting.exitToTray', { postProcess: 'sentenceCase' }), title: t('setting.exitToTray', { postProcess: 'sentenceCase' }),
}, },
{
control: (
<Switch
aria-label="Toggle start in tray"
defaultChecked={settings.startMinimized}
disabled={!isElectron()}
onChange={(e) => {
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 <SettingsSection options={windowOptions} />; return <SettingsSection options={windowOptions} />;

View File

@ -267,6 +267,7 @@ export interface SettingsState {
disableAutoUpdate: boolean; disableAutoUpdate: boolean;
exitToTray: boolean; exitToTray: boolean;
minimizeToTray: boolean; minimizeToTray: boolean;
startMinimized: boolean;
windowBarStyle: Platform; windowBarStyle: Platform;
}; };
} }
@ -575,6 +576,7 @@ const initialState: SettingsState = {
disableAutoUpdate: false, disableAutoUpdate: false,
exitToTray: false, exitToTray: false,
minimizeToTray: false, minimizeToTray: false,
startMinimized: false,
windowBarStyle: platformDefaultWindowBarStyle, windowBarStyle: platformDefaultWindowBarStyle,
}, },
}; };