git ssb

10+

Matt McKegg / patchwork



Commit 05d26ec79bdbb7f7583ee169d8ed48689f4f6bad

Replace mousetrap in favour of using Electron API

Chris Adams committed on 5/12/2018, 9:27:02 AM
Parent: 20e56e6bb267f73d48091b7c9576ae3f9bab0bee

Files changed

index.jschanged
main-window.jschanged
package.jsonchanged
index.jsView
@@ -44,9 +44,33 @@
4444 electron.app.on('ready', () => {
4545 setupContext('ssb', {
4646 server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
4747 }, () => {
48 +
49 + var browserWindow = openMainWindow();
4850 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 +
4973 var view = menu.find(x => x.label === 'View')
5074 view.submenu = [
5175 { role: 'reload' },
5276 { role: 'toggledevtools' },
@@ -73,10 +97,10 @@
7397 { type: 'separator' },
7498 { role: 'front' }
7599 ]
76100 }
101 +
77102 Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
78- openMainWindow()
79103 })
80104
81105 electron.app.on('activate', function (e) {
82106 if (windows.main) {
@@ -126,8 +150,9 @@
126150 windows.main = null
127151 if (process.platform !== 'darwin') electron.app.quit()
128152 })
129153 }
154 + return windows.main
130155 }
131156
132157 function setupContext (appName, opts, cb) {
133158 ssbConfig = require('ssb-config/inject')(appName, extend({
main-window.jsView
@@ -11,11 +11,9 @@
1111 var LatestUpdate = require('./lib/latest-update')
1212 var ref = require('ssb-ref')
1313 var setupContextMenuAndSpellCheck = require('./lib/context-menu-and-spellcheck')
1414 var watch = require('mutant/watch')
15-var mousetrap = require("mousetrap")
1615
17-
1816 module.exports = function (config) {
1917 var sockets = combine(
2018 overrideConfig(config),
2119 addCommand('app.navigate', navigate),
@@ -67,18 +65,18 @@
6765
6866 var views = api.app.views(api.page.html.render, [
6967 '/public', '/private', id, '/mentions'
7068 ])
71-
69 +
7270 var pendingCount = views.get('/mentions').pendingUpdates
7371
7472 watch(pendingCount, count => {
7573 electron.remote.app.setBadgeCount(count)
7674 })
7775
78-
76 + electron.ipcRenderer.on("goForward", views.goForward)
77 + electron.ipcRenderer.on("goBack", views.goBack)
7978
80-
8179 document.head.appendChild(
8280 h('style', {
8381 innerHTML: computed(api.settings.obs.get('patchwork.theme', 'light'), themeName => {
8482 return themes[themeName] || themes['light']
@@ -151,17 +149,8 @@
151149 } else {
152150 api.app.navigate(href)
153151 }
154152 })
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-
164153 return [container, previewElement]
165154
166155 // scoped
167156
package.jsonView
@@ -38,9 +38,8 @@
3838 "level": "~1.7.0",
3939 "lrucache": "^1.0.2",
4040 "micro-css": "^2.0.1",
4141 "moment": "^2.18.1",
42- "mousetrap": "^1.6.1",
4342 "mutant": "^3.21.2",
4443 "mutant-pull-reduce": "^1.1.0",
4544 "obv": "0.0.1",
4645 "patch-settings": "~1.1.0",

Built with git-ssb-web