UNPKG

7 kBJavaScriptView Raw
1/**
2 *
3 * 2app
4 * 2016-03-23
5 *
6 * Haochuan Liu <haochuan.liu@gmail.com>
7 * http://haochuan.io
8 *
9 */
10var electron = require('electron');
11var app = electron.app; // Module to control application life.
12var BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
13var Menu = require('menu');
14var MenuItem = require('menu-item');
15
16// Report crashes to our server.
17require('crash-reporter').start();
18
19// Keep a global reference of the window object, if you don't, the window will
20// be closed automatically when the javascript object is GCed.
21var mainWindow = null;
22var menu = null;
23
24// Quit when all windows are closed.
25app.on('window-all-closed', function() {
26 app.quit();
27});
28
29// This method will be called when Electron has done everything
30// initialization and ready for creating browser windows.
31app.on('ready', function() {
32 // Create the browser window.
33 mainWindow = new BrowserWindow({
34 width: 800,
35 height: 600,
36 'auto-hide-menu-bar': true,
37 'use-content-size': true
38 });
39
40 // and load the index.html of the app.
41 mainWindow.loadUrl('file://' + __dirname + '/index.html');
42
43 mainWindow.focus();
44
45 // Emitted when the window is closed.
46 mainWindow.on('closed', function() {
47 // Dereference the window object, usually you would store windows
48 // in an array if your app supports multi windows, this is the time
49 // when you should delete the corresponding element.
50 mainWindow = null;
51 });
52
53 if (process.platform == 'darwin') {
54 var template = [
55 {
56 label: 'Electron',
57 submenu: [
58 {
59 label: 'About Electron',
60 selector: 'orderFrontStandardAboutPanel:'
61 },
62 {
63 type: 'separator'
64 },
65 {
66 label: 'Services',
67 submenu: []
68 },
69 {
70 type: 'separator'
71 },
72 {
73 label: 'Hide Electron',
74 accelerator: 'Command+H',
75 selector: 'hide:'
76 },
77 {
78 label: 'Hide Others',
79 accelerator: 'Command+Shift+H',
80 selector: 'hideOtherApplications:'
81 },
82 {
83 label: 'Show All',
84 selector: 'unhideAllApplications:'
85 },
86 {
87 type: 'separator'
88 },
89 {
90 label: 'Quit',
91 accelerator: 'Command+Q',
92 click: function() { app.quit(); }
93 },
94 ]
95 },
96 {
97 label: 'Edit',
98 submenu: [
99 {
100 label: 'Undo',
101 accelerator: 'Command+Z',
102 selector: 'undo:'
103 },
104 {
105 label: 'Redo',
106 accelerator: 'Shift+Command+Z',
107 selector: 'redo:'
108 },
109 {
110 type: 'separator'
111 },
112 {
113 label: 'Cut',
114 accelerator: 'Command+X',
115 selector: 'cut:'
116 },
117 {
118 label: 'Copy',
119 accelerator: 'Command+C',
120 selector: 'copy:'
121 },
122 {
123 label: 'Paste',
124 accelerator: 'Command+V',
125 selector: 'paste:'
126 },
127 {
128 label: 'Select All',
129 accelerator: 'Command+A',
130 selector: 'selectAll:'
131 },
132 ]
133 },
134 {
135 label: 'View',
136 submenu: [
137 {
138 label: 'Reload',
139 accelerator: 'Command+R',
140 click: function() { mainWindow.restart(); }
141 },
142 {
143 label: 'Toggle Full Screen',
144 accelerator: 'Ctrl+Command+F',
145 click: function() { mainWindow.setFullScreen(!mainWindow.isFullScreen()); }
146 },
147 {
148 label: 'Toggle Developer Tools',
149 accelerator: 'Alt+Command+I',
150 click: function() { mainWindow.toggleDevTools(); }
151 },
152 ]
153 },
154 {
155 label: 'Window',
156 submenu: [
157 {
158 label: 'Minimize',
159 accelerator: 'Command+M',
160 selector: 'performMiniaturize:'
161 },
162 {
163 label: 'Close',
164 accelerator: 'Command+W',
165 selector: 'performClose:'
166 },
167 {
168 type: 'separator'
169 },
170 {
171 label: 'Bring All to Front',
172 selector: 'arrangeInFront:'
173 },
174 ]
175 },
176 {
177 label: 'Help',
178 submenu: [
179 {
180 label: 'Learn More',
181 click: function() { require('shell').openExternal('http://electron.atom.io'); }
182 },
183 {
184 label: 'Documentation',
185 click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme'); }
186 },
187 {
188 label: 'Community Discussions',
189 click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron'); }
190 },
191 {
192 label: 'Search Issues',
193 click: function() { require('shell').openExternal('https://github.com/atom/electron/issues'); }
194 }
195 ]
196 }
197 ];
198
199 menu = Menu.buildFromTemplate(template);
200 Menu.setApplicationMenu(menu);
201 } else {
202 var template = [
203 {
204 label: '&File',
205 submenu: [
206 {
207 label: '&Open',
208 accelerator: 'Ctrl+O',
209 },
210 {
211 label: '&Close',
212 accelerator: 'Ctrl+W',
213 click: function() { mainWindow.close(); }
214 },
215 ]
216 },
217 {
218 label: '&View',
219 submenu: [
220 {
221 label: '&Reload',
222 accelerator: 'Ctrl+R',
223 click: function() { mainWindow.restart(); }
224 },
225 {
226 label: 'Toggle &Full Screen',
227 accelerator: 'F11',
228 click: function() { mainWindow.setFullScreen(!mainWindow.isFullScreen()); }
229 },
230 {
231 label: 'Toggle &Developer Tools',
232 accelerator: 'Alt+Ctrl+I',
233 click: function() { mainWindow.toggleDevTools(); }
234 },
235 ]
236 },
237 {
238 label: 'Help',
239 submenu: [
240 {
241 label: 'Learn More',
242 click: function() { require('shell').openExternal('http://electron.atom.io'); }
243 },
244 {
245 label: 'Documentation',
246 click: function() { require('shell').openExternal('https://github.com/atom/electron/tree/master/docs#readme'); }
247 },
248 {
249 label: 'Community Discussions',
250 click: function() { require('shell').openExternal('https://discuss.atom.io/c/electron'); }
251 },
252 {
253 label: 'Search Issues',
254 click: function() { require('shell').openExternal('https://github.com/atom/electron/issues'); }
255 }
256 ]
257 }
258 ];
259
260 menu = Menu.buildFromTemplate(template);
261 mainWindow.setMenu(menu);
262}
263});