From 783f39bb4e34a643699e0c6f387ee0d5225aac89 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 11 Nov 2025 19:16:55 -0500 Subject: [PATCH] add install/uninstall options in the setup menu --- bin/bundle.config.json | 4 ++-- bin/bundler.mjs | 11 ++++++++--- package.json | 4 +++- src/main/kiri.js | 15 ++++++++++++++- web/boot/service.js | 4 ++-- web/kiri/index.html | 9 +++++++++ web/kiri/lang/en.js | 2 ++ web/kiri/manifest.json | 2 +- 8 files changed, 41 insertions(+), 10 deletions(-) diff --git a/bin/bundle.config.json b/bin/bundle.config.json index e7bd3566..97890b62 100644 --- a/bin/bundle.config.json +++ b/bin/bundle.config.json @@ -1,7 +1,7 @@ { "compress": false, "outputs": { - "bundle": "./web/boot/bundle.bin" + "bundle": "./web/boot/bundle-{version}.bin" }, "inputs": [ { "root": "web", "prefix": "" }, @@ -12,6 +12,6 @@ ], "excludes": [ "src/pack", - "web/boot/bundle.bin" + "web/boot/bundle*" ] } diff --git a/bin/bundler.mjs b/bin/bundler.mjs index e63aba3e..12f43186 100644 --- a/bin/bundler.mjs +++ b/bin/bundler.mjs @@ -3,8 +3,10 @@ import path from 'path'; import uglify from 'uglify-js'; import { Buffer } from 'buffer'; +const version = JSON.parse(fs.readFileSync('package.json', 'utf8')).version; const cfg = JSON.parse(fs.readFileSync(process.argv[2] || './bin/bundle.config.json', 'utf8')); const { inputs, outputs, excludes, compress } = cfg; +const excludePre = (excludes ?? []).filter(s => s.indexOf('*') >= 0).map(s => s.replaceAll('*','')); const envcomp = process.env.COMPRESS ? JSON.parse(process.env.COMPRESS) : undefined; const debug = process.env.DEBUG; @@ -65,7 +67,7 @@ if (compEnable) { function fileTime(path) { try { - return (fs.statSync(path).ctimeMs/1000) | 0; + return (fs.statSync(path).ctimeMs / 1000) | 0; } catch (e) { return 0; } @@ -75,6 +77,9 @@ for (const { file, virt } of entries) { if (excludes.indexOf(file) >= 0) { continue; } + if (excludePre.filter(ex => file.startsWith(ex)).length) { + continue; + } let record = cache.get(file); if (record) { if (debug) console.log({ alias: virt, from: file }); @@ -86,7 +91,7 @@ for (const { file, virt } of entries) { let cpath = path.resolve(cacheDir, file); if (fileTime(cpath) > fileTime(file)) { data = fs.readFileSync(cpath); - console.log('cached', file); + // console.log('cached', file); } else { console.log('compress', file); data = uglify.minify(data.toString(), { @@ -141,7 +146,7 @@ const header = Buffer.concat([count, ...headerParts]); const full = Buffer.concat([header, ...dataParts]); // --- write final bundle --- -const outPath = outputs.bundle || './bundle.bin'; +const outPath = (outputs.bundle || './bundle.bin').replace('{version}', version); fs.mkdirSync(path.dirname(outPath), { recursive: true }); fs.writeFileSync(outPath, full); // ⚡ write raw binary diff --git a/package.json b/package.json index 433966d5..47cea945 100644 --- a/package.json +++ b/package.json @@ -93,13 +93,15 @@ "build-win-arm": "npm run build -- --win --arm64", "build-mac": "npm run build -- --mac --arm64", "build-mac-intel": "npm run build -- --mac --x64", + "bundle": "npm run dev -- --alt --dryrun && COMPRESS=1 node bin/bundler.mjs", + "bundle:dev": "npm run dev -- --alt --dryrun && node bin/bundler.mjs", "clean": "rm -rf build data dist src/pack tmp src.old web.old .bcache", "docs-dev": "docusaurus start --config conf/docusaurus.config.js", "docs-build": "docusaurus build --config conf/docusaurus.config.js", "docs-serve": "docusaurus serve --config conf/docusaurus.config.js", "docs-check": "prettier --config ./conf/prettier.config.js ./docs --check", "dev": "npm run webpack-ext && gs-app-server --debug --single", - "prod": "npm run webpack-ext && npm run webpack-src prod && COMPRESS=1 node bin/bundler.mjs && gs-app-server", + "prod": "npm run webpack-ext && npm run webpack-src prod && npm run bundle && gs-app-server", "prod-pack": "npm run webpack-ext && npm run webpack-src prod", "prod-dryrun": "gs-app-server --dryrun", "start": "npm run prebuild prod && electron .", diff --git a/src/main/kiri.js b/src/main/kiri.js index b68b0a90..185a9cf3 100644 --- a/src/main/kiri.js +++ b/src/main/kiri.js @@ -37,7 +37,8 @@ function safeExec(fn) { function checkReady() { if (document.readyState === 'complete') { - console.log(`kiri | boot ctrl | ` + (navigator.serviceWorker.controller ? true : false)); + let bootctrl = navigator.serviceWorker.controller; + console.log(`kiri | boot ctrl | ` + (bootctrl ? true : false)); kiri.api = run(); self.$ = kiri.api.web.$; for (let fn of load) { @@ -45,6 +46,18 @@ function checkReady() { } load = undefined; kiri.api.event.emit('load-done', stats); + if (bootctrl) { + $('install').classList.add('hide'); + $('uninstall').classList.remove('hide'); + $('uninstall').onclick = () => { + bootctrl.postMessage({ clear: true, disable: true }); + location.reload(); + } + } else { + $('install').onclick = () => { + location.replace('/boot'); + } + } } } diff --git a/web/boot/service.js b/web/boot/service.js index 8d0f405a..2c5d6625 100644 --- a/web/boot/service.js +++ b/web/boot/service.js @@ -1,11 +1,10 @@ // --- configurable --- const CACHE_VERSION = 'boot-001'; -const BUNDLE_URL = '/boot/bundle.bin'; const VERSION_KEY = '/__version__'; let loaded = 0; let mode = 'cached'; -let currentVersion = null; +let BUNDLE_URL = '/boot/bundle.bin'; // --- logging --- const log = (...a) => console.log('[SW]', ...a); @@ -30,6 +29,7 @@ self.addEventListener('message', e => { unregister(); } else if (version !== undefined) { mode = 'cached'; + BUNDLE_URL = `/boot/bundle-${version}.bin`; log('version', version); ensureVersion(version); } diff --git a/web/kiri/index.html b/web/kiri/index.html index f9baab76..d8bc28c3 100644 --- a/web/kiri/index.html +++ b/web/kiri/index.html @@ -229,6 +229,15 @@ +
+
+ + +
+
+ + +
diff --git a/web/kiri/lang/en.js b/web/kiri/lang/en.js index e8ccb87c..cfba031e 100644 --- a/web/kiri/lang/en.js +++ b/web/kiri/lang/en.js @@ -27,6 +27,7 @@ self.lang['en-us'] = { hide: "hide", // left render pop menu (invisible) home: "home", import: "import", + install: "install", language: "language", left: "left", machines: "machines", // device or machine @@ -58,6 +59,7 @@ self.lang['en-us'] = { tools: "tools", // CAM tool menu button top: "top", type: "type", // CAM tool type + uninstall: "uninstall", version: "version", view: "view", // left view pop menu wire: "wire", // left render pop menu diff --git a/web/kiri/manifest.json b/web/kiri/manifest.json index c08e6a84..01f7287f 100644 --- a/web/kiri/manifest.json +++ b/web/kiri/manifest.json @@ -2,7 +2,7 @@ "name": "Kiri:Moto 4.4.0", "short_name": "Kiri:Moto", "description": "Slicer for 3D printers, CNC mills, laser cutters and more", - "start_url": "/kiri/", + "start_url": "/boot/", "id": "/kiri/", "display": "standalone", "theme_color": "#7e99b7",