oldj 10 years ago
parent
commit
f11323cc20
4 changed files with 207 additions and 183 deletions
  1. 2 2
      app/js/lang.js
  2. 170 0
      app/js/menu.js
  3. 29 0
      app/js/tray.js
  4. 6 181
      app/main.js

+ 2 - 2
app/js/lang.js

@@ -14,7 +14,7 @@ const languages = {
         , edit_host: 'Edit host'
         , host_title: 'Host title'
         , host_title_cant_be_empty: 'Host title could not be empty!'
-        , sys_host_title: 'System Host'
+        , sys_host_title: 'System Hosts'
         , input_sudo_pswd: 'Input your sudo password'
         , sudo_pswd: 'Password'
         , del_host: 'Delete current host'
@@ -32,7 +32,7 @@ const languages = {
         , edit_host: '修改 host'
         , host_title: 'host 方案名'
         , host_title_cant_be_empty: 'Host 方案名不能为空!'
-        , sys_host_title: '系统 Host'
+        , sys_host_title: '系统 Hosts'
         , input_sudo_pswd: '请输入管理员密码'
         , sudo_pswd: '密码'
         , del_host: '删除当前 host'

+ 170 - 0
app/js/menu.js

@@ -0,0 +1,170 @@
+/**
+ * @author oldj
+ * @blog http://oldj.net
+ */
+
+"use strict";
+
+const Menu = require('menu');
+
+function makeMenu(app) {
+
+    let template = [{
+        label: 'Edit',
+        submenu: [{
+            label: 'Undo',
+            accelerator: 'CmdOrCtrl+Z',
+            role: 'undo'
+        }, {
+            label: 'Redo',
+            accelerator: 'Shift+CmdOrCtrl+Z',
+            role: 'redo'
+        }, {
+            type: 'separator'
+        }, {
+            label: 'Cut',
+            accelerator: 'CmdOrCtrl+X',
+            role: 'cut'
+        }, {
+            label: 'Copy',
+            accelerator: 'CmdOrCtrl+C',
+            role: 'copy'
+        }, {
+            label: 'Paste',
+            accelerator: 'CmdOrCtrl+V',
+            role: 'paste'
+        }, {
+            label: 'Select All',
+            accelerator: 'CmdOrCtrl+A',
+            role: 'selectall'
+        }]
+    }, {
+        label: 'View',
+        submenu: [{
+            label: 'Toggle Full Screen',
+            accelerator: (function () {
+                if (process.platform == 'darwin') {
+                    return 'Ctrl+Command+F';
+                } else {
+                    return 'F11';
+                }
+            })(),
+            click: function (item, focusedWindow) {
+                if (focusedWindow) {
+                    focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
+                }
+            }
+            //},
+            //{
+            //    label: 'Toggle Developer Tools',
+            //    accelerator: (function () {
+            //        if (process.platform == 'darwin') {
+            //            return 'Alt+Command+I';
+            //        } else {
+            //            return 'Ctrl+Shift+I';
+            //        }
+            //    })(),
+            //    click: function (item, focusedWindow) {
+            //        if (focusedWindow) {
+            //            focusedWindow.toggleDevTools();
+            //        }
+            //    }
+        }]
+    }, {
+        label: 'Window',
+        role: 'window',
+        submenu: [{
+            label: 'Minimize',
+            accelerator: 'CmdOrCtrl+M',
+            role: 'minimize'
+        }, {
+            label: 'Close',
+            accelerator: 'CmdOrCtrl+W',
+            role: 'close'
+        }]
+    }, {
+        label: 'Help',
+        role: 'help',
+        submenu: [{
+            label: 'Homepage',
+            click: function () {
+                require('electron').shell.openExternal(config.url_homepage);
+            }
+        }, {
+            label: 'Feedback',
+            click: function () {
+                require('electron').shell.openExternal(config.url_feedback);
+            }
+        }]
+    }];
+
+    if (app.__is_debug) {
+        template[1].submenu.push({
+            label: 'Reload',
+            accelerator: 'CmdOrCtrl+R',
+            click: function (item, focusedWindow) {
+                if (focusedWindow)
+                    focusedWindow.reload();
+            }
+        });
+    }
+
+    if (process.platform == 'darwin') {
+        let name = require('electron').app.getName();
+        template.unshift({
+            label: name,
+            submenu: [{
+                label: 'About ' + name,
+                role: 'about'
+            }, {
+                label: 'Check for Updates...',
+                click: function () {
+                    require('./js/chk').chkUpdate(config.VERSION, mainWindow);
+                }
+            }, {
+                type: 'separator'
+            }, {
+                label: 'Services',
+                role: 'services',
+                submenu: []
+            }, {
+                type: 'separator'
+            }, {
+                label: 'Hide ' + name,
+                accelerator: 'Command+H',
+                role: 'hide'
+            }, {
+                label: 'Hide Others',
+                accelerator: 'Command+Shift+H',
+                role: 'hideothers'
+            }, {
+                label: 'Show All',
+                role: 'unhide'
+            }, {
+                type: 'separator'
+            }, {
+                label: 'Quit',
+                accelerator: 'Command+Q',
+                click: function () {
+                    app.__force_quit = true;
+                    app.quit();
+                }
+            }]
+        });
+        // Window menu.
+        template[3].submenu.push(
+            {
+                type: 'separator'
+            },
+            {
+                label: 'Bring All to Front',
+                role: 'front'
+            }
+        );
+    }
+
+    let menu = Menu.buildFromTemplate(template);
+    Menu.setApplicationMenu(menu);
+}
+
+exports.makeMenu = makeMenu;

+ 29 - 0
app/js/tray.js

@@ -0,0 +1,29 @@
+/**
+ * @author oldj
+ * @blog http://oldj.net
+ */
+
+"use strict";
+
+//const Tray = require('tray');
+
+let appIcon = null;
+
+function makeTray(app) {
+    /*
+     //console.log('file://' + __dirname + '/images/t.png');
+     // @see https://github.com/atom/electron/blob/master/docs/api/tray.md
+     appIcon = new Tray(__dirname + '/images/t.png');
+     //appIcon = new Tray('/Users/wu/studio/owl/sh3/app/images/t.png');
+     let contextMenu = Menu.buildFromTemplate([
+     {label: 'Item1', type: 'radio'},
+     {label: 'Item2', type: 'radio'},
+     {label: 'Item3', type: 'radio', checked: true},
+     {label: 'Item4', type: 'radio'}
+     ]);
+     appIcon.setToolTip('This is my application.');
+     appIcon.setContextMenu(contextMenu);
+     */
+}
+
+exports.makeTray = makeTray;

+ 6 - 181
app/main.js

@@ -10,11 +10,8 @@ const config = require('./config');
 const app = require('app');  // Module to control application life.
 const BrowserWindow = require('browser-window');  // Module to create native browser window.
 const http = require('http');
-const Menu = require('menu');
-//const Tray = require('tray');
 
-//let is_debug = true;
-let is_debug = false;
+app.__is_debug = false;
 
 
 // Report crashes to our server.
@@ -23,7 +20,6 @@ require('crash-reporter').start();
 // Keep a global reference of the window object, if you don't, the window will
 // be closed automatically when the javascript object is GCed.
 let mainWindow = null;
-let force_quit = false;
 
 // Quit when all windows are closed.
 app.on('window-all-closed', function () {
@@ -32,8 +28,6 @@ app.on('window-all-closed', function () {
     }
 });
 
-let appIcon = null;
-
 // This method will be called when atom-shell has done everything
 // initialization and ready for creating browser windows.
 app.on('ready', function () {
@@ -43,12 +37,12 @@ app.on('ready', function () {
     // and load the index.html of the app.
     mainWindow.loadURL('file://' + __dirname + '/index.html');
 
-    if (is_debug) {
+    if (app.__is_debug) {
         mainWindow.toggleDevTools();
     }
 
     mainWindow.on('close', function (e) {
-        if (!force_quit) {
+        if (!app.__force_quit) {
             e.preventDefault();
             mainWindow.hide();
         }
@@ -57,7 +51,7 @@ app.on('ready', function () {
     // You can use 'before-quit' instead of (or with) the close event
     app.on('before-quit', function (e) {
         // Handle menu-item or keyboard shortcut quit here
-        if (!force_quit) {
+        if (!app.__force_quit) {
             e.preventDefault();
             mainWindow.hide();
         }
@@ -78,175 +72,6 @@ app.on('ready', function () {
         mainWindow.show();
     });
 
-    /*
-     //console.log('file://' + __dirname + '/images/t.png');
-     // @see https://github.com/atom/electron/blob/master/docs/api/tray.md
-     appIcon = new Tray(__dirname + '/images/t.png');
-     //appIcon = new Tray('/Users/wu/studio/owl/sh3/app/images/t.png');
-     let contextMenu = Menu.buildFromTemplate([
-     {label: 'Item1', type: 'radio'},
-     {label: 'Item2', type: 'radio'},
-     {label: 'Item3', type: 'radio', checked: true},
-     {label: 'Item4', type: 'radio'}
-     ]);
-     appIcon.setToolTip('This is my application.');
-     appIcon.setContextMenu(contextMenu);
-     */
-
-    let template = [{
-        label: 'Edit',
-        submenu: [{
-            label: 'Undo',
-            accelerator: 'CmdOrCtrl+Z',
-            role: 'undo'
-        }, {
-            label: 'Redo',
-            accelerator: 'Shift+CmdOrCtrl+Z',
-            role: 'redo'
-        }, {
-            type: 'separator'
-        }, {
-            label: 'Cut',
-            accelerator: 'CmdOrCtrl+X',
-            role: 'cut'
-        }, {
-            label: 'Copy',
-            accelerator: 'CmdOrCtrl+C',
-            role: 'copy'
-        }, {
-            label: 'Paste',
-            accelerator: 'CmdOrCtrl+V',
-            role: 'paste'
-        }, {
-            label: 'Select All',
-            accelerator: 'CmdOrCtrl+A',
-            role: 'selectall'
-        }]
-    }, {
-        label: 'View',
-        submenu: [{
-            label: 'Toggle Full Screen',
-            accelerator: (function () {
-                if (process.platform == 'darwin') {
-                    return 'Ctrl+Command+F';
-                } else {
-                    return 'F11';
-                }
-            })(),
-            click: function (item, focusedWindow) {
-                if (focusedWindow) {
-                    focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
-                }
-            }
-            //},
-            //{
-            //    label: 'Toggle Developer Tools',
-            //    accelerator: (function () {
-            //        if (process.platform == 'darwin') {
-            //            return 'Alt+Command+I';
-            //        } else {
-            //            return 'Ctrl+Shift+I';
-            //        }
-            //    })(),
-            //    click: function (item, focusedWindow) {
-            //        if (focusedWindow) {
-            //            focusedWindow.toggleDevTools();
-            //        }
-            //    }
-        }]
-    }, {
-        label: 'Window',
-        role: 'window',
-        submenu: [{
-            label: 'Minimize',
-            accelerator: 'CmdOrCtrl+M',
-            role: 'minimize'
-        }, {
-            label: 'Close',
-            accelerator: 'CmdOrCtrl+W',
-            role: 'close'
-        }]
-    }, {
-        label: 'Help',
-        role: 'help',
-        submenu: [{
-            label: 'Homepage',
-            click: function () {
-                require('electron').shell.openExternal(config.url_homepage);
-            }
-        }, {
-            label: 'Feedback',
-            click: function () {
-                require('electron').shell.openExternal(config.url_feedback);
-            }
-        }]
-    }];
-
-    if (is_debug) {
-        template[1].submenu.push({
-            label: 'Reload',
-            accelerator: 'CmdOrCtrl+R',
-            click: function (item, focusedWindow) {
-                if (focusedWindow)
-                    focusedWindow.reload();
-            }
-        });
-    }
-
-    if (process.platform == 'darwin') {
-        let name = require('electron').app.getName();
-        template.unshift({
-            label: name,
-            submenu: [{
-                label: 'About ' + name,
-                role: 'about'
-            }, {
-                label: 'Check for Updates...',
-                click: function () {
-                    require('./js/chk').chkUpdate(config.VERSION, mainWindow);
-                }
-            }, {
-                type: 'separator'
-            }, {
-                label: 'Services',
-                role: 'services',
-                submenu: []
-            }, {
-                type: 'separator'
-            }, {
-                label: 'Hide ' + name,
-                accelerator: 'Command+H',
-                role: 'hide'
-            }, {
-                label: 'Hide Others',
-                accelerator: 'Command+Shift+H',
-                role: 'hideothers'
-            }, {
-                label: 'Show All',
-                role: 'unhide'
-            }, {
-                type: 'separator'
-            }, {
-                label: 'Quit',
-                accelerator: 'Command+Q',
-                click: function () {
-                    force_quit = true;
-                    app.quit();
-                }
-            }]
-        });
-        // Window menu.
-        template[3].submenu.push(
-            {
-                type: 'separator'
-            },
-            {
-                label: 'Bring All to Front',
-                role: 'front'
-            }
-        );
-    }
-
-    let menu = Menu.buildFromTemplate(template);
-    Menu.setApplicationMenu(menu);
+    require('./js/menu').makeMenu(app);
+    require('./js/tray').makeTray(app);
 });