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

Add Traymenu (#86)

* 添加托盘

* high-DPI支持
parent a95cfe50
...@@ -50,6 +50,14 @@ app ...@@ -50,6 +50,14 @@ app
event.preventDefault(); event.preventDefault();
app.exit(0); app.exit(0);
}) })
.on('minimize', (event) => {
event.preventDefault();
if (process.platform == 'darwin') {
app.hide();
}else{
mainWindow.hide();
}
})
.on('resize', reloadUI) .on('resize', reloadUI)
.on('maximize', reloadUI) .on('maximize', reloadUI)
.on('unmaximize', reloadUI) .on('unmaximize', reloadUI)
......
...@@ -9,7 +9,10 @@ class Menubar { ...@@ -9,7 +9,10 @@ class Menubar {
constructor(electron, app, mainWindow) { constructor(electron, app, mainWindow) {
const Menu = electron.Menu; const Menu = electron.Menu;
const Tray = electron.Tray;
const nativeImage = electron.nativeImage;
const path = require('path');
// 清空菜单栏 // 清空菜单栏
Menu.setApplicationMenu(Menu.buildFromTemplate([])); Menu.setApplicationMenu(Menu.buildFromTemplate([]));
// 监听重载菜单事件 // 监听重载菜单事件
...@@ -20,6 +23,10 @@ class Menubar { ...@@ -20,6 +23,10 @@ class Menubar {
this.electron = electron; this.electron = electron;
this.app = app; this.app = app;
this.Menu = Menu; this.Menu = Menu;
this.Tray = Tray;
this.nativeImage = nativeImage;
this.path = path;
this.trayIcon = null;
this.mainWindow = mainWindow; this.mainWindow = mainWindow;
} }
...@@ -131,6 +138,61 @@ class Menubar { ...@@ -131,6 +138,61 @@ class Menubar {
]; ];
// 更新菜单栏 // 更新菜单栏
this.Menu.setApplicationMenu(this.Menu.buildFromTemplate(template)); 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 = { ...@@ -38,6 +38,14 @@ module.exports = {
title: 'Debug', title: 'Debug',
restart: 'Restart APP', restart: 'Restart APP',
devtools: 'Developer Tools' devtools: 'Developer Tools'
},
tray: {
tip: 'AntSword',
show: 'Show',
hide: 'Hide',
settings: 'System setting',
about: 'About',
quit: 'Quit'
} }
}, },
shellmanager: { shellmanager: {
......
...@@ -11,7 +11,7 @@ const languages = { ...@@ -11,7 +11,7 @@ const languages = {
// 获取本地设置语言(如若没有,则获取浏览器语言 // 获取本地设置语言(如若没有,则获取浏览器语言
let lang = antSword['storage']('language', let lang = antSword['storage']('language',
false, false,
navigator.language navigator.language.substr(0,2)
); );
// 判断本地设置语言是否符合语言模板 // 判断本地设置语言是否符合语言模板
......
...@@ -39,6 +39,14 @@ module.exports = { ...@@ -39,6 +39,14 @@ module.exports = {
title: '调试', title: '调试',
restart: '重启应用', restart: '重启应用',
devtools: '开发者工具' devtools: '开发者工具'
},
tray: {
tip: '中国蚁剑',
show: '显示',
hide: '隐藏',
settings: '系统设置',
about: '关于蚁剑',
quit: '退出'
} }
}, },
shellmanager: { 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