Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize to System Tray (bug fix) #451

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/app/src/services/services/electron-app/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class ElectronAppService extends ServiceBase implements RPC.Interface<Ele
// @ts-ignore
hideTrayIcon(): Promise<void> {}
// @ts-ignore
trayIconVisible(): Promise<boolean> {}
// @ts-ignore
addObserver(obs: RPC.ObserverNode<ElectronAppServiceObserver>): Promise<RPC.Subscription> {}
// @ts-ignore
setProvider(provider: RPC.Node<ElectronAppServiceProviderService>): Promise<void> {}
Expand All @@ -53,4 +55,6 @@ export class ElectronAppServiceProviderService extends ServiceBase implements RP
showTrayIcon(): Promise<void> {}
// @ts-ignore
hideTrayIcon(): Promise<void> {}
// @ts-ignore
trayIconVisible(): Promise<boolean> {}
}
4 changes: 4 additions & 0 deletions packages/app/src/services/services/electron-app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ export class ElectronAppServiceImpl extends ElectronAppService implements RPC.In
}
await this.provider.hideTrayIcon();
}

async trayIconVisible() {
return await this.provider?.trayIconVisible() || false;
}

private initPrepareQuit() {
app.on('before-quit', (event) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/app/src/services/services/electron-app/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-ignore: no declaration file
import { setMinimizeToTray } from '../../../app/duck';
import { getAppMinimizeToTrayStatus } from '../../../app/selectors';
import { StationStoreWorker } from '../../../types';
import { RPC } from '../../lib/types';
import { ElectronAppServiceProviderService } from './interface';
Expand All @@ -19,4 +20,8 @@ export class ElectronAppServiceProviderServiceImpl extends ElectronAppServicePro
async hideTrayIcon() {
this.store.dispatch(setMinimizeToTray(false));
}

async trayIconVisible() {
return getAppMinimizeToTrayStatus(this.store.getState()) || false;
}
}
8 changes: 6 additions & 2 deletions packages/app/src/windows/utils/MainWindowManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getUrlToLoad } from '../../utils/dev';
import { isDarwin } from '../../utils/process';
import { getResourceIconPath } from '../../utils/resources';
// @ts-ignore: no declaration file
import { windowCreated } from '../duck';
import GenericWindowManager from './GenericWindowManager';
import services from '../../services/servicesManager';
Expand Down Expand Up @@ -28,8 +29,11 @@ export default class MainWindowManager extends GenericWindowManager {
savePosition: 'main-window',
});

this.on('minimize', () => {
services.browserWindow.hideAllWindows();
this.on('minimize', async () => {
const trayIconVisible = await services.electronApp.trayIconVisible()
if (trayIconVisible) {
services.browserWindow.hideAllWindows();
}
});

await super.load();
Expand Down