mirror of
https://github.com/rhysd/Mstdn.git
synced 2025-01-21 20:52:11 +01:00
do not append tray icon at normal window
This commit is contained in:
parent
5442699549
commit
a15e6a25fb
@ -44,9 +44,11 @@ export default class AccountSwitcher extends EventEmitter {
|
||||
});
|
||||
|
||||
const menu = Menu.getApplicationMenu();
|
||||
// Insert item before 'Help'
|
||||
menu.insert(menu.items.length - 1, item);
|
||||
Menu.setApplicationMenu(menu);
|
||||
if (menu !== null) {
|
||||
// Insert item before 'Help'
|
||||
menu.insert(menu.items.length - 1, item);
|
||||
Menu.setApplicationMenu(menu);
|
||||
}
|
||||
}
|
||||
|
||||
switchTo(account: Account) {
|
||||
|
35
main/app.ts
35
main/app.ts
@ -1,5 +1,5 @@
|
||||
import * as path from 'path';
|
||||
import {app, Menu, globalShortcut} from 'electron';
|
||||
import {app, Menu, globalShortcut, Tray} from 'electron';
|
||||
import log from './log';
|
||||
import {Config, Account} from './config';
|
||||
import AccountSwitcher from './account_switcher';
|
||||
@ -9,6 +9,12 @@ import Window from './window';
|
||||
const IS_DARWIN = process.platform === 'darwin';
|
||||
const APP_ICON = path.join(__dirname, '..', 'resources', 'icon', 'icon.png');
|
||||
|
||||
function trayIcon(color: string) {
|
||||
return path.join(__dirname, '..', 'resources', 'icon', `tray-icon-${
|
||||
color === 'white' ? 'white' : 'black'
|
||||
}@2x.png`);
|
||||
}
|
||||
|
||||
export class App {
|
||||
private switcher: AccountSwitcher;
|
||||
|
||||
@ -22,6 +28,33 @@ export class App {
|
||||
Menu.setApplicationMenu(defaultMenu());
|
||||
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()) {
|
||||
log.debug('Toggle window: shown -> hidden');
|
||||
if (IS_DARWIN) {
|
||||
app.hide();
|
||||
} else {
|
||||
win.hide();
|
||||
}
|
||||
} else {
|
||||
log.debug('Toggle window: hidden -> shown');
|
||||
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() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as path from 'path';
|
||||
import {app, BrowserWindow, globalShortcut, Tray, shell, dialog, Menu} from 'electron';
|
||||
import {app, BrowserWindow, globalShortcut, shell, dialog, Menu} from 'electron';
|
||||
import windowState = require('electron-window-state');
|
||||
import * as menubar from 'menubar';
|
||||
import {Config, Account} from './config';
|
||||
@ -156,14 +156,6 @@ function startNormalWindow(account: Account, config: Config): Promise<Window> {
|
||||
}
|
||||
});
|
||||
|
||||
const normalIcon = trayIcon(config.icon_color);
|
||||
const tray = new Tray(normalIcon);
|
||||
tray.on('click', toggleWindow);
|
||||
tray.on('double-click', toggleWindow);
|
||||
if (IS_DARWIN) {
|
||||
tray.setHighlightMode('never');
|
||||
}
|
||||
|
||||
resolve(new Window(win, state, account, null));
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user