mirror of https://codeberg.org/pzp/zooboard.git
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
const { app, BrowserWindow } = require('electron')
|
|
const Path = require('node:path')
|
|
const URL = require('node:url')
|
|
|
|
// WARNING monkey patch! --------------------------------------
|
|
// const na = require('sodium-native')
|
|
// na.sodium_malloc = function sodium_malloc_monkey_patched(n) {
|
|
// return Buffer.alloc(n)
|
|
// }
|
|
// na.sodium_free = function sodium_free_monkey_patched() {}
|
|
// Electron > 20.3.8 breaks a napi method that `sodium_malloc`
|
|
// depends on to create external buffers. (see v8 memory cage)
|
|
//
|
|
// This crashes electron when called by various libraries, so
|
|
// we monkey-patch this particular function.
|
|
// ------------------------------------------------------------
|
|
|
|
function createWindow() {
|
|
const mainWindow = new BrowserWindow({
|
|
width: 800,
|
|
height: 600,
|
|
webPreferences: {
|
|
preload: Path.join(__dirname, 'preload.js'),
|
|
},
|
|
})
|
|
|
|
const startUrl =
|
|
process.env.ELECTRON_START_URL ??
|
|
URL.format({
|
|
pathname: Path.join(__dirname, '/../build/index.html'),
|
|
protocol: 'file:',
|
|
slashes: true,
|
|
})
|
|
mainWindow.loadURL(startUrl)
|
|
// mainWindow.loadFile('index.html')
|
|
|
|
// mainWindow.webContents.openDevTools()
|
|
}
|
|
|
|
app.whenReady().then(() => {
|
|
createWindow()
|
|
|
|
app.on('activate', function () {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
})
|
|
})
|
|
|
|
app.on('window-all-closed', function () {
|
|
if (process.platform !== 'darwin') app.quit()
|
|
})
|