mirror of
https://github.com/rhysd/Mstdn.git
synced 2025-03-13 18:29:15 +01:00
manage focus on toggling window on Windows
This commit is contained in:
parent
840ecde8ef
commit
282b24d7b0
35
main/app.ts
35
main/app.ts
@ -36,20 +36,7 @@ export class App {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.win.menubar) {
|
||||
globalShortcut.register(this.config.hot_key, () => {
|
||||
const mb = this.win.menubar!;
|
||||
if (mb.window.isFocused()) {
|
||||
log.debug('Toggle window: shown -> hidden');
|
||||
mb.hideWindow();
|
||||
} else {
|
||||
log.debug('Toggle window: hidden -> shown');
|
||||
mb.showWindow();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
globalShortcut.register(this.config.hot_key, this.toggleNormalWindow);
|
||||
}
|
||||
globalShortcut.register(this.config.hot_key, () => this.win.toggle());
|
||||
log.debug('Hot key was set to:', this.config.hot_key);
|
||||
}
|
||||
|
||||
@ -62,28 +49,14 @@ export class App {
|
||||
|
||||
const icon = trayIcon(this.config.icon_color);
|
||||
const tray = new Tray(icon);
|
||||
tray.on('click', this.toggleNormalWindow);
|
||||
tray.on('double-click', this.toggleNormalWindow);
|
||||
const toggle = this.win.toggle.bind(this.win);
|
||||
tray.on('click', toggle);
|
||||
tray.on('double-click', toggle);
|
||||
if (IS_DARWIN) {
|
||||
tray.setHighlightMode('never');
|
||||
}
|
||||
}
|
||||
|
||||
private toggleNormalWindow = () => {
|
||||
const win = this.win.browser;
|
||||
if (win.isFocused()) {
|
||||
log.debug('Toggle window: shown -> hidden');
|
||||
if (IS_DARWIN) {
|
||||
app.hide();
|
||||
} else {
|
||||
win.hide();
|
||||
}
|
||||
} else {
|
||||
log.debug('Toggle window: hidden -> shown');
|
||||
win.show();
|
||||
}
|
||||
}
|
||||
|
||||
private onAccountSwitch = (next: Account) => {
|
||||
this.win.close();
|
||||
Window.create(next, this.config, this.win.menubar).then(win => {
|
||||
|
@ -106,6 +106,36 @@ export default class Window {
|
||||
}
|
||||
this.browser.close();
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this.menubar) {
|
||||
if (this.browser.isFocused()) {
|
||||
log.debug('Toggle window: shown -> hidden');
|
||||
this.menubar.hideWindow();
|
||||
} else {
|
||||
log.debug('Toggle window: hidden -> shown');
|
||||
this.menubar.showWindow();
|
||||
}
|
||||
} else {
|
||||
if (this.browser.isFocused()) {
|
||||
log.debug('Toggle window: shown -> hidden');
|
||||
if (IS_DARWIN) {
|
||||
app.hide();
|
||||
} else {
|
||||
if (IS_WINDOWS) {
|
||||
this.browser.blur();
|
||||
}
|
||||
this.browser.hide();
|
||||
}
|
||||
} else {
|
||||
log.debug('Toggle window: hidden -> shown');
|
||||
this.browser.show();
|
||||
if (IS_WINDOWS) {
|
||||
this.browser.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function applyUserCss(win: Electron.BrowserWindow, config: Config) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user