Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
e7725160
Commit
e7725160
authored
Mar 22, 2017
by
undefined
Committed by
GitHub
Mar 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Traymenu (#86)
* 添加托盘 * high-DPI支持
parent
a95cfe50
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
88 additions
and
2 deletions
+88
-2
app.js
app.js
+8
-0
menubar.js
modules/menubar.js
+63
-1
en.js
source/language/en.js
+8
-0
index.js
source/language/index.js
+1
-1
zh.js
source/language/zh.js
+8
-0
tray-icon-mac-2.png
static/imgs/tray-icon-mac-2.png
+0
-0
tray-icon-mac-2@2x.png
static/imgs/tray-icon-mac-2@2x.png
+0
-0
tray-icon-mac-2@3x.png
static/imgs/tray-icon-mac-2@3x.png
+0
-0
tray-icon-mac.png
static/imgs/tray-icon-mac.png
+0
-0
tray-icon-mac@2x.png
static/imgs/tray-icon-mac@2x.png
+0
-0
tray-icon-mac@3x.png
static/imgs/tray-icon-mac@3x.png
+0
-0
tray-icon-win-black.ico
static/imgs/tray-icon-win-black.ico
+0
-0
tray-icon-win-colorful.ico
static/imgs/tray-icon-win-colorful.ico
+0
-0
No files found.
app.js
View file @
e7725160
...
@@ -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
)
...
...
modules/menubar.js
View file @
e7725160
...
@@ -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
));
}
}
}
}
...
...
source/language/en.js
View file @
e7725160
...
@@ -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
:
{
...
...
source/language/index.js
View file @
e7725160
...
@@ -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
)
);
);
// 判断本地设置语言是否符合语言模板
// 判断本地设置语言是否符合语言模板
...
...
source/language/zh.js
View file @
e7725160
...
@@ -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
:
{
...
...
static/imgs/tray-icon-mac-2.png
0 → 100644
View file @
e7725160
15.2 KB
static/imgs/tray-icon-mac-2@2x.png
0 → 100644
View file @
e7725160
15.4 KB
static/imgs/tray-icon-mac-2@3x.png
0 → 100644
View file @
e7725160
15.7 KB
static/imgs/tray-icon-mac.png
0 → 100644
View file @
e7725160
20.7 KB
static/imgs/tray-icon-mac@2x.png
0 → 100644
View file @
e7725160
22.2 KB
static/imgs/tray-icon-mac@3x.png
0 → 100644
View file @
e7725160
24.1 KB
static/imgs/tray-icon-win-black.ico
0 → 100644
View file @
e7725160
361 KB
static/imgs/tray-icon-win-colorful.ico
0 → 100644
View file @
e7725160
361 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment