runbay 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/main/index.js +55 -26
- package/package.json +1 -1
package/out/main/index.js
CHANGED
|
@@ -632,7 +632,6 @@ async function scanAll(onBatch, onStatus) {
|
|
|
632
632
|
const REGISTRY = process.env.RUNBAY_REGISTRY ?? "https://registry.npmjs.org";
|
|
633
633
|
const PKG = "runbay";
|
|
634
634
|
const SIM_CMD = process.env.RUNBAY_SELFUPDATE_CMD;
|
|
635
|
-
const SIMULATED = !!SIM_CMD;
|
|
636
635
|
let available = null;
|
|
637
636
|
function selfUpdateStatus() {
|
|
638
637
|
return available;
|
|
@@ -658,46 +657,76 @@ async function checkSelfUpdate() {
|
|
|
658
657
|
}
|
|
659
658
|
return available;
|
|
660
659
|
}
|
|
661
|
-
async function
|
|
660
|
+
async function globalRoot() {
|
|
662
661
|
try {
|
|
663
|
-
|
|
664
|
-
return electron.app.getAppPath().toLowerCase().startsWith(root.toLowerCase());
|
|
662
|
+
return (await run("npm", ["root", "-g"], { shim: true, timeout: 3e4 })).trim();
|
|
665
663
|
} catch {
|
|
666
|
-
return
|
|
664
|
+
return null;
|
|
667
665
|
}
|
|
668
666
|
}
|
|
667
|
+
async function installedGlobally() {
|
|
668
|
+
const root = await globalRoot();
|
|
669
|
+
return !!root && electron.app.getAppPath().toLowerCase().startsWith(root.toLowerCase());
|
|
670
|
+
}
|
|
671
|
+
function runCommand(command) {
|
|
672
|
+
return new Promise((resolve2, reject) => {
|
|
673
|
+
const child = node_child_process.spawn(command, { shell: true, windowsHide: true });
|
|
674
|
+
const timer = setTimeout(() => {
|
|
675
|
+
child.kill();
|
|
676
|
+
reject(new Error("npm timed out"));
|
|
677
|
+
}, 5 * 6e4);
|
|
678
|
+
child.on("error", reject);
|
|
679
|
+
child.on("close", (code) => {
|
|
680
|
+
clearTimeout(timer);
|
|
681
|
+
if (code === 0) resolve2();
|
|
682
|
+
else reject(new Error(`npm exited with code ${code}`));
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
}
|
|
669
686
|
async function applySelfUpdate() {
|
|
670
687
|
if (!available) return { state: "error", message: "No update pending" };
|
|
671
688
|
const target = available.latest;
|
|
672
689
|
const registryFlag = REGISTRY === "https://registry.npmjs.org" ? "" : ` --registry "${REGISTRY}"`;
|
|
673
|
-
|
|
674
|
-
|
|
690
|
+
if (SIM_CMD) {
|
|
691
|
+
try {
|
|
692
|
+
await runCommand(SIM_CMD);
|
|
693
|
+
} catch (err) {
|
|
694
|
+
return { state: "error", message: err instanceof Error ? err.message : String(err) };
|
|
695
|
+
}
|
|
696
|
+
available = null;
|
|
697
|
+
return { state: "done", message: `Updated to ${target} — restart to apply` };
|
|
698
|
+
}
|
|
699
|
+
if (!await installedGlobally()) {
|
|
675
700
|
return { state: "manual", message: `npm install -g ${PKG}@latest` };
|
|
676
701
|
}
|
|
702
|
+
const root = await globalRoot();
|
|
703
|
+
const shim = node_path.join(node_path.dirname(root), `${PKG}.cmd`);
|
|
704
|
+
const script = node_path.join(electron.app.getPath("userData"), "update.cmd");
|
|
705
|
+
const log = node_path.join(electron.app.getPath("userData"), "update.log");
|
|
706
|
+
const install = `call npm install -g ${PKG}@latest${registryFlag}`;
|
|
707
|
+
const body = [
|
|
708
|
+
"@echo off",
|
|
709
|
+
"ping -n 5 127.0.0.1 >nul",
|
|
710
|
+
// le temps que l'app se ferme et relâche ses fichiers
|
|
711
|
+
`${install} > "${log}" 2>&1`,
|
|
712
|
+
"if errorlevel 1 (",
|
|
713
|
+
" ping -n 31 127.0.0.1 >nul",
|
|
714
|
+
// le registre met parfois une minute à propager une publication prouvée
|
|
715
|
+
`${install} --prefer-online >> "${log}" 2>&1`,
|
|
716
|
+
")",
|
|
717
|
+
`start "" "${shim}"`,
|
|
718
|
+
'del "%~f0"',
|
|
719
|
+
""
|
|
720
|
+
].join("\r\n");
|
|
677
721
|
try {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
const timer = setTimeout(() => {
|
|
681
|
-
child.kill();
|
|
682
|
-
reject(new Error("npm timed out"));
|
|
683
|
-
}, 5 * 6e4);
|
|
684
|
-
child.on("error", reject);
|
|
685
|
-
child.on("close", (code) => {
|
|
686
|
-
clearTimeout(timer);
|
|
687
|
-
if (code === 0) resolve2();
|
|
688
|
-
else reject(new Error(`npm exited with code ${code}`));
|
|
689
|
-
});
|
|
690
|
-
});
|
|
722
|
+
node_fs.writeFileSync(script, body);
|
|
723
|
+
node_child_process.spawn(script, { detached: true, stdio: "ignore", windowsHide: true }).unref();
|
|
691
724
|
} catch (err) {
|
|
692
725
|
return { state: "error", message: err instanceof Error ? err.message : String(err) };
|
|
693
726
|
}
|
|
694
727
|
available = null;
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
electron.app.relaunch();
|
|
698
|
-
electron.app.quit();
|
|
699
|
-
}, 1500);
|
|
700
|
-
return { state: "done", message: `Updated to ${target} — restarting…` };
|
|
728
|
+
setTimeout(() => electron.app.quit(), 1500);
|
|
729
|
+
return { state: "done", message: `Updating to ${target} — restarting…` };
|
|
701
730
|
}
|
|
702
731
|
let scanning = false;
|
|
703
732
|
let mainHooks = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runbay",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Not an installer. A launcher. Detect, launch, update and uninstall apps installed from the command line (npm, pnpm, yarn, bun, scoop) — in one modern window.",
|
|
5
5
|
"main": "./out/main/index.js",
|
|
6
6
|
"bin": {
|