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

Commit 06ded70

Browse files
Merge pull request #1419 from ssbc/electron-bump
Electron bump
2 parents deaacf9 + 4d9f238 commit 06ded70

File tree

9 files changed

+697
-519
lines changed

9 files changed

+697
-519
lines changed

assets/base.html

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
var electron = require('electron')
88
var localLog = console.log
99
var localError = console.error
10-
var remoteLog = electron.remote.getGlobal('console').log
11-
var remoteError = electron.remote.getGlobal('console').error
10+
var remoteLog = function (o) {
11+
const payload = JSON.parse(JSON.stringify(o, null, 2))
12+
electron.ipcRenderer.invoke('consoleLog', `${payload}`)
13+
}
14+
var remoteError = function (o) {
15+
const payload = JSON.parse(JSON.stringify(o, null, 2))
16+
electron.ipcRenderer.invoke('consoleError', `${payload}`)
17+
}
1218

1319
console.log = function (...args) {
1420
localLog.apply(console, args)
@@ -20,12 +26,35 @@
2026
remoteError(...args)
2127
}
2228

23-
process.exit = electron.remote.app.quit
29+
process.exit = function(status) {electron.ipcRenderer.sendSync('exit')}
2430
// redirect errors to stderr
2531
window.addEventListener('error', function (e) {
2632
e.preventDefault()
27-
console.error(e.error.stack || 'Uncaught ' + e.error)
33+
console.log(e)
34+
console.error(e.error?.stack || 'Uncaught ' + e.error)
35+
})
36+
37+
electron.ipcRenderer.once('window-setup', (event, msg) => {
38+
const {
39+
config,
40+
rootPath,
41+
data,
42+
title,
43+
} = msg
44+
var rootView = require(rootPath)
45+
var h = require('mutant/h')
46+
47+
electron.webFrame.setVisualZoomLevelLimits(1, 1)
48+
49+
document.documentElement.querySelector('head').appendChild(
50+
h('title', title)
51+
)
52+
53+
document.documentElement.replaceChild(h('body', [
54+
rootView(config, data)
55+
]), document.body)
2856
})
57+
2958
</script>
3059
</body>
3160
</html>

index.js

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,66 @@ electron.app.on('ready', () => {
150150
quitting = true
151151
})
152152

153-
electron.ipcMain.on('open-background-devtools', function () {
154-
if (windows.background) {
155-
windows.background.webContents.openDevTools({ mode: 'detach' })
156-
}
153+
electron.ipcMain.handle('navigation-menu-popup', (event, data) => {
154+
const {items, x, y} = data
155+
const window = event.sender
156+
const factor = event.sender.zoomFactor
157+
const menuItems = buildMenu(items, window)
158+
const menu = electron.Menu.buildFromTemplate(menuItems);
159+
menu.popup({
160+
window,
161+
x: Math.round(x * factor),
162+
y: Math.round(y * factor) + 4,
163+
});
157164
})
165+
166+
electron.ipcMain.handle('consoleLog', (ev, o) => console.log(o))
167+
electron.ipcMain.handle('consoleError', (ev, o) => console.error(o))
168+
electron.ipcMain.handle('badgeCount', (ev, count) => {
169+
electron.app.badgeCount = count;
170+
});
171+
electron.ipcMain.on('exit', (ev, code) => process.exit(code))
172+
158173
})
159174

175+
function openServerDevTools () {
176+
if (windows.background) {
177+
windows.background.webContents.openDevTools({ mode: 'detach' })
178+
}
179+
}
180+
181+
function buildMenu(items, window) {
182+
const result = []
183+
for (let item of items) {
184+
switch (item.type) {
185+
case 'separator':
186+
result.push(item)
187+
break
188+
case 'submenu':
189+
result.push({
190+
...item,
191+
submenu: buildMenu(item.submenu, window),
192+
})
193+
break
194+
case 'normal':
195+
result.push({
196+
...item,
197+
click: () => navigateTo(item.target)
198+
})
199+
break
200+
default:
201+
throw Error(`Unknown menu item of type "${item.type}": ${JSON.stringify(item, null, 2)}`);
202+
}
203+
}
204+
return result
205+
}
206+
207+
function navigateTo(target) {
208+
if (windows?.main) {
209+
windows.main.send('navigate-to', target)
210+
}
211+
}
212+
160213
function openMainWindow () {
161214
if (!windows.main) {
162215
const windowState = WindowState({
@@ -174,8 +227,11 @@ function openMainWindow () {
174227
title: 'Patchwork',
175228
show: true,
176229
backgroundColor: '#EEE',
177-
icon: Path.join(__dirname, 'assets/icon.png')
178-
})
230+
icon: Path.join(__dirname, 'assets/icon.png'),
231+
},
232+
openServerDevTools,
233+
navigateTo,
234+
)
179235

180236
windowState.manage(windows.main)
181237
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)