Electron: Properly handle toggling window visibility on Windows (#3902)
This commit is contained in:
parent
15f44b1fd2
commit
9b37c1a77a
@ -4,7 +4,7 @@ import path from 'path';
|
|||||||
import { ElectronEvent } from '../types/electron';
|
import { ElectronEvent } from '../types/electron';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getLastWindow, IS_LINUX, IS_MAC_OS, IS_WINDOWS,
|
focusLastWindow, getLastWindow, IS_LINUX, IS_MAC_OS, IS_WINDOWS,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
const TG_PROTOCOL = 'tg';
|
const TG_PROTOCOL = 'tg';
|
||||||
@ -12,8 +12,6 @@ const TG_PROTOCOL = 'tg';
|
|||||||
let deeplinkUrl: string | undefined;
|
let deeplinkUrl: string | undefined;
|
||||||
|
|
||||||
export function initDeeplink() {
|
export function initDeeplink() {
|
||||||
const window = getLastWindow();
|
|
||||||
|
|
||||||
if (process.defaultApp) {
|
if (process.defaultApp) {
|
||||||
if (process.argv.length >= 2) {
|
if (process.argv.length >= 2) {
|
||||||
app.setAsDefaultProtocolClient(TG_PROTOCOL, process.execPath, [path.resolve(process.argv[1])]);
|
app.setAsDefaultProtocolClient(TG_PROTOCOL, process.execPath, [path.resolve(process.argv[1])]);
|
||||||
@ -35,6 +33,7 @@ export function initDeeplink() {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
deeplinkUrl = url;
|
deeplinkUrl = url;
|
||||||
processDeeplink();
|
processDeeplink();
|
||||||
|
focusLastWindow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -50,14 +49,7 @@ export function initDeeplink() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processDeeplink();
|
processDeeplink();
|
||||||
|
focusLastWindow();
|
||||||
if (window) {
|
|
||||||
if (window.isMinimized()) {
|
|
||||||
window.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.focus();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import {
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
forceQuit, getAppTitle, getLastWindow, store,
|
focusLastWindow, forceQuit, getAppTitle, store,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
const TRAY_ICON_SETTINGS_KEY = 'trayIcon';
|
const TRAY_ICON_SETTINGS_KEY = 'trayIcon';
|
||||||
@ -52,11 +52,7 @@ const tray: TrayHelper = {
|
|||||||
this.instance = new Tray(icon);
|
this.instance = new Tray(icon);
|
||||||
|
|
||||||
const handleOpenFromTray = () => {
|
const handleOpenFromTray = () => {
|
||||||
if (BrowserWindow.getAllWindows().every((window) => !window.isVisible())) {
|
focusLastWindow();
|
||||||
BrowserWindow.getAllWindows().forEach((window) => window.show());
|
|
||||||
} else {
|
|
||||||
getLastWindow()?.focus();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseFromTray = () => {
|
const handleCloseFromTray = () => {
|
||||||
|
|||||||
@ -38,6 +38,14 @@ export function reloadWindows(isAutoUpdateEnabled = true): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function focusLastWindow(): void {
|
||||||
|
if (BrowserWindow.getAllWindows().every((window) => !window.isVisible())) {
|
||||||
|
BrowserWindow.getAllWindows().forEach((window) => window.show());
|
||||||
|
} else {
|
||||||
|
getLastWindow()?.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getAppTitle(chatTitle?: string): string {
|
export function getAppTitle(chatTitle?: string): string {
|
||||||
const appName = app.getName();
|
const appName = app.getName();
|
||||||
|
|
||||||
|
|||||||
@ -93,7 +93,7 @@ export function createWindow(url?: string) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
window.on('close', (event) => {
|
window.on('close', (event) => {
|
||||||
if (IS_MAC_OS || IS_WINDOWS) {
|
if (IS_MAC_OS || (IS_WINDOWS && tray.isEnabled)) {
|
||||||
if (forceQuit.isEnabled) {
|
if (forceQuit.isEnabled) {
|
||||||
app.exit(0);
|
app.exit(0);
|
||||||
forceQuit.disable();
|
forceQuit.disable();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user