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
71
main/app.ts
71
main/app.ts
@ -20,10 +20,56 @@ export class App {
|
|||||||
this.switcher = new AccountSwitcher(this.config.accounts);
|
this.switcher = new AccountSwitcher(this.config.accounts);
|
||||||
this.switcher.on('switch', this.onAccountSwitch);
|
this.switcher.on('switch', this.onAccountSwitch);
|
||||||
|
|
||||||
if (!win.menubar) {
|
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');
|
||||||
|
mb.hideWindow();
|
||||||
|
} else {
|
||||||
|
log.debug('Toggle window: hidden -> shown');
|
||||||
|
mb.showWindow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
globalShortcut.register(this.config.hot_key, this.toggleNormalWindow);
|
||||||
|
}
|
||||||
|
log.debug('Hot key was set to:', this.config.hot_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
const a = this.switcher.current;
|
||||||
|
const url = `https://${a.host}${a.default_page}`;
|
||||||
|
this.win.open(url);
|
||||||
|
log.debug('Application started', a, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
private setupTray() {
|
||||||
|
if (this.win.menubar) {
|
||||||
// Note:
|
// Note:
|
||||||
// If it's menubar window, tray will be put in menubar().
|
// If it's menubar window, tray will be put in menubar().
|
||||||
const toggleWindow = () => {
|
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;
|
const win = this.win.browser;
|
||||||
if (win.isFocused()) {
|
if (win.isFocused()) {
|
||||||
log.debug('Toggle window: shown -> hidden');
|
log.debug('Toggle window: shown -> hidden');
|
||||||
@ -36,31 +82,10 @@ export class App {
|
|||||||
log.debug('Toggle window: hidden -> shown');
|
log.debug('Toggle window: hidden -> shown');
|
||||||
win.show();
|
win.show();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
start() {
|
|
||||||
const a = this.switcher.current;
|
|
||||||
const url = `https://${a.host}${a.default_page}`;
|
|
||||||
this.win.open(url);
|
|
||||||
log.debug('Application started', a, url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private onAccountSwitch = (next: Account) => {
|
private onAccountSwitch = (next: Account) => {
|
||||||
this.win.close();
|
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);
|
log.debug('Window was recreated again', next);
|
||||||
this.win = win;
|
this.win = win;
|
||||||
|
@ -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 windowState = require('electron-window-state');
|
||||||
import * as menubar from 'menubar';
|
import * as menubar from 'menubar';
|
||||||
import {Config, Account} from './config';
|
import {Config, Account} from './config';
|
||||||
@ -116,30 +116,12 @@ function startNormalWindow(account: Account, config: Config): Promise<Window> {
|
|||||||
}
|
}
|
||||||
state.manage(win);
|
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', () => {
|
win.webContents.on('dom-ready', () => {
|
||||||
log.debug('Send config to renderer procress');
|
log.debug('Send config to renderer procress');
|
||||||
win.webContents.send('mstdn:config', config, account);
|
win.webContents.send('mstdn:config', config, account);
|
||||||
});
|
});
|
||||||
win.webContents.once('dom-ready', () => {
|
win.webContents.once('dom-ready', () => {
|
||||||
log.debug('Normal window application was launched');
|
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) {
|
if (IS_DEBUG) {
|
||||||
win.webContents.openDevTools({mode: 'detach'});
|
win.webContents.openDevTools({mode: 'detach'});
|
||||||
}
|
}
|
||||||
@ -176,18 +158,6 @@ function startMenuBar(account: Account, config: Config, bar: Menubar.MenubarApp
|
|||||||
});
|
});
|
||||||
mb.once('after-create-window', () => {
|
mb.once('after-create-window', () => {
|
||||||
log.debug('Menubar application was launched');
|
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) {
|
if (IS_DEBUG) {
|
||||||
mb.window.webContents.openDevTools({mode: 'detach'});
|
mb.window.webContents.openDevTools({mode: 'detach'});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user