Commit e7725160 authored by undefined's avatar undefined Committed by GitHub

Add Traymenu (#86)

* 添加托盘

* high-DPI支持
parent a95cfe50
......@@ -50,6 +50,14 @@ app
event.preventDefault();
app.exit(0);
})
.on('minimize', (event) => {
event.preventDefault();
if (process.platform == 'darwin') {
app.hide();
}else{
mainWindow.hide();
}
})
.on('resize', reloadUI)
.on('maximize', reloadUI)
.on('unmaximize', reloadUI)
......
......@@ -9,6 +9,9 @@ class Menubar {
constructor(electron, app, mainWindow) {
const Menu = electron.Menu;
const Tray = electron.Tray;
const nativeImage = electron.nativeImage;
const path = require('path');
// 清空菜单栏
Menu.setApplicationMenu(Menu.buildFromTemplate([]));
......@@ -20,6 +23,10 @@ class Menubar {
this.electron = electron;
this.app = app;
this.Menu = Menu;
this.Tray = Tray;
this.nativeImage = nativeImage;
this.path = path;
this.trayIcon = null;
this.mainWindow = mainWindow;
}
......@@ -131,6 +138,61 @@ class Menubar {
];
// 更新菜单栏
this.Menu.setApplicationMenu(this.Menu.buildFromTemplate(template));
if (this.trayIcon) {
this.trayIcon.setContextMenu(this.Menu.buildFromTemplate([]));
}else{
let image;
if (process.platform === 'darwin' || process.platform === 'linux') {
image = this.nativeImage.createFromPath(this.path.join(__dirname, '../static/imgs/tray-icon-mac-2.png'));
}else{
// windows下的Tray图标
image = this.nativeImage.createFromPath(this.path.join(__dirname, '../static/imgs/tray-icon-win-colorful.ico'));
}
image.setTemplateImage(true);
this.trayIcon = new this.Tray(image);
}
var trayMenuTemplate = [
{
label: LANG['tray']['show'],
click: () => {
this.mainWindow.show();
}
}, {
label: LANG['tray']['hide'],
click: () => {
if (process.platform == 'darwin') {
this.app.hide();
}else{
this.mainWindow.hide();
}
}
}, {
label: LANG['tray']['settings'],
click: event.sender.send.bind(event.sender, 'menubar', 'settings')
}, {
label: LANG['tray']['about'],
click: event.sender.send.bind(event.sender, 'menubar', 'settings-about')
}, {
type: 'separator'
}, {
label: LANG['tray']['quit'],
click: this.app.quit.bind(this.app)
}
];
this.trayIcon.on('click', () => {
if (process.platform == 'darwin') return;
if (this.mainWindow.isVisible()) {
this.mainWindow.hide();
}else{
this.mainWindow.show();
}
});
this.trayIcon.setToolTip(LANG['tray']['tip']);
this.trayIcon.setContextMenu(this.Menu.buildFromTemplate(trayMenuTemplate));
}
}
......
......@@ -38,6 +38,14 @@ module.exports = {
title: 'Debug',
restart: 'Restart APP',
devtools: 'Developer Tools'
},
tray: {
tip: 'AntSword',
show: 'Show',
hide: 'Hide',
settings: 'System setting',
about: 'About',
quit: 'Quit'
}
},
shellmanager: {
......
......@@ -11,7 +11,7 @@ const languages = {
// 获取本地设置语言(如若没有,则获取浏览器语言
let lang = antSword['storage']('language',
false,
navigator.language
navigator.language.substr(0,2)
);
// 判断本地设置语言是否符合语言模板
......
......@@ -39,6 +39,14 @@ module.exports = {
title: '调试',
restart: '重启应用',
devtools: '开发者工具'
},
tray: {
tip: '中国蚁剑',
show: '显示',
hide: '隐藏',
settings: '系统设置',
about: '关于蚁剑',
quit: '退出'
}
},
shellmanager: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment