]> khamidou — GitHub mirrors - electron.git/commitdiff
Add a context menu for the initial default app.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 14 May 2013 13:39:00 +0000 (21:39 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 14 May 2013 13:39:00 +0000 (21:39 +0800)
browser/default_app/index.html
browser/default_app/main.js

index b7a6a78e6eeea1c964d7b2a45aca4b6c796b73d4..8e865787e07f9a03f3b6a2002680689bab0e21bb 100644 (file)
@@ -5,5 +5,13 @@
 </head>
 <body>
   Content
+  <script type="text/javascript" charset="utf-8">
+    var ipc = require('ipc');
+
+    window.addEventListener('contextmenu', function (e) {
+      e.preventDefault();
+      ipc.send('menu');
+    }, false);
+  </script>
 </body>
 </html>
index e19921fa94bb1fb5906d9e895f3c79d3dbc5ab48..15ac5840604de0231bc9e2e4ad0850960804ab38 100644 (file)
@@ -1,24 +1,17 @@
 var app = require('app');
 var delegate = require('atom_delegate');
 var ipc = require('ipc');
+var Menu = require('menu');
 var Window = require('window');
 
 var mainWindow = null;
+var menu = null;
 
 // Quit when all windows are closed.
 app.on('window-all-closed', function() {
   app.terminate();
 });
 
-// Echo every message back.
-ipc.on('message', function(process_id, routing_id) {
-  ipc.send.apply(ipc, arguments);
-});
-
-ipc.on('sync-message', function(event, process_id, routing_id) {
-  event.result = arguments;
-});
-
 delegate.browserMainParts.preMainMessageLoopRun = function() {
   mainWindow = new Window({ width: 800, height: 600 });
   mainWindow.loadUrl('file://' + __dirname + '/index.html');
@@ -33,4 +26,24 @@ delegate.browserMainParts.preMainMessageLoopRun = function() {
     console.log('closed');
     mainWindow = null;
   });
+
+  menu = new Menu;
+  menu.appendItem(0, 'Open GitHub');
+
+  menu.delegate = {
+    getAcceleratorForCommandId: function(commandId) {
+      if (commandId == 0)
+        return 'Ctrl+g';
+    }
+  }
+
+  menu.on('execute', function(commandId) {
+    if (commandId == 0)
+      mainWindow.loadUrl('https://github.com');
+  });
+
+  ipc.on('message', function(processId, routingId, type) {
+    if (type == 'menu')
+      menu.popup(mainWindow);
+  });
 }