mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
fix: minimize to tray not restoring #5581
# Conflicts: # electron/ipc-handler.ts
This commit is contained in:
parent
744894ad7e
commit
f13ad58e9d
5 changed files with 42 additions and 62 deletions
|
|
@ -1,26 +0,0 @@
|
|||
import { BrowserWindow, ipcMain, IpcMainEvent } from 'electron';
|
||||
import { IPC } from './shared-with-frontend/ipc-events.const';
|
||||
import { warn } from 'electron-log/main';
|
||||
import { GlobalConfigState } from '../src/app/features/config/global-config.model';
|
||||
|
||||
let cbs: ((settings: GlobalConfigState) => void)[] = [];
|
||||
export const getSettings = (
|
||||
win: BrowserWindow,
|
||||
cbIN: (settings: GlobalConfigState) => void,
|
||||
): void => {
|
||||
cbs.push(cbIN);
|
||||
win.webContents.send(IPC.TRANSFER_SETTINGS_REQUESTED);
|
||||
};
|
||||
|
||||
ipcMain.on(IPC.TRANSFER_SETTINGS_TO_ELECTRON, getSettingsCb);
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
function getSettingsCb(ev: IpcMainEvent, settings: GlobalConfigState): void {
|
||||
if (cbs.length) {
|
||||
cbs.forEach((cb) => cb(settings));
|
||||
cbs = [];
|
||||
} else {
|
||||
// NOTE: can happen, but is unlikely and unlikely to be a problem
|
||||
warn('getSettingsCb no callbacks left');
|
||||
}
|
||||
}
|
||||
|
|
@ -20,9 +20,10 @@ import { exec } from 'child_process';
|
|||
import { getWin } from './main-window';
|
||||
import { quitApp, showOrFocus } from './various-shared';
|
||||
import { loadSimpleStoreAll, saveSimpleStore } from './simple-store';
|
||||
import { getIsLocked } from './shared-state';
|
||||
import { getIsLocked, setIsMinimizeToTray } from './shared-state';
|
||||
import { BACKUP_DIR, BACKUP_DIR_WINSTORE } from './backup';
|
||||
import { pluginNodeExecutor } from './plugin-node-executor';
|
||||
import { GlobalConfigState } from '../src/app/features/config/global-config.model';
|
||||
|
||||
export const initIpcInterfaces = (): void => {
|
||||
// Initialize plugin node executor (registers IPC handlers)
|
||||
|
|
@ -62,6 +63,9 @@ export const initIpcInterfaces = (): void => {
|
|||
ipcMain.on(IPC.RELOAD_MAIN_WIN, () => getWin().reload());
|
||||
ipcMain.on(IPC.OPEN_PATH, (ev, path: string) => shell.openPath(path));
|
||||
ipcMain.on(IPC.OPEN_EXTERNAL, (ev, url: string) => shell.openExternal(url));
|
||||
ipcMain.on(IPC.TRANSFER_SETTINGS_TO_ELECTRON, (ev, cfg: GlobalConfigState) => {
|
||||
setIsMinimizeToTray(cfg.misc.isMinimizeToTray);
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.SAVE_FILE_DIALOG, async (ev, { filename, data }) => {
|
||||
const result = await dialog.showSaveDialog(getWin(), {
|
||||
|
|
|
|||
|
|
@ -13,17 +13,15 @@ import * as path from 'path';
|
|||
import { join, normalize } from 'path';
|
||||
import { format } from 'url';
|
||||
import { IPC } from './shared-with-frontend/ipc-events.const';
|
||||
import { getSettings } from './get-settings';
|
||||
import { readFileSync, stat } from 'fs';
|
||||
import { error, log } from 'electron-log/main';
|
||||
import { GlobalConfigState } from '../src/app/features/config/global-config.model';
|
||||
import { IS_MAC } from './common.const';
|
||||
import {
|
||||
destroyOverlayWindow,
|
||||
hideOverlayWindow,
|
||||
showOverlayWindow,
|
||||
} from './overlay-indicator/overlay-indicator';
|
||||
import { getIsQuiting, setIsQuiting } from './shared-state';
|
||||
import { getIsMinimizeToTray, getIsQuiting, setIsQuiting } from './shared-state';
|
||||
|
||||
let mainWin: BrowserWindow;
|
||||
|
||||
|
|
@ -325,20 +323,18 @@ const appCloseHandler = (app: App): void => {
|
|||
log('close, isQuiting:', getIsQuiting());
|
||||
if (!getIsQuiting()) {
|
||||
event.preventDefault();
|
||||
getSettings(mainWin, (appCfg: GlobalConfigState) => {
|
||||
if (appCfg && appCfg.misc.isMinimizeToTray && !getIsQuiting()) {
|
||||
mainWin.hide();
|
||||
showOverlayWindow();
|
||||
return;
|
||||
}
|
||||
if (getIsMinimizeToTray()) {
|
||||
mainWin.hide();
|
||||
showOverlayWindow();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ids.length > 0) {
|
||||
log('Actions to wait for ', ids);
|
||||
mainWin.webContents.send(IPC.NOTIFY_ON_CLOSE, ids);
|
||||
} else {
|
||||
_quitApp();
|
||||
}
|
||||
});
|
||||
if (ids.length > 0) {
|
||||
log('Actions to wait for ', ids);
|
||||
mainWin.webContents.send(IPC.NOTIFY_ON_CLOSE, ids);
|
||||
} else {
|
||||
_quitApp();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -364,19 +360,17 @@ const appMinimizeHandler = (app: App): void => {
|
|||
// TODO find reason for the typing error
|
||||
// @ts-ignore
|
||||
mainWin.on('minimize', (event: Event) => {
|
||||
getSettings(mainWin, (appCfg: GlobalConfigState) => {
|
||||
if (appCfg.misc.isMinimizeToTray) {
|
||||
event.preventDefault();
|
||||
mainWin.hide();
|
||||
showOverlayWindow();
|
||||
} else {
|
||||
// For regular minimize (not to tray), also show overlay
|
||||
showOverlayWindow();
|
||||
if (IS_MAC) {
|
||||
app.dock?.show();
|
||||
}
|
||||
if (getIsMinimizeToTray()) {
|
||||
event.preventDefault();
|
||||
mainWin.hide();
|
||||
showOverlayWindow();
|
||||
} else {
|
||||
// For regular minimize (not to tray), also show overlay
|
||||
showOverlayWindow();
|
||||
if (IS_MAC) {
|
||||
app.dock?.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
let isQuiting = false;
|
||||
let isLocked = false;
|
||||
let isMinimizeToTray = false;
|
||||
|
||||
export const getIsQuiting = (): boolean => isQuiting;
|
||||
|
||||
|
|
@ -17,3 +18,9 @@ export const getIsLocked = (): boolean => isLocked;
|
|||
export const setIsLocked = (value: boolean): void => {
|
||||
isLocked = value;
|
||||
};
|
||||
|
||||
export const getIsMinimizeToTray = (): boolean => isMinimizeToTray;
|
||||
|
||||
export const setIsMinimizeToTray = (value: boolean): void => {
|
||||
isMinimizeToTray = value;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ import { TrackingReminderService } from './features/tracking-reminder/tracking-r
|
|||
import { map, take } from 'rxjs/operators';
|
||||
import { IS_MOBILE } from './util/is-mobile';
|
||||
import { warpAnimation, warpInAnimation } from './ui/animations/warp.ani';
|
||||
import { GlobalConfigState } from './features/config/global-config.model';
|
||||
import { AddTaskBarComponent } from './features/tasks/add-task-bar/add-task-bar.component';
|
||||
import { Dir } from '@angular/cdk/bidi';
|
||||
import { MagicSideNavComponent } from './core-ui/magic-side-nav/magic-side-nav.component';
|
||||
|
|
@ -307,13 +306,15 @@ export class AppComponent implements OnDestroy, AfterViewInit {
|
|||
});
|
||||
});
|
||||
|
||||
this._uiHelperService.initElectron();
|
||||
|
||||
window.ea.on(IPC.TRANSFER_SETTINGS_REQUESTED, () => {
|
||||
window.ea.sendAppSettingsToElectron(
|
||||
this._globalConfigService.cfg() as GlobalConfigState,
|
||||
);
|
||||
// Sync settings to electron on change
|
||||
effect(() => {
|
||||
const cfg = this._globalConfigService.cfg();
|
||||
if (cfg) {
|
||||
window.ea.sendAppSettingsToElectron(cfg);
|
||||
}
|
||||
});
|
||||
|
||||
this._uiHelperService.initElectron();
|
||||
} else {
|
||||
// WEB VERSION
|
||||
window.addEventListener('beforeunload', (e) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue