2024-08-11 12:35:14 -04:00
|
|
|
const { app, shell, session, BrowserWindow } = require('electron');
|
2024-06-14 17:38:07 -04:00
|
|
|
const path = require('path');
|
|
|
|
|
const server = require('@gridspace/app-server');
|
|
|
|
|
|
|
|
|
|
const basDir = __dirname;
|
|
|
|
|
const usrDir = app.getPath("userData");
|
2024-06-14 17:48:01 -04:00
|
|
|
const appDir = path.join(usrDir, 'gapp');
|
2024-06-14 17:38:07 -04:00
|
|
|
const cnfDir = path.join(appDir, 'conf');
|
|
|
|
|
const logDir = path.join(appDir, 'logs');
|
|
|
|
|
const datDir = path.join(appDir, 'data');
|
2024-06-17 15:21:50 -04:00
|
|
|
const debug = process.argv.slice(2).map(v => v.replaceAll('-', '')).contains('debugg');
|
|
|
|
|
const devel = process.argv.slice(2).map(v => v.replaceAll('-', '')).contains('devel');
|
2024-06-14 17:38:07 -04:00
|
|
|
|
2025-07-07 18:51:17 -04:00
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
|
|
|
|
|
|
2024-06-14 17:38:07 -04:00
|
|
|
// console.log({ appDir, usrDir, logDir, datDir, basDir });
|
|
|
|
|
// console.log({ argv: process.argv, debug, devel });
|
|
|
|
|
// console.log({
|
|
|
|
|
// cwd: process.cwd(),
|
|
|
|
|
// dir: require('fs').readdirSync('.'),
|
|
|
|
|
// out: require('fs').readdirSync(appDir),
|
|
|
|
|
// ___: require('fs').readdirSync(basDir)
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
server({
|
2024-06-17 15:21:50 -04:00
|
|
|
port: 5309,
|
2024-06-14 17:38:07 -04:00
|
|
|
apps: basDir,
|
|
|
|
|
data: datDir,
|
|
|
|
|
conf: cnfDir,
|
|
|
|
|
logs: logDir,
|
2024-06-17 15:21:50 -04:00
|
|
|
cache: path.join(basDir, "data", "cache"),
|
|
|
|
|
single: true,
|
2024-06-16 21:48:41 -04:00
|
|
|
electron: true,
|
2024-06-14 17:38:07 -04:00
|
|
|
debug
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function createWindow() {
|
|
|
|
|
const mainWindow = new BrowserWindow({
|
2025-02-03 18:01:47 -05:00
|
|
|
width: 1600,
|
2024-06-14 17:38:07 -04:00
|
|
|
height: 900,
|
|
|
|
|
webPreferences: {
|
|
|
|
|
// preload: path.join(__dirname, 'preload.js')
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-17 15:21:50 -04:00
|
|
|
mainWindow.loadURL('http://localhost:5309/kiri');
|
|
|
|
|
|
2024-07-10 18:57:24 -04:00
|
|
|
// default normal url navigation or page opens to happen outside Electron
|
2024-06-17 15:21:50 -04:00
|
|
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
2024-07-23 13:08:17 -04:00
|
|
|
// console.log('EXTERNAL', details);
|
2024-06-17 15:21:50 -04:00
|
|
|
shell.openExternal(details.url);
|
|
|
|
|
return { action: 'deny' }
|
|
|
|
|
});
|
2024-06-14 17:38:07 -04:00
|
|
|
|
2024-07-10 18:57:24 -04:00
|
|
|
// prevent "other" urls from opening inside Electron (alerts are problematic)
|
|
|
|
|
mainWindow.webContents.on('will-navigate', (event, url) => {
|
2024-07-23 13:08:17 -04:00
|
|
|
// console.log('DIVERT', url);
|
2025-02-03 18:22:19 -05:00
|
|
|
if (url.endsWith('/kiri') || url.endsWith('/kiri/')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (url.endsWith('/mesh') || url.endsWith('/mesh/')) {
|
2024-07-23 13:08:17 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2024-07-10 18:57:24 -04:00
|
|
|
event.preventDefault();
|
|
|
|
|
shell.openExternal(url);
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-14 17:38:07 -04:00
|
|
|
if (devel) {
|
|
|
|
|
console.log("opening developer tools");
|
|
|
|
|
mainWindow.webContents.openDevTools();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-11 12:35:14 -04:00
|
|
|
app.on('ready', () => {
|
|
|
|
|
session.defaultSession.clearCache().then(createWindow);
|
|
|
|
|
});
|
2024-06-17 15:21:50 -04:00
|
|
|
|
2024-06-14 17:38:07 -04:00
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
|
app.quit();
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-17 15:21:50 -04:00
|
|
|
|
2024-06-14 17:38:07 -04:00
|
|
|
app.on('activate', () => {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
|
createWindow();
|
|
|
|
|
}
|
|
|
|
|
});
|