fix electron build/run
This commit is contained in:
parent
1ca497ca5d
commit
e72ac11fbe
6 changed files with 33 additions and 24 deletions
|
|
@ -11,6 +11,8 @@ const datDir = path.join(appDir, 'data');
|
|||
const debug = process.argv.slice(2).map(v => v.replaceAll('-', '')).contains('debugg');
|
||||
const devel = process.argv.slice(2).map(v => v.replaceAll('-', '')).contains('devel');
|
||||
|
||||
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
|
||||
|
||||
// console.log({ appDir, usrDir, logDir, datDir, basDir });
|
||||
// console.log({ argv: process.argv, debug, devel });
|
||||
// console.log({
|
||||
|
|
|
|||
24
app.js
24
app.js
|
|
@ -20,7 +20,6 @@ const append = { mesh:'', kiri:'' };
|
|||
const code = {};
|
||||
const mods = {};
|
||||
const load = [];
|
||||
const synth = {};
|
||||
const api = {};
|
||||
|
||||
let forceUseCache = false;
|
||||
|
|
@ -226,6 +225,7 @@ function initModule(mod, file, dir) {
|
|||
},
|
||||
inject: (code, file, opt = {}) => {
|
||||
const body = fs.readFileSync(dir + '/' + file);
|
||||
// console.log({ inject: code, file, opt });
|
||||
if (opt.first) {
|
||||
append[code] = body.toString() + '\n' + append[code];
|
||||
} else {
|
||||
|
|
@ -314,19 +314,19 @@ function handleVersion(req, res, next) {
|
|||
// in production serve packed bundles
|
||||
let { path } = req.app;
|
||||
if (path === '/lib/mesh/work.js') {
|
||||
req.url = req.app.path = '/lib/pack/mesh-work.js';
|
||||
req.url = '/lib/pack/mesh-work.js';
|
||||
} else if (path === '/lib/main/mesh.js') {
|
||||
req.url = req.app.path = '/lib/pack/mesh-main.js';
|
||||
req.url = '/lib/pack/mesh-main.js';
|
||||
} else if (path === '/lib/kiri-run/minion.js') {
|
||||
req.url = req.app.path = '/lib/pack/kiri-pool.js';
|
||||
req.url = '/lib/pack/kiri-pool.js';
|
||||
} else if (path === '/lib/kiri-run/worker.js') {
|
||||
req.url = req.app.path = '/lib/pack/kiri-work.js';
|
||||
req.url = '/lib/pack/kiri-work.js';
|
||||
} else if (path === '/lib/main/kiri.js') {
|
||||
req.url = req.app.path = '/lib/pack/kiri-main.js';
|
||||
req.url = '/lib/pack/kiri-main.js';
|
||||
}
|
||||
// add cors headers on rewrite
|
||||
if (path !== req.url) {
|
||||
console.log('rewrite', path, req.url);
|
||||
// console.log('rewrite', path, req.url);
|
||||
addCorsHeaders(req, res);
|
||||
}
|
||||
next();
|
||||
|
|
@ -388,6 +388,11 @@ function serveWasm(req, res, next) {
|
|||
|
||||
// pack/concat device script strings to inject into /code/ scripts
|
||||
function generateDevices() {
|
||||
if (process.versions.electron) {
|
||||
// bail when running inside electron
|
||||
console.log('skipping device generation in electron');
|
||||
return;
|
||||
}
|
||||
let root = PATH.join(dir,"src","kiri-dev");
|
||||
let devs = {};
|
||||
fs.readdirSync(root).forEach(type => {
|
||||
|
|
@ -400,7 +405,6 @@ function generateDevices() {
|
|||
});
|
||||
});
|
||||
let dstr = JSON.stringify(devs);
|
||||
synth.devices = `self.devices = ${dstr};`;
|
||||
fs.writeFileSync(PATH.join(dir,"src","pack","devices.js"), `export const devices = ${dstr};`);
|
||||
}
|
||||
|
||||
|
|
@ -533,12 +537,12 @@ function rewriteHtmlVersion(req, res, next) {
|
|||
}
|
||||
if ([
|
||||
"/lib/main/kiri.js",
|
||||
"/lib/main/mesh.js",
|
||||
"/lib/main/mesh.js"
|
||||
].indexOf(req.app.path) >= 0) {
|
||||
const data = append[req.app.path.split('/')[3].split('.')[0]];
|
||||
// console.log({ append: req.app.path, data: data?.length });
|
||||
|
||||
if (!data) return next();
|
||||
console.log({ append: req.app.path, data: data.length });
|
||||
|
||||
const real_write = res.write;
|
||||
const real_end = res.end;
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ self.kiri.load(api => {
|
|||
|
||||
function monitoring() {
|
||||
let mon = selected?.rec?.serial ?? '';
|
||||
ui.setVisible($('bbl_connect'), select.value !== '' && monitors.indexOf(mon) < 0);
|
||||
ui.setVisible($('bbl_connect'), select?.value && monitors.indexOf(mon) < 0);
|
||||
return mon ? true : false;
|
||||
}
|
||||
|
||||
|
|
@ -660,7 +660,7 @@ self.kiri.load(api => {
|
|||
}
|
||||
});
|
||||
|
||||
api.event.on("init-done", function() {
|
||||
api.event.on("load-done", function() {
|
||||
if (init) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
if (self.kiri)
|
||||
self.kiri.load(api => {
|
||||
console.log('ELECTRON MODULE RUNNING');
|
||||
api.electron = {};
|
||||
api.event.on('init-done', () => {
|
||||
$('app-name-text').innerText = "More Info";
|
||||
$('top-sep').style.display = 'flex';
|
||||
if (self.kiri && !self.kiri.electron) {
|
||||
self.kiri.electron = {};
|
||||
self.kiri.load(api => {
|
||||
console.log('ELECTRON MODULE RUNNING');
|
||||
api.event.on('load-done', () => {
|
||||
$('app-name-text').innerText = "More Info";
|
||||
$('top-sep').style.display = 'flex';
|
||||
});
|
||||
api.stats.set('kiri', api.version + 'e');
|
||||
});
|
||||
api.stats.set('kiri', self.kiri.version + 'e');
|
||||
});
|
||||
|
||||
if (self.mesh && self.mesh.api) {
|
||||
self.mesh.api.electron = {};
|
||||
}
|
||||
|
||||
if (self.mesh && self.mesh) {
|
||||
self.mesh.electron = {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@
|
|||
"mklinks": "find src web -type l | xargs -I{} sh -c 'echo \"{},$(readlink {})\"' > links.csv",
|
||||
"mac-verify": "spctl --assess -vv --type install dist/*/*.app",
|
||||
"clear-cache": "rm -rf data/cache/* dist/ tmp/*",
|
||||
"prebuild": "node bin/electron-pre.js",
|
||||
"prebuild": "npm run setup && node bin/electron-pre.js",
|
||||
"postbuild": "node bin/electron-post.js",
|
||||
"preinstall": "",
|
||||
"docs-dev": "docusaurus start --config conf/docusaurus.config.js",
|
||||
|
|
|
|||
|
|
@ -21,10 +21,12 @@ function safeExec(fn) {
|
|||
function checkReady() {
|
||||
if (document.readyState === 'complete') {
|
||||
kiri.api = run();
|
||||
self.$ = kiri.api.web.$;
|
||||
for (let fn of load) {
|
||||
safeExec(fn);
|
||||
}
|
||||
load = undefined;
|
||||
kiri.api.event.emit('load-done', stats);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue