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