mirror of
https://github.com/rhysd/Mstdn.git
synced 2025-01-21 20:52:11 +01:00
do not reset global shortcut
This commit is contained in:
parent
ed99f9fd8f
commit
e8ab0c20e7
77
main/app.ts
77
main/app.ts
@ -20,32 +20,30 @@ export class App {
|
||||
this.switcher = new AccountSwitcher(this.config.accounts);
|
||||
this.switcher.on('switch', this.onAccountSwitch);
|
||||
|
||||
if (!win.menubar) {
|
||||
// Note:
|
||||
// If it's menubar window, tray will be put in menubar().
|
||||
const toggleWindow = () => {
|
||||
const win = this.win.browser;
|
||||
if (win.isFocused()) {
|
||||
this.setupTray();
|
||||
this.setupHotkey();
|
||||
}
|
||||
|
||||
private setupHotkey() {
|
||||
if (!this.config.hot_key) {
|
||||
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');
|
||||
if (IS_DARWIN) {
|
||||
app.hide();
|
||||
} else {
|
||||
win.hide();
|
||||
}
|
||||
mb.hideWindow();
|
||||
} else {
|
||||
log.debug('Toggle window: hidden -> shown');
|
||||
win.show();
|
||||
mb.showWindow();
|
||||
}
|
||||
};
|
||||
|
||||
const icon = trayIcon(config.icon_color);
|
||||
const tray = new Tray(icon);
|
||||
tray.on('click', toggleWindow);
|
||||
tray.on('double-click', toggleWindow);
|
||||
if (IS_DARWIN) {
|
||||
tray.setHighlightMode('never');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
globalShortcut.register(this.config.hot_key, this.toggleNormalWindow);
|
||||
}
|
||||
log.debug('Hot key was set to:', this.config.hot_key);
|
||||
}
|
||||
|
||||
start() {
|
||||
@ -55,13 +53,40 @@ export class App {
|
||||
log.debug('Application started', a, url);
|
||||
}
|
||||
|
||||
private setupTray() {
|
||||
if (this.win.menubar) {
|
||||
// Note:
|
||||
// If it's menubar window, tray will be put in menubar().
|
||||
return;
|
||||
}
|
||||
|
||||
const icon = trayIcon(this.config.icon_color);
|
||||
const tray = new Tray(icon);
|
||||
tray.on('click', this.toggleNormalWindow);
|
||||
tray.on('double-click', this.toggleNormalWindow);
|
||||
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();
|
||||
if (this.config.hot_key) {
|
||||
log.debug('Disable global shortcut for switching account');
|
||||
globalShortcut.unregister(this.config.hot_key);
|
||||
}
|
||||
Window.create(next, this.config, this.win.menubar) .then(win => {
|
||||
Window.create(next, this.config, this.win.menubar).then(win => {
|
||||
log.debug('Window was recreated again', next);
|
||||
this.win = win;
|
||||
this.start();
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {app, BrowserWindow, globalShortcut, shell, dialog, Menu} from 'electron';
|
||||
import {app, BrowserWindow, shell, dialog, Menu} from 'electron';
|
||||
import windowState = require('electron-window-state');
|
||||
import * as menubar from 'menubar';
|
||||
import {Config, Account} from './config';
|
||||
@ -116,30 +116,12 @@ function startNormalWindow(account: Account, config: Config): Promise<Window> {
|
||||
}
|
||||
state.manage(win);
|
||||
|
||||
const toggleWindow = () => {
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
win.webContents.on('dom-ready', () => {
|
||||
log.debug('Send config to renderer procress');
|
||||
win.webContents.send('mstdn:config', config, account);
|
||||
});
|
||||
win.webContents.once('dom-ready', () => {
|
||||
log.debug('Normal window application was launched');
|
||||
if (config.hot_key) {
|
||||
globalShortcut.register(config.hot_key, toggleWindow);
|
||||
log.debug('Hot key was set to:', config.hot_key);
|
||||
}
|
||||
if (IS_DEBUG) {
|
||||
win.webContents.openDevTools({mode: 'detach'});
|
||||
}
|
||||
@ -176,18 +158,6 @@ function startMenuBar(account: Account, config: Config, bar: Menubar.MenubarApp
|
||||
});
|
||||
mb.once('after-create-window', () => {
|
||||
log.debug('Menubar application was launched');
|
||||
if (config.hot_key) {
|
||||
globalShortcut.register(config.hot_key, () => {
|
||||
if (mb.window.isFocused()) {
|
||||
log.debug('Toggle window: shown -> hidden');
|
||||
mb.hideWindow();
|
||||
} else {
|
||||
log.debug('Toggle window: hidden -> shown');
|
||||
mb.showWindow();
|
||||
}
|
||||
});
|
||||
log.debug('Hot key was set to:', config.hot_key);
|
||||
}
|
||||
if (IS_DEBUG) {
|
||||
mb.window.webContents.openDevTools({mode: 'detach'});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user