Skip to content

Commit

Permalink
Merge pull request #451 from viktor44/feature/tray_icon_2
Browse files Browse the repository at this point in the history
Minimize to System Tray (bug fix)
  • Loading branch information
viktor44 authored Dec 1, 2024
2 parents e251d5e + 54c980a commit 8cbac5e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
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

0 comments on commit 8cbac5e

Please sign in to comment.