Commit 05d26ec79bdbb7f7583ee169d8ed48689f4f6bad
Replace mousetrap in favour of using Electron API
Chris Adams committed on 5/12/2018, 9:27:02 AMParent: 20e56e6bb267f73d48091b7c9576ae3f9bab0bee
Files changed
index.js | changed |
main-window.js | changed |
package.json | changed |
index.js | ||
---|---|---|
@@ -44,9 +44,33 @@ | ||
44 | 44 … | electron.app.on('ready', () => { |
45 | 45 … | setupContext('ssb', { |
46 | 46 … | server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb')) |
47 | 47 … | }, () => { |
48 … | + | |
49 … | + var browserWindow = openMainWindow(); | |
48 | 50 … | var menu = defaultMenu(electron.app, electron.shell) |
51 … | + | |
52 … | + menu.splice(4, 0, { | |
53 … | + label: "History", | |
54 … | + submenu: [ | |
55 … | + { | |
56 … | + label: "Forward", | |
57 … | + accelerator: "CmdOrCtrl+]", | |
58 … | + click: () => { | |
59 … | + browserWindow.webContents.send('goForward') | |
60 … | + } | |
61 … | + }, | |
62 … | + { | |
63 … | + label: "Back", | |
64 … | + accelerator: "CmdOrCtrl+[", | |
65 … | + click: () => { | |
66 … | + browserWindow.webContents.send("goBack") | |
67 … | + } | |
68 … | + } | |
69 … | + ] | |
70 … | + }); | |
71 … | + | |
72 … | + | |
49 | 73 … | var view = menu.find(x => x.label === 'View') |
50 | 74 … | view.submenu = [ |
51 | 75 … | { role: 'reload' }, |
52 | 76 … | { role: 'toggledevtools' }, |
@@ -73,10 +97,10 @@ | ||
73 | 97 … | { type: 'separator' }, |
74 | 98 … | { role: 'front' } |
75 | 99 … | ] |
76 | 100 … | } |
101 … | + | |
77 | 102 … | Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) |
78 | - openMainWindow() | |
79 | 103 … | }) |
80 | 104 … | |
81 | 105 … | electron.app.on('activate', function (e) { |
82 | 106 … | if (windows.main) { |
@@ -126,8 +150,9 @@ | ||
126 | 150 … | windows.main = null |
127 | 151 … | if (process.platform !== 'darwin') electron.app.quit() |
128 | 152 … | }) |
129 | 153 … | } |
154 … | + return windows.main | |
130 | 155 … | } |
131 | 156 … | |
132 | 157 … | function setupContext (appName, opts, cb) { |
133 | 158 … | ssbConfig = require('ssb-config/inject')(appName, extend({ |
main-window.js | |||
---|---|---|---|
@@ -11,11 +11,9 @@ | |||
11 | 11 … | var LatestUpdate = require('./lib/latest-update') | |
12 | 12 … | var ref = require('ssb-ref') | |
13 | 13 … | var setupContextMenuAndSpellCheck = require('./lib/context-menu-and-spellcheck') | |
14 | 14 … | var watch = require('mutant/watch') | |
15 | -var mousetrap = require("mousetrap") | ||
16 | 15 … | ||
17 | - | ||
18 | 16 … | module.exports = function (config) { | |
19 | 17 … | var sockets = combine( | |
20 | 18 … | overrideConfig(config), | |
21 | 19 … | addCommand('app.navigate', navigate), | |
@@ -67,18 +65,18 @@ | |||
67 | 65 … | ||
68 | 66 … | var views = api.app.views(api.page.html.render, [ | |
69 | 67 … | '/public', '/private', id, '/mentions' | |
70 | 68 … | ]) | |
71 | - | ||
69 … | + | ||
72 | 70 … | var pendingCount = views.get('/mentions').pendingUpdates | |
73 | 71 … | ||
74 | 72 … | watch(pendingCount, count => { | |
75 | 73 … | electron.remote.app.setBadgeCount(count) | |
76 | 74 … | }) | |
77 | 75 … | ||
78 | - | ||
76 … | + electron.ipcRenderer.on("goForward", views.goForward) | ||
77 … | + electron.ipcRenderer.on("goBack", views.goBack) | ||
79 | 78 … | ||
80 | - | ||
81 | 79 … | document.head.appendChild( | |
82 | 80 … | h('style', { | |
83 | 81 … | innerHTML: computed(api.settings.obs.get('patchwork.theme', 'light'), themeName => { | |
84 | 82 … | return themes[themeName] || themes['light'] | |
@@ -151,17 +149,8 @@ | |||
151 | 149 … | } else { | |
152 | 150 … | api.app.navigate(href) | |
153 | 151 … | } | |
154 | 152 … | }) | |
155 | - | ||
156 | - | ||
157 | - // TODO - should this be in a separate file instead? | ||
158 | - // And should we be using the Electron MenuItem API over mousetrap? | ||
159 | - | ||
160 | - mousetrap.bind(["command+[", "command+left"], views.goBack) | ||
161 | - mousetrap.bind(["command+]", "command+right"], views.goForward) | ||
162 | - | ||
163 | - | ||
164 | 153 … | return [container, previewElement] | |
165 | 154 … | ||
166 | 155 … | // scoped | |
167 | 156 … |
Built with git-ssb-web