Skip to content

Commit 5ac23d5

Browse files
committed
New: Added sysem menu support.
1 parent edec61b commit 5ac23d5

File tree

7 files changed

+778
-290
lines changed

7 files changed

+778
-290
lines changed

app/main.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ const ipc = require('electron').ipcMain;
44
const dialog = require('electron').dialog;
55
const {ArcWindowsManager} = require('./scripts/windows-manager');
66
const {UpdateStatus} = require('./scripts/update-status');
7+
const {ArcMainMenu} = require('./scripts/main-menu');
78

89
class Arc {
910
constructor() {
11+
this.menu = new ArcMainMenu();
1012
this.wm = new ArcWindowsManager();
11-
this.us = new UpdateStatus(this.wm);
13+
this.us = new UpdateStatus(this.wm, this.menu);
14+
15+
this._listenMenu(this.menu);
1216
}
1317

1418
attachListeners() {
@@ -20,6 +24,7 @@ class Arc {
2024
_readyHandler() {
2125
this.wm.open();
2226
this.us.start();
27+
this.menu.build();
2328
}
2429
// Quits when all windows are closed.
2530
_allClosedHandler() {
@@ -34,6 +39,51 @@ class Arc {
3439
this.wm.open();
3540
}
3641
}
42+
43+
_listenMenu(menu) {
44+
menu.on('menu-action', this._menuHandler.bind(this));
45+
}
46+
47+
_menuHandler(action, win) {
48+
if (action.indexOf('application') === 0) {
49+
return this._handleApplicationAction(action.substr(12), win);
50+
}
51+
if (action.indexOf('request') === 0) {
52+
return win.webContents.send('request-action', action.substr(8));
53+
}
54+
}
55+
56+
_handleApplicationAction(action, win) {
57+
var windowCommand = 'command';
58+
switch (action) {
59+
case 'install-update':
60+
this.us.installUpdate();
61+
break;
62+
case 'check-for-update':
63+
this.us.check();
64+
break;
65+
case 'quit':
66+
app.quit();
67+
break;
68+
case 'show-settings':
69+
case 'about':
70+
case 'open-license':
71+
win.webContents.send(windowCommand, action);
72+
break;
73+
case 'new-window':
74+
this.wm.open();
75+
break;
76+
case 'open-privacy-policy':
77+
case 'open-documentation':
78+
case 'open-faq':
79+
case 'open-discussions':
80+
case 'report-issue':
81+
case 'search-issues':
82+
let {HelpManager} = require('./scripts/help-manager');
83+
HelpManager.helpWith(action);
84+
break;
85+
}
86+
}
3787
}
3888

3989
const arcApp = new Arc();

app/menus/darwin.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"menu": [{
3+
"label": "ARC",
4+
"submenu": [
5+
{"label": "About ARC", "command": "application:about"},
6+
{"label": "Version", "enabled": false},
7+
{"label": "Restart and Install Update", "command": "application:install-update", "visible": false},
8+
{"label": "Check for Update", "command": "application:check-for-update", "visible": false},
9+
{"label": "Checking for Update", "enabled": false, "visible": false},
10+
{"label": "Downloading Update", "enabled": false, "visible": false},
11+
{"type": "separator"},
12+
{"label": "Preferences…", "command": "application:show-settings", "accelerator": "CommandOrControl+,"},
13+
{"type": "separator"},
14+
{"label": "Quit", "command": "application:quit"}
15+
]
16+
}, {
17+
"label": "File",
18+
"submenu": [
19+
{"label": "Save", "command": "request:save", "accelerator": "CommandOrControl+s"},
20+
{"label": "Save as...", "command": "request:save-as", "accelerator": "CommandOrControl+Shift+s"}
21+
]
22+
}, {
23+
"label": "View",
24+
"submenu": [
25+
{"role": "togglefullscreen"},
26+
{
27+
"label": "Developer",
28+
"submenu": [
29+
{"role": "reload"},
30+
{"role": "forcereload"},
31+
{"role": "toggledevtools"}
32+
]
33+
},
34+
{"type": "separator"},
35+
{"role": "resetzoom"},
36+
{"role": "zoomin"},
37+
{"role": "zoomout"},
38+
{"role": "close"},
39+
{"role": "minimize"},
40+
{"role": "zoom"}
41+
]
42+
}, {
43+
"label": "Window",
44+
"role": "window",
45+
"submenu": [
46+
{"role": "minimize"},
47+
{"role": "zoom"},
48+
{"type": "separator"},
49+
{"role": "front"},
50+
{"type": "separator"},
51+
{"label": "New window", "command": "application:new-window", "accelerator": "CommandOrControl+n"}
52+
]
53+
}, {
54+
"label": "Help",
55+
"role": "help",
56+
"submenu": [
57+
{"label": "Privacy policy", "command": "application:open-privacy-policy"},
58+
{"label": "Documentation", "command": "application:open-documentation"},
59+
{"label": "Frequently Asked Questions", "command": "application:open-faq"},
60+
{"type": "separator"},
61+
{"label": "Community Discussions", "command": "application:open-discussions"},
62+
{"label": "Report Issue", "command": "application:report-issue"},
63+
{"label": "Search Issues", "command": "application:search-issues"},
64+
{"type": "separator"},
65+
{"label": "License information", "command": "application:open-license"}
66+
]
67+
}]
68+
}

app/menus/win.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"menu": [{
3+
"label": "File",
4+
"submenu": [
5+
{"label": "New Window", "command": "application:new-window", "accelerator": "CommandOrControl+n"},
6+
{"type": "separator"},
7+
{"label": "Settings", "command": "application:show-settings", "accelerator": "CommandOrControl+,"},
8+
{"type": "separator"},
9+
{"label": "Save", "command": "request:save", "accelerator": "CommandOrControl+s"},
10+
{"label": "Save as...", "command": "request:save-as", "accelerator": "CommandOrControl+Shift+s"},
11+
{"type": "separator"},
12+
{"label": "Quit", "command": "application:quit"}
13+
]
14+
}, {
15+
"label": "View",
16+
"submenu": [
17+
{"role": "togglefullscreen"},
18+
{
19+
"label": "Developer",
20+
"submenu": [
21+
{"role": "reload"},
22+
{"role": "forcereload"},
23+
{"role": "toggledevtools"}
24+
]
25+
},
26+
{"type": "separator"},
27+
{"role": "resetzoom"},
28+
{"role": "zoomin"},
29+
{"role": "zoomout"},
30+
{"role": "minimize"}
31+
]
32+
}, {
33+
"label": "Window",
34+
"role": "window",
35+
"submenu": [
36+
{"role": "minimize"},
37+
{"role": "zoom"},
38+
{"type": "separator"},
39+
{"role": "front"}
40+
]
41+
}, {
42+
"label": "Help",
43+
"role": "help",
44+
"submenu": [
45+
{"label": "Version", "enabled": false},
46+
{"label": "Restart and Install Update", "command": "application:install-update", "visible": false},
47+
{"label": "Check for Update", "command": "application:check-for-update", "visible": false},
48+
{"label": "Checking for Update", "enabled": false, "visible": false},
49+
{"label": "Downloading Update", "enabled": false, "visible": false},
50+
{"label": "Privacy policy", "command": "application:open-privacy-policy"},
51+
{"label": "Documentation", "command": "application:open-documentation"},
52+
{"label": "Frequently Asked Questions", "command": "application:open-faq"},
53+
{"type": "separator"},
54+
{"label": "Community Discussions", "command": "application:open-discussions"},
55+
{"label": "Report Issue", "command": "application:report-issue"},
56+
{"label": "Search Issues", "command": "application:search-issues"},
57+
{"type": "separator"},
58+
{"label": "About ARC", "command": "application:about"},
59+
{"label": "License information", "command": "application:open-license"}
60+
]
61+
}]
62+
}

app/scripts/help-manager.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const {shell} = require('electron');
2+
const {app} = require('electron');
3+
4+
class HelpManager {
5+
static helpWith(action) {
6+
switch (action) {
7+
case 'open-faq':
8+
HelpManager.openFaq();
9+
break;
10+
case 'open-discussions':
11+
HelpManager.openDiscussions();
12+
break;
13+
case 'report-issue':
14+
HelpManager.reportIssue();
15+
break;
16+
case 'search-issues':
17+
HelpManager.searchIssues();
18+
break;
19+
case 'open-documentation':
20+
HelpManager.openDocumentation();
21+
break;
22+
case 'open-privacy-policy':
23+
HelpManager.openPrivacyPolicy();
24+
break;
25+
}
26+
}
27+
28+
static openFaq() {
29+
shell.openExternal('https://github.com/advanced-rest-client/arc-electron/wiki/FAQ');
30+
}
31+
32+
static openDiscussions() {
33+
shell.openExternal('https://groups.google.com/forum/#!forum/advanced-rest-client-discussions');
34+
}
35+
36+
static searchIssues() {
37+
var url = 'https://github.com/search';
38+
url += '?q=+is%3Aissue+user%3Aadvanced-rest-client&type=Issues';
39+
shell.openExternal(url);
40+
}
41+
42+
static openDocumentation() {
43+
shell.openExternal('https://github.com/advanced-rest-client/arc-electron/wiki');
44+
}
45+
46+
static reportIssue() {
47+
const version = app.getVersion();
48+
var message = 'Your description here\n\n';
49+
message += '## Expected outcome\nWhat should happen?\n\n';
50+
message += '## Actual outcome\nWhat happened?\n\n';
51+
message += `## Versions\nApp: ${version}\n`;
52+
message += `Platform: ${process.platform}\n`;
53+
message += `Electron: ${process.versions.electron}\n`;
54+
message += `Chrome: ${process.versions.chrome}\n`;
55+
message += `V8: ${process.versions.v8}\n`;
56+
message += `Node: ${process.versions.node}\n\n`;
57+
message += '## Steps to reproduce\n1. \n2. \n3. ';
58+
message = encodeURIComponent(message);
59+
var url = 'https://github.com/advanced-rest-client/arc-electron/issues/new';
60+
url += '?body=' + message;
61+
shell.openExternal(url);
62+
}
63+
64+
static openPrivacyPolicy() {
65+
let url = 'https://docs.google.com/document/d/';
66+
url += '1BzrKQ0NxFXuDIe2zMA-0SZBNU0P46MHr4GftZmoLUQU/edit';
67+
shell.openExternal(url);
68+
}
69+
}
70+
exports.HelpManager = HelpManager;

0 commit comments

Comments
 (0)