Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 4d9f238

Browse files
Port context menu to electron 11 & electron-context-menu
The old menu was handling more than we needed: it was doing spell-checking, which has been built into electron since v8.0.0, and it was also overly complicated. The new version should be a bit easier to read. Avoiding use of the remote module means that a lot of things have to be handled via explicit IPC (instead of relying on implicit proxy objects from the remote module) and especially for the "Copy Message Text" and "Copy Message Reference" items and such I had to hack a bit. As a result, this *might* still have race conditions that would mean that text doesn't get copied, or an outdated version of it.
1 parent 8a33480 commit 4d9f238

File tree

6 files changed

+470
-210
lines changed

6 files changed

+470
-210
lines changed

index.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,14 @@ electron.app.on('ready', () => {
170170
});
171171
electron.ipcMain.on('exit', (ev, code) => process.exit(code))
172172

173-
electron.ipcMain.on('open-background-devtools', function () {
174-
if (windows.background) {
175-
windows.background.webContents.openDevTools({ mode: 'detach' })
176-
}
177-
})
178173
})
179174

175+
function openServerDevTools () {
176+
if (windows.background) {
177+
windows.background.webContents.openDevTools({ mode: 'detach' })
178+
}
179+
}
180+
180181
function buildMenu(items, window) {
181182
const result = []
182183
for (let item of items) {
@@ -193,9 +194,7 @@ function buildMenu(items, window) {
193194
case 'normal':
194195
result.push({
195196
...item,
196-
click: () => {
197-
window.send('navigate-to', item.target)
198-
}
197+
click: () => navigateTo(item.target)
199198
})
200199
break
201200
default:
@@ -205,6 +204,12 @@ function buildMenu(items, window) {
205204
return result
206205
}
207206

207+
function navigateTo(target) {
208+
if (windows?.main) {
209+
windows.main.send('navigate-to', target)
210+
}
211+
}
212+
208213
function openMainWindow () {
209214
if (!windows.main) {
210215
const windowState = WindowState({
@@ -222,8 +227,11 @@ function openMainWindow () {
222227
title: 'Patchwork',
223228
show: true,
224229
backgroundColor: '#EEE',
225-
icon: Path.join(__dirname, 'assets/icon.png')
226-
})
230+
icon: Path.join(__dirname, 'assets/icon.png'),
231+
},
232+
openServerDevTools,
233+
navigateTo,
234+
)
227235

228236
windowState.manage(windows.main)
229237
windows.main.setSheetOffset(40)

lib/context-menu-and-spellcheck.js

Lines changed: 0 additions & 196 deletions
This file was deleted.

0 commit comments

Comments
 (0)