pear-electron 1.0.31 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boot.js +34 -0
- package/electron-main.js +112 -0
- package/{boot.bundle → gui/decal.js} +1 -20255
- package/gui/gui.js +1938 -0
- package/gui/icons/tray.js +3 -0
- package/gui/index.js +2 -0
- package/gui/preload.js +425 -0
- package/package.json +8 -12
- package/preload.js +407 -0
package/boot.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** @typedef {import('pear-interface')} */
|
|
2
|
+
'use strict'
|
|
3
|
+
const { isElectron, isElectronRenderer, isElectronWorker, isWindows } = require('which-runtime')
|
|
4
|
+
const BOOT_ELECTRON_MAIN = 1
|
|
5
|
+
const BOOT_ELECTRON_PRELOAD = 2
|
|
6
|
+
const rtiFlagIx = process.argv.indexOf('--rti')
|
|
7
|
+
const RTI = rtiFlagIx > -1 && process.argv[rtiFlagIx + 1]
|
|
8
|
+
const state = RTI ? null : JSON.parse(process.argv.slice(isWindows ? -2 : -1)[0])
|
|
9
|
+
|
|
10
|
+
class API {
|
|
11
|
+
static RTI = RTI ? JSON.parse(RTI) : state.rti
|
|
12
|
+
static get CONSTANTS () { return require('pear-api/constants') }
|
|
13
|
+
config = {}
|
|
14
|
+
}
|
|
15
|
+
global.Pear = new API()
|
|
16
|
+
|
|
17
|
+
switch (getBootType()) {
|
|
18
|
+
case BOOT_ELECTRON_MAIN: {
|
|
19
|
+
require('./electron-main.js')
|
|
20
|
+
break
|
|
21
|
+
}
|
|
22
|
+
case BOOT_ELECTRON_PRELOAD: {
|
|
23
|
+
require('./preload.js')(state)
|
|
24
|
+
break
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getBootType () {
|
|
29
|
+
if (isElectron) {
|
|
30
|
+
return (isElectronRenderer || isElectronWorker)
|
|
31
|
+
? BOOT_ELECTRON_PRELOAD
|
|
32
|
+
: BOOT_ELECTRON_MAIN
|
|
33
|
+
}
|
|
34
|
+
}
|
package/electron-main.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const electron = require('electron')
|
|
3
|
+
const { isWindows, isMac, isLinux } = require('which-runtime')
|
|
4
|
+
const { command } = require('paparam')
|
|
5
|
+
const { SWAP, SOCKET_PATH, CONNECT_TIMEOUT } = require('pear-api/constants')
|
|
6
|
+
const crasher = require('pear-api/crasher')
|
|
7
|
+
const tryboot = require('pear-api/tryboot')
|
|
8
|
+
const rundef = require('pear-api/cmd/run')
|
|
9
|
+
const State = require('pear-api/state')
|
|
10
|
+
const GUI = require('./gui')
|
|
11
|
+
const argv = (process.argv.length > 1 && process.argv[1][0] === '-') ? process.argv.slice(1) : process.argv.slice(2)
|
|
12
|
+
const runix = argv.indexOf('--run')
|
|
13
|
+
if (runix > -1) argv.splice(runix, 1)
|
|
14
|
+
|
|
15
|
+
configureElectron()
|
|
16
|
+
crasher('electron-main', SWAP, argv.indexOf('--log') > -1)
|
|
17
|
+
const run = command('run', ...rundef, electronMain)
|
|
18
|
+
run.parse(argv)
|
|
19
|
+
run.running?.catch(console.error)
|
|
20
|
+
|
|
21
|
+
async function electronMain (cmd) {
|
|
22
|
+
const state = new State({
|
|
23
|
+
dir: global.Pear.constructor.RTI.dir,
|
|
24
|
+
link: cmd.args.link.replace('_||', '://'), // for Windows
|
|
25
|
+
flags: cmd.flags,
|
|
26
|
+
args: cmd.rest
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
if (state.error) {
|
|
30
|
+
console.error(state.error)
|
|
31
|
+
electron.app.quit(1)
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const gui = new GUI({
|
|
36
|
+
socketPath: SOCKET_PATH,
|
|
37
|
+
connectTimeout: CONNECT_TIMEOUT,
|
|
38
|
+
tryboot,
|
|
39
|
+
state
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
await gui.ready()
|
|
43
|
+
|
|
44
|
+
// note: would be unhandled rejection on failure, but should never fail:
|
|
45
|
+
if (await gui.ipc.wakeup(state.link, state.storage, state.key === null ? state.dir : null, state.link?.startsWith('pear://dev'))) {
|
|
46
|
+
electron.app.quit(0)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
electron.ipcMain.on('send-to', (e, id, channel, message) => { electron.webContents.fromId(id)?.send(channel, message) })
|
|
51
|
+
|
|
52
|
+
const app = await gui.app()
|
|
53
|
+
app.unloading().then(async () => {
|
|
54
|
+
await app.close()
|
|
55
|
+
}) // note: would be unhandled rejection on failure, but should never fail
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function configureElectron () {
|
|
59
|
+
const appName = applingName()
|
|
60
|
+
if (appName) {
|
|
61
|
+
process.title = appName
|
|
62
|
+
electron.app.on('ready', () => { process.title = appName })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'
|
|
66
|
+
|
|
67
|
+
/* c8 ignore start */
|
|
68
|
+
const inspix = process.argv.indexOf('--inspector-port')
|
|
69
|
+
if (inspix > -1) {
|
|
70
|
+
electron.app.commandLine.appendSwitch('remote-debugging-port', inspix + 1)
|
|
71
|
+
}
|
|
72
|
+
/* c8 ignore stop */
|
|
73
|
+
electron.protocol.registerSchemesAsPrivileged([
|
|
74
|
+
{ scheme: 'file', privileges: { secure: true, bypassCSP: true, corsEnabled: true, supportFetchAPI: true, allowServiceWorkers: true } }
|
|
75
|
+
])
|
|
76
|
+
|
|
77
|
+
// TODO: Remove when issue https://github.com/electron/electron/issues/29458 is resolved.
|
|
78
|
+
electron.app.commandLine.appendSwitch('disable-features', 'WindowCaptureMacV2')
|
|
79
|
+
|
|
80
|
+
// Needed for running fully-local WebRTC proxies
|
|
81
|
+
electron.app.commandLine.appendSwitch('allow-loopback-in-peer-connection')
|
|
82
|
+
|
|
83
|
+
if (isLinux && process.env.XDG_SESSION_TYPE === 'wayland') {
|
|
84
|
+
electron.app.commandLine.appendSwitch('enable-features', 'WebRTCPipeWireCapturer,WaylandWindowDecorations')
|
|
85
|
+
electron.app.commandLine.appendSwitch('ozone-platform-hint', 'auto')
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function applingPath () {
|
|
90
|
+
const i = process.argv.indexOf('--appling')
|
|
91
|
+
if (i === -1 || process.argv.length <= i + 1) return null
|
|
92
|
+
return process.argv[i + 1]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function applingName () {
|
|
96
|
+
const a = applingPath()
|
|
97
|
+
if (!a) return null
|
|
98
|
+
|
|
99
|
+
if (isMac) {
|
|
100
|
+
const end = a.indexOf('.app')
|
|
101
|
+
if (end === -1) return null
|
|
102
|
+
const start = a.lastIndexOf('/', end) + 1
|
|
103
|
+
return a.slice(start, end)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (isWindows) {
|
|
107
|
+
const name = a.slice(a.lastIndexOf('\\') + 1).replace(/\.exe$/i, '')
|
|
108
|
+
return name || null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return null
|
|
112
|
+
}
|