@petercjl/omni-desktop-app 0.1.8 → 0.1.10
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/INSTALL.md +9 -0
- package/README.md +4 -4
- package/UPDATE.md +7 -0
- package/app/assets/{CartesianChart-Bwf4u0Tg.js → CartesianChart-CP7p2vlm.js} +2 -2
- package/app/assets/{CollaborationWorkspace-Bd6Sjj31.js → CollaborationWorkspace-Cnp5PNn_.js} +3 -3
- package/app/assets/CompetitorAnalysis-Cujy_a2L.js +1 -0
- package/app/assets/CompetitorAnalysis-h1zdt0F2.css +1 -0
- package/app/assets/EmptyState-CUHuNsaV.js +1 -0
- package/app/assets/ErrorBarContext-BJE5-ljg.js +1 -0
- package/app/assets/{EvidenceSourceGuide-CwfB7Z6T.js → EvidenceSourceGuide-B1AJCZm2.js} +1 -1
- package/app/assets/FavoritePicker-XD1a_uOa.js +1 -0
- package/app/assets/Favorites-B5_fdEvZ.js +1 -0
- package/app/assets/{HelpTip-CX2LFdwD.js → HelpTip-BqRBO41J.js} +1 -1
- package/app/assets/LineChart-Ckvg5wfQ.js +4 -0
- package/app/assets/{Opportunities-a5IpRN6k.js → Opportunities-BvH64-dz.js} +1 -1
- package/app/assets/{ProgressiveRows-ByxDeTyy.js → ProgressiveRows-NojOUgmr.js} +1 -1
- package/app/assets/ShopLayoutPage-CCrRwaAx.js +1 -0
- package/app/assets/TrendChart-BF4JgwxH.js +1 -0
- package/app/assets/arrow-down-B1nil3T4.js +1 -0
- package/app/assets/arrow-left-BhFSpYzK.js +1 -0
- package/app/assets/arrow-up-right-IBQoN72x.js +1 -0
- package/app/assets/{book-open-C0B9Pao9.js → book-open-Cqdn6s-H.js} +1 -1
- package/app/assets/chart-column-DCwNhXki.js +1 -0
- package/app/assets/{chart-no-axes-combined-XDy9u9SV.js → chart-no-axes-combined-DVgKs36j.js} +1 -1
- package/app/assets/check-DBnlZFEo.js +1 -0
- package/app/assets/chevron-down-DO6RUQm8.js +1 -0
- package/app/assets/chevron-right-e65CaeL6.js +1 -0
- package/app/assets/{clock-3-TH35nOP-.js → clock-3-CDHtQwAe.js} +1 -1
- package/app/assets/competitor-analysis-D6eM9ugQ.js +1 -0
- package/app/assets/{components-C2-vHJtu.js → components-B5Xyjfpi.js} +2 -2
- package/app/assets/{download-BlJN0Lg8.js → download-DfM49VvV.js} +1 -1
- package/app/assets/entry-Bq7tA83b.js +1 -0
- package/app/assets/{entry-OcErMaMp.css → entry-CMur_AE7.css} +1 -1
- package/app/assets/entry-DC4oDjzU.js +2 -0
- package/app/assets/{entry-DM3aLe2I.js → entry-DM64sJfS.js} +1 -1
- package/app/assets/entry-DbqMDIJi.js +1 -0
- package/app/assets/{entry-CdLi3Z9F.js → entry-N8bfKXTF.js} +2 -2
- package/app/assets/{entry-CYGrMJuR.js → entry-kAWoaIsV.js} +2 -2
- package/app/assets/favorites.module-CHYv-Z8y.js +1 -0
- package/app/assets/{file-text-Hd45wNTe.js → file-text-DKAT5fzJ.js} +1 -1
- package/app/assets/getRadiusAndStrokeWidthFromDot-bv_ksZ7y.js +1 -0
- package/app/assets/{grid-2x2-C0aJVeyS.js → grid-2x2-DB6zRPIV.js} +1 -1
- package/app/assets/index-BgJNmU0Z.css +1 -0
- package/app/assets/{index-BguiS02-.js → index-DLSVWUSu.js} +2 -2
- package/app/assets/{layers-Dj9z2et6.js → layers-CjsT_HGi.js} +1 -1
- package/app/assets/{layout-dashboard-DS537D8b.js → layout-dashboard-sgUrlApv.js} +1 -1
- package/app/assets/{link-2-CCKUDMV6.js → link-2-VLti-YG9.js} +1 -1
- package/app/assets/{list-LZcXKWKD.js → list-Dfzc0sXQ.js} +1 -1
- package/app/assets/market-SuD7x_Hf.css +1 -0
- package/app/assets/market.module-VpU4XmGg.js +1 -0
- package/app/assets/{module-host-C4vqZw2y.js → module-host-DNtiV4gZ.js} +1 -1
- package/app/assets/{orbit-G4ZspWKB.js → orbit-CrQs6cpl.js} +1 -1
- package/app/assets/play-BxTFlaQX.js +1 -0
- package/app/assets/plus-D78h7lrw.js +1 -0
- package/app/assets/{products-BAKFF--e.js → products-B5vjXM_b.js} +1 -1
- package/app/assets/{project-public-HdtYycKS.js → project-public-CgW1u7BI.js} +1 -1
- package/app/assets/{project-public-BCoD2Anq.js → project-public-DWTt808B.js} +1 -1
- package/app/assets/public-C-PBMVOQ.js +1 -0
- package/app/assets/{refresh-cw-dsQ_f-9j.js → refresh-cw-CxbRf97c.js} +1 -1
- package/app/assets/search-DFdSppzm.js +1 -0
- package/app/assets/{triangle-alert-l-Mfj0iE.js → triangle-alert-C7qiylOf.js} +1 -1
- package/app/assets/{ui-public-BPe2GJZ-.css → ui-public-DHoRDp5_.css} +1 -1
- package/app/assets/{ui-public-DWkIf658.js → ui-public-Dt5dHt-8.js} +1 -1
- package/app/assets/workbench-DIKJZNJQ.js +2 -0
- package/app/assets/{workspace-view-state-BJMX6vWb.js → workspace-view-state-D0ujRczW.js} +1 -1
- package/app/desktop/main.mjs +7719 -0
- package/app/desktop/preload.cjs +30 -0
- package/app/index.html +2 -2
- package/app/package.json +1 -0
- package/app/public/omni-icon.png +0 -0
- package/app/tools/bootstrap.bin +0 -0
- package/app/tools/omni-desktop.mjs +526 -0
- package/package.json +7 -2
- package/release.json +1 -1
- package/release.sig +1 -1
- package/app/assets/EmptyState-CE7obISq.js +0 -1
- package/app/assets/Favorites-4oU1mgEb.js +0 -1
- package/app/assets/LineChart-B6igYupv.js +0 -4
- package/app/assets/ShopLayoutPage-D7KKJVEq.js +0 -1
- package/app/assets/TrendChart-BdRXaz4z.js +0 -1
- package/app/assets/arrow-down-DSjucZgz.js +0 -1
- package/app/assets/arrow-left-DmIga4jN.js +0 -1
- package/app/assets/arrow-up-right-DzAKT3cL.js +0 -1
- package/app/assets/check-BB89tIU6.js +0 -1
- package/app/assets/chevron-down-BiokgLxD.js +0 -1
- package/app/assets/chevron-right-CZlQQ5gV.js +0 -1
- package/app/assets/entry-Bxc-KNuY.js +0 -1
- package/app/assets/entry-ZwyGbRek.js +0 -1
- package/app/assets/entry-ffP7X21A.js +0 -2
- package/app/assets/index-D1qZkLPg.css +0 -1
- package/app/assets/market-DqV9l-vR.css +0 -1
- package/app/assets/market.module-BSrEp5Ak.js +0 -1
- package/app/assets/package-BFlv-jYw.js +0 -1
- package/app/assets/play-DxbesM66.js +0 -1
- package/app/assets/plus-QakkcxdA.js +0 -1
- package/app/assets/public-JUGpS2z7.js +0 -1
- package/app/assets/search-Cisx0wBF.js +0 -1
- package/app/assets/use-favorites-ALxrDxDW.js +0 -1
- package/app/assets/workbench-DZTf1DRZ.js +0 -2
- /package/app/assets/{api-hjUd9Skg.js → api-KZa8CR8X.js} +0 -0
- /package/app/assets/{use-favorites-_eKBQGeF.css → favorites-_eKBQGeF.css} +0 -0
- /package/app/assets/{format-BCxMsVJh.js → format-DL7i7_eV.js} +0 -0
- /package/app/assets/{graphicalItemSelectors-Hc730Dd1.js → graphicalItemSelectors-CJfZ6cht.js} +0 -0
- /package/app/assets/{group-CjIFQYrJ.js → group-Ed305HyG.js} +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- Sandboxed Electron preloads use CommonJS.
|
|
2
|
+
const {contextBridge, ipcRenderer} = require('electron');
|
|
3
|
+
contextBridge.exposeInMainWorld('omni', {
|
|
4
|
+
updateStatus:()=>ipcRenderer.invoke('omni:update-status'),
|
|
5
|
+
updateCheck:()=>ipcRenderer.invoke('omni:update-check'),
|
|
6
|
+
updateDownload:()=>ipcRenderer.invoke('omni:update-download'),
|
|
7
|
+
updateInstall:()=>ipcRenderer.invoke('omni:update-install'),
|
|
8
|
+
updateRepair:()=>ipcRenderer.invoke('omni:update-repair'),
|
|
9
|
+
onUpdate:callback=>{const listener=(_event,value)=>callback(value);ipcRenderer.on('omni:update',listener);return()=>ipcRenderer.removeListener('omni:update',listener);},
|
|
10
|
+
setWindowTheme:theme=>ipcRenderer.invoke('omni:window-theme',theme),
|
|
11
|
+
info: () => ipcRenderer.invoke('omni:info'),
|
|
12
|
+
probe: () => ipcRenderer.invoke('omni:probe'),
|
|
13
|
+
login: (credentials) => ipcRenderer.invoke('omni:login', credentials),
|
|
14
|
+
logout: () => ipcRenderer.invoke('omni:logout'),
|
|
15
|
+
verify: () => ipcRenderer.invoke('omni:verify'),
|
|
16
|
+
request: (request) => ipcRenderer.invoke('omni:request', request),
|
|
17
|
+
setScope: (shopIds) => ipcRenderer.invoke('omni:scope',shopIds),
|
|
18
|
+
copyText:(text)=>ipcRenderer.invoke('omni:copy-text',text),
|
|
19
|
+
projectExecution:input=>ipcRenderer.invoke('omni:project-execution',input),
|
|
20
|
+
onProjectExecution:callback=>{const listener=(_event,value)=>callback(value);ipcRenderer.on('omni:project-execution',listener);return()=>ipcRenderer.removeListener('omni:project-execution',listener);},
|
|
21
|
+
localAgent:input=>ipcRenderer.invoke('omni:local-agent',input),
|
|
22
|
+
projectAgent:input=>ipcRenderer.invoke('omni:project-agent',input),
|
|
23
|
+
agentStatus:()=>ipcRenderer.invoke('omni:agent-status'),
|
|
24
|
+
competitorAnalysis:input=>ipcRenderer.invoke('omni:competitor-analysis',input),
|
|
25
|
+
onSession: (callback) => {
|
|
26
|
+
const listener = (_event, state) => callback(state);
|
|
27
|
+
ipcRenderer.on('omni:session', listener);
|
|
28
|
+
return () => ipcRenderer.removeListener('omni:session', listener);
|
|
29
|
+
},
|
|
30
|
+
});
|
package/app/index.html
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>山海 · OMNI</title> <script type="module" crossorigin src="./assets/index-
|
|
3
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
2
|
+
<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>山海 · OMNI</title> <script type="module" crossorigin src="./assets/index-DLSVWUSu.js"></script>
|
|
3
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BgJNmU0Z.css">
|
|
4
4
|
</head><body><div id="root"></div></body></html>
|
package/app/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// desktop/shell-cli.mjs
|
|
4
|
+
import path3 from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
// desktop/shell-install.mjs
|
|
8
|
+
import fs2 from "node:fs/promises";
|
|
9
|
+
import path2 from "node:path";
|
|
10
|
+
import os from "node:os";
|
|
11
|
+
import { execFile } from "node:child_process";
|
|
12
|
+
import { promisify } from "node:util";
|
|
13
|
+
import { createHash as createHash2, verify as verify2 } from "node:crypto";
|
|
14
|
+
|
|
15
|
+
// desktop/updater.mjs
|
|
16
|
+
import nodeFs from "node:fs/promises";
|
|
17
|
+
import { createRequire } from "node:module";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import { createHash, verify } from "node:crypto";
|
|
20
|
+
import { gunzipSync } from "node:zlib";
|
|
21
|
+
var fs = process.versions.electron ? createRequire(import.meta.url)("original-fs").promises : nodeFs;
|
|
22
|
+
var PACKAGE = "@petercjl/omni-desktop-app";
|
|
23
|
+
var REGISTRY = "https://registry.npmjs.org";
|
|
24
|
+
var LIMIT = 100 * 1024 * 1024;
|
|
25
|
+
var EXPANDED = 256 * 1024 * 1024;
|
|
26
|
+
var INTERVAL = 4 * 36e5;
|
|
27
|
+
var hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
28
|
+
var exists = async (p) => !!await fs.lstat(p).catch(() => null);
|
|
29
|
+
var newer = (a, b) => /^\d+\.\d+\.\d+$/.test(a) && a.split(".").some((x, i, all) => Number(x) > Number(b.split(".")[i]) && all.slice(0, i).every((n, j) => Number(n) === Number(b.split(".")[j])));
|
|
30
|
+
var version = (v) => typeof v === "string" && /^\d+\.\d+\.\d+$/.test(v);
|
|
31
|
+
var safe = (p) => typeof p === "string" && p.length < 200 && /^[a-zA-Z0-9_.\/-]+$/.test(p) && !p.split("/").some((x) => x === ".." || x === "" || x === ".") && !path.isAbsolute(p);
|
|
32
|
+
async function json(p) {
|
|
33
|
+
return JSON.parse(await fs.readFile(p, "utf8"));
|
|
34
|
+
}
|
|
35
|
+
async function write(p, v) {
|
|
36
|
+
for (const name of [p, p + ".tmp"]) {
|
|
37
|
+
const stat = await fs.lstat(name).catch((error) => {
|
|
38
|
+
if (error.code === "ENOENT") return null;
|
|
39
|
+
throw error;
|
|
40
|
+
});
|
|
41
|
+
if (stat && (!stat.isFile() || stat.isSymbolicLink())) throw Error("\u66F4\u65B0\u72B6\u6001\u6587\u4EF6\u7C7B\u578B\u4E0D\u6B63\u786E");
|
|
42
|
+
}
|
|
43
|
+
const tmp = p + ".tmp";
|
|
44
|
+
if (await exists(tmp)) await fs.unlink(tmp);
|
|
45
|
+
await fs.writeFile(tmp, JSON.stringify(v), { flag: "wx", mode: 384 });
|
|
46
|
+
await fs.rename(tmp, p);
|
|
47
|
+
}
|
|
48
|
+
async function plain(dir) {
|
|
49
|
+
const stat = await fs.lstat(dir);
|
|
50
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw Error("\u66F4\u65B0\u76EE\u5F55\u5F52\u5C5E\u68C0\u67E5\u5931\u8D25");
|
|
51
|
+
}
|
|
52
|
+
async function verifyPayload(dir, key, shell, { requireShell = false, electron = process.versions.electron } = {}) {
|
|
53
|
+
await plain(dir);
|
|
54
|
+
const manifest = await json(path.join(dir, "release.json"));
|
|
55
|
+
if (manifest.package !== PACKAGE || !version(manifest.version) || ![1, 2].includes(manifest.contract) || manifest.contract === 2 && !requireShell || !version(manifest.minShell) || newer(manifest.minShell, shell)) throw Error("\u5F53\u524D\u5B89\u88C5\u9700\u8981\u5148\u5347\u7EA7\u66F4\u65B0\u7EC4\u4EF6\uFF0C\u5E94\u7528\u548C\u767B\u5F55\u72B6\u6001\u5DF2\u4FDD\u7559");
|
|
56
|
+
if (!verify(null, Buffer.from(JSON.stringify(manifest)), key, Buffer.from(await fs.readFile(path.join(dir, "release.sig"), "utf8"), "base64"))) throw Error("\u66F4\u65B0\u53D1\u884C\u7B7E\u540D\u65E0\u6548");
|
|
57
|
+
if (requireShell) {
|
|
58
|
+
const value = manifest.contract === 2 ? manifest.application : manifest.shell;
|
|
59
|
+
if (!value || value.contract !== 1 || value.entry !== "app/desktop/main.mjs" || value.preload !== "app/desktop/preload.cjs" || !version(value.version) || value.version !== manifest.version || !Array.isArray(value.electronMajors) || !value.electronMajors.includes(Number(electron?.split(".")[0])) || !manifest.files?.[value.entry] || !manifest.files?.[value.preload]) throw Error("\u66F4\u65B0\u4E0E\u5F53\u524D\u684C\u9762\u8FD0\u884C\u73AF\u5883\u4E0D\u517C\u5BB9");
|
|
60
|
+
}
|
|
61
|
+
const pkg = await json(path.join(dir, "package.json"));
|
|
62
|
+
if (pkg.name !== PACKAGE || pkg.version !== manifest.version) throw Error("\u66F4\u65B0\u5305\u8EAB\u4EFD\u4E0D\u5339\u914D");
|
|
63
|
+
if (!manifest.files || !Object.hasOwn(manifest.files, "app/index.html") || Object.keys(manifest.files).length > 5e3) throw Error("\u66F4\u65B0\u6587\u4EF6\u6E05\u5355\u4E0D\u5B8C\u6574");
|
|
64
|
+
let bytes = 0;
|
|
65
|
+
const walk = async (base, prefix = "") => {
|
|
66
|
+
for (const e of await fs.readdir(base, { withFileTypes: true })) {
|
|
67
|
+
const name = prefix + e.name;
|
|
68
|
+
if (e.isDirectory()) {
|
|
69
|
+
await walk(path.join(base, e.name), name + "/");
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!e.isFile() || !safe(name) || !Object.hasOwn(manifest.files, name)) throw Error("\u66F4\u65B0\u6587\u4EF6\u6E05\u5355\u542B\u672A\u6388\u6743\u5185\u5BB9");
|
|
73
|
+
const raw = await fs.readFile(path.join(base, e.name));
|
|
74
|
+
bytes += raw.length;
|
|
75
|
+
if (bytes > EXPANDED || hash(raw) !== manifest.files[name]) throw Error("\u66F4\u65B0\u6587\u4EF6\u5B8C\u6574\u6027\u6821\u9A8C\u5931\u8D25");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
await plain(path.join(dir, "app"));
|
|
79
|
+
await walk(path.join(dir, "app"), "app/");
|
|
80
|
+
for (const name of Object.keys(manifest.files)) if (!safe(name) || !name.startsWith("app/") || !await exists(path.join(dir, name))) throw Error("\u66F4\u65B0\u6587\u4EF6\u7F3A\u5931");
|
|
81
|
+
return manifest;
|
|
82
|
+
}
|
|
83
|
+
async function unpack(bytes, destination) {
|
|
84
|
+
if (bytes.length > LIMIT) throw Error("\u66F4\u65B0\u538B\u7F29\u5305\u8D85\u8FC7\u5927\u5C0F\u9650\u5236");
|
|
85
|
+
const raw = gunzipSync(bytes, { maxOutputLength: EXPANDED });
|
|
86
|
+
let offset = 0, count = 0;
|
|
87
|
+
const seen = /* @__PURE__ */ new Set();
|
|
88
|
+
await fs.mkdir(destination, { recursive: true, mode: 448 });
|
|
89
|
+
await plain(destination);
|
|
90
|
+
while (offset + 512 <= raw.length) {
|
|
91
|
+
const header = raw.subarray(offset, offset + 512);
|
|
92
|
+
if (header.every((x) => x === 0)) break;
|
|
93
|
+
const string = (a, b) => header.subarray(a, b).toString().split("\0")[0];
|
|
94
|
+
const name = string(345, 500) ? string(345, 500) + "/" + string(0, 100) : string(0, 100);
|
|
95
|
+
const kind = String.fromCharCode(header[156]);
|
|
96
|
+
const size = parseInt(string(124, 136).trim(), 8) || 0;
|
|
97
|
+
const checksum = parseInt(string(148, 156).trim(), 8);
|
|
98
|
+
let sum = 0;
|
|
99
|
+
for (let i = 0; i < 512; i++) sum += i >= 148 && i < 156 ? 32 : header[i];
|
|
100
|
+
if (sum !== checksum || !Number.isSafeInteger(size) || size < 0 || offset + 512 + size > raw.length) throw Error("\u66F4\u65B0\u5F52\u6863\u683C\u5F0F\u65E0\u6548");
|
|
101
|
+
const relative = name.replace(/\/$/, "");
|
|
102
|
+
if (!relative.startsWith("package/") || !safe(relative) || !["0", "\0", "5"].includes(kind) || seen.has(relative) || ++count > 5e3) throw Error("\u66F4\u65B0\u5F52\u6863\u5305\u542B\u4E0D\u5B89\u5168\u8DEF\u5F84\u6216\u6587\u4EF6\u7C7B\u578B");
|
|
103
|
+
seen.add(relative);
|
|
104
|
+
const target = path.join(destination, ...relative.split("/").slice(1));
|
|
105
|
+
if (kind === "5") await fs.mkdir(target, { recursive: true, mode: 448 });
|
|
106
|
+
else {
|
|
107
|
+
await fs.mkdir(path.dirname(target), { recursive: true, mode: 448 });
|
|
108
|
+
await fs.writeFile(target, raw.subarray(offset + 512, offset + 512 + size), { flag: "wx", mode: 384 });
|
|
109
|
+
}
|
|
110
|
+
offset += 512 + Math.ceil(size / 512) * 512;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var DesktopUpdater = class {
|
|
114
|
+
constructor({ userData, base, publicKey, shellVersion = "0.1.0", enabled = true, fetchImpl = globalThis.fetch, authorize = async () => {
|
|
115
|
+
}, onChange = () => {
|
|
116
|
+
}, now = Date.now, requireShell = false, electron = process.versions.electron }) {
|
|
117
|
+
Object.assign(this, { requireShell, electron, base, publicKey, shellVersion, enabled, fetchImpl, authorize, onChange, now });
|
|
118
|
+
this.home = path.join(userData, "updates");
|
|
119
|
+
this.runtime = path.join(userData, "runtime");
|
|
120
|
+
this.active = path.join(this.runtime, "active");
|
|
121
|
+
this.stage = path.join(this.home, "staging");
|
|
122
|
+
this.value = { status: enabled ? "idle" : "development", version: shellVersion, shellVersion, automatic: true, progress: 0 };
|
|
123
|
+
this.running = null;
|
|
124
|
+
this.failures = 0;
|
|
125
|
+
this.nextCheck = 0;
|
|
126
|
+
}
|
|
127
|
+
status() {
|
|
128
|
+
return { ...this.value };
|
|
129
|
+
}
|
|
130
|
+
emit(value) {
|
|
131
|
+
Object.assign(this.value, value);
|
|
132
|
+
this.onChange(this.status());
|
|
133
|
+
return this.status();
|
|
134
|
+
}
|
|
135
|
+
async owned() {
|
|
136
|
+
for (const dir of [this.home, this.runtime]) {
|
|
137
|
+
if (await exists(dir)) {
|
|
138
|
+
await plain(dir);
|
|
139
|
+
const marker = path.join(dir, ".omni-owned"), stat = await fs.lstat(marker).catch(() => null);
|
|
140
|
+
if (!stat?.isFile() || stat.isSymbolicLink() || await fs.readFile(marker, "utf8") !== "omni-desktop-v1") throw Error("\u66F4\u65B0\u76EE\u5F55\u5DF2\u6709\u672A\u6258\u7BA1\u6587\u4EF6\uFF0C\u4FDD\u7559\u539F\u6587\u4EF6");
|
|
141
|
+
} else {
|
|
142
|
+
await fs.mkdir(dir, { recursive: true, mode: 448 });
|
|
143
|
+
await fs.writeFile(path.join(dir, ".omni-owned"), "omni-desktop-v1", { flag: "wx", mode: 384 });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
async remove(p) {
|
|
148
|
+
if (![this.active, this.stage, path.join(this.home, "pending.json"), path.join(this.home, "booting.json")].includes(p)) throw Error("\u6E05\u7406\u8303\u56F4\u65E0\u6548");
|
|
149
|
+
if (await exists(p)) {
|
|
150
|
+
const s = await fs.lstat(p);
|
|
151
|
+
if (s.isSymbolicLink()) throw Error("\u6E05\u7406\u76EE\u6807\u542B\u94FE\u63A5");
|
|
152
|
+
await fs.rm(p, { recursive: true, force: true });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async boot() {
|
|
156
|
+
if (!this.enabled) return { dir: this.base, version: this.shellVersion };
|
|
157
|
+
await this.owned();
|
|
158
|
+
if (await exists(path.join(this.home, "booting.json"))) {
|
|
159
|
+
const failed = await json(path.join(this.home, "booting.json")).catch(() => ({}));
|
|
160
|
+
if (version(failed.version)) await write(path.join(this.home, "failed.json"), { version: failed.version });
|
|
161
|
+
await this.remove(this.active);
|
|
162
|
+
await this.remove(path.join(this.home, "booting.json"));
|
|
163
|
+
await this.remove(path.join(this.home, "pending.json"));
|
|
164
|
+
await this.remove(this.stage);
|
|
165
|
+
this.emit({ status: "recovered", error: "\u4E0A\u6B21\u66F4\u65B0\u672A\u6B63\u5E38\u542F\u52A8\uFF0C\u5DF2\u6062\u590D\u5185\u7F6E\u7248\u672C" });
|
|
166
|
+
}
|
|
167
|
+
if (await exists(path.join(this.home, "pending.json"))) {
|
|
168
|
+
try {
|
|
169
|
+
const pending = await json(path.join(this.home, "pending.json")), failed = await json(path.join(this.home, "failed.json")).catch(() => null);
|
|
170
|
+
if (failed?.version === pending.version) throw Error("\u5DF2\u9694\u79BB\u5931\u8D25\u66F4\u65B0");
|
|
171
|
+
const m = await verifyPayload(path.join(this.stage, "candidate"), this.publicKey, this.shellVersion, { requireShell: this.requireShell, electron: this.electron });
|
|
172
|
+
await write(path.join(this.home, "booting.json"), { version: m.version });
|
|
173
|
+
await this.remove(this.active);
|
|
174
|
+
await fs.rename(path.join(this.stage, "candidate"), this.active);
|
|
175
|
+
await this.remove(path.join(this.home, "pending.json"));
|
|
176
|
+
} catch {
|
|
177
|
+
await this.remove(this.active);
|
|
178
|
+
await this.remove(path.join(this.home, "pending.json"));
|
|
179
|
+
await this.remove(path.join(this.home, "booting.json"));
|
|
180
|
+
this.emit({ status: "recovered", error: "\u66F4\u65B0\u6FC0\u6D3B\u5931\u8D25\uFF0C\u5DF2\u6062\u590D\u5185\u7F6E\u7248\u672C" });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
await this.remove(this.stage);
|
|
184
|
+
if (await exists(this.active)) {
|
|
185
|
+
try {
|
|
186
|
+
const manifest = await verifyPayload(this.active, this.publicKey, this.shellVersion, { requireShell: this.requireShell, electron: this.electron });
|
|
187
|
+
if (newer(this.shellVersion, manifest.version)) {
|
|
188
|
+
await this.remove(this.active);
|
|
189
|
+
await this.remove(path.join(this.home, "booting.json"));
|
|
190
|
+
this.emit({ version: this.shellVersion });
|
|
191
|
+
return { dir: this.base, version: this.shellVersion };
|
|
192
|
+
}
|
|
193
|
+
this.emit({ version: manifest.version });
|
|
194
|
+
return { dir: path.join(this.active, "app"), version: manifest.version };
|
|
195
|
+
} catch {
|
|
196
|
+
await this.remove(this.active);
|
|
197
|
+
await this.remove(path.join(this.home, "booting.json"));
|
|
198
|
+
this.emit({ status: "recovered", error: "\u66F4\u65B0\u6A21\u5757\u6821\u9A8C\u5931\u8D25\uFF0C\u5DF2\u6062\u590D\u5185\u7F6E\u7248\u672C" });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return { dir: this.base, version: this.shellVersion };
|
|
202
|
+
}
|
|
203
|
+
async stagePayload(source) {
|
|
204
|
+
await this.owned();
|
|
205
|
+
if (this.running) throw Error("\u8BF7\u7B49\u5F85\u66F4\u65B0\u5B8C\u6210");
|
|
206
|
+
const m = await verifyPayload(source, this.publicKey, this.shellVersion, { requireShell: this.requireShell, electron: this.electron });
|
|
207
|
+
await this.remove(this.stage);
|
|
208
|
+
await fs.mkdir(this.stage, { mode: 448 });
|
|
209
|
+
try {
|
|
210
|
+
await fs.cp(source, path.join(this.stage, "candidate"), { recursive: true, dereference: false });
|
|
211
|
+
await verifyPayload(path.join(this.stage, "candidate"), this.publicKey, this.shellVersion, { requireShell: this.requireShell, electron: this.electron });
|
|
212
|
+
await write(path.join(this.home, "pending.json"), { version: m.version });
|
|
213
|
+
return this.emit({ status: "ready", latest: m.version, progress: 100 });
|
|
214
|
+
} catch (error) {
|
|
215
|
+
await this.remove(this.stage);
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async healthy() {
|
|
220
|
+
if (this.enabled) await this.remove(path.join(this.home, "booting.json"));
|
|
221
|
+
}
|
|
222
|
+
async request(url, max = LIMIT, progress = false) {
|
|
223
|
+
const u = new URL(url);
|
|
224
|
+
if (u.origin !== REGISTRY || u.username || u.password) throw Error("\u66F4\u65B0\u4E0B\u8F7D\u6E90\u4E0D\u53D7\u652F\u6301");
|
|
225
|
+
const response = await this.fetchImpl(url, { redirect: "error", signal: AbortSignal.timeout(progress ? 18e4 : 15e3) });
|
|
226
|
+
if (!response.ok) throw Error("\u66F4\u65B0\u670D\u52A1\u6682\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
|
|
227
|
+
const chunks = [];
|
|
228
|
+
let size = 0;
|
|
229
|
+
const total = Number(response.headers.get("content-length")) || 0;
|
|
230
|
+
if (total > max) throw Error("\u66F4\u65B0\u5185\u5BB9\u8D85\u8FC7\u5927\u5C0F\u9650\u5236");
|
|
231
|
+
for await (const part of response.body) {
|
|
232
|
+
size += part.length;
|
|
233
|
+
if (size > max) throw Error("\u66F4\u65B0\u5185\u5BB9\u8D85\u8FC7\u5927\u5C0F\u9650\u5236");
|
|
234
|
+
chunks.push(Buffer.from(part));
|
|
235
|
+
if (progress) this.emit({ progress: total ? Math.min(99, Math.round(size / total * 100)) : 0 });
|
|
236
|
+
}
|
|
237
|
+
return Buffer.concat(chunks);
|
|
238
|
+
}
|
|
239
|
+
async check({ download = false } = {}) {
|
|
240
|
+
if (!this.enabled) return this.status();
|
|
241
|
+
if (this.running) return this.running;
|
|
242
|
+
this.running = this.perform(download).catch((error) => {
|
|
243
|
+
this.failures++;
|
|
244
|
+
this.nextCheck = this.now() + [9e5, 36e5, INTERVAL][Math.min(2, this.failures - 1)];
|
|
245
|
+
return this.emit({ status: "error", error: error.message });
|
|
246
|
+
}).finally(() => {
|
|
247
|
+
this.running = null;
|
|
248
|
+
});
|
|
249
|
+
return this.running;
|
|
250
|
+
}
|
|
251
|
+
async perform(download) {
|
|
252
|
+
await this.authorize();
|
|
253
|
+
await this.owned();
|
|
254
|
+
if (await exists(path.join(this.home, "pending.json"))) return this.emit({ status: "ready" });
|
|
255
|
+
this.emit({ status: "checking", error: void 0 });
|
|
256
|
+
const metadata = JSON.parse((await this.request(REGISTRY + "/" + encodeURIComponent(PACKAGE) + "/latest", 2 * 1024 * 1024)).toString());
|
|
257
|
+
if (metadata.name !== PACKAGE || !version(metadata.version)) throw Error("\u66F4\u65B0\u7248\u672C\u4FE1\u606F\u4E0D\u5408\u6CD5");
|
|
258
|
+
this.nextCheck = this.now() + INTERVAL;
|
|
259
|
+
this.failures = 0;
|
|
260
|
+
this.emit({ lastChecked: new Date(this.now()).toISOString(), latest: metadata.version });
|
|
261
|
+
const failed = await json(path.join(this.home, "failed.json")).catch(() => null);
|
|
262
|
+
if (failed?.version === metadata.version) return this.emit({ status: "recovered", error: "\u8BE5\u7248\u672C\u4E0A\u6B21\u542F\u52A8\u5931\u8D25\uFF0C\u5DF2\u4FDD\u7559\u5185\u7F6E\u7248\u672C\u5E76\u7B49\u5F85\u540E\u7EED\u66F4\u65B0" });
|
|
263
|
+
if (!newer(metadata.version, this.value.version)) return this.emit({ status: "current" });
|
|
264
|
+
if (!download) return this.emit({ status: "available" });
|
|
265
|
+
await this.authorize();
|
|
266
|
+
const space = await fs.statfs(this.home);
|
|
267
|
+
if (Number(space.bavail) * Number(space.bsize) < EXPANDED + LIMIT + 64 * 1024 * 1024) throw Error("\u78C1\u76D8\u7A7A\u95F4\u4E0D\u8DB3\uFF0C\u8BF7\u91CA\u653E\u81F3\u5C11 420 MB");
|
|
268
|
+
this.emit({ status: "downloading", progress: 0 });
|
|
269
|
+
await this.remove(this.stage);
|
|
270
|
+
await fs.mkdir(this.stage, { mode: 448 });
|
|
271
|
+
try {
|
|
272
|
+
const bytes = await this.request(metadata.dist?.tarball, LIMIT, true);
|
|
273
|
+
const integrity = "sha512-" + createHash("sha512").update(bytes).digest("base64");
|
|
274
|
+
if (integrity !== metadata.dist?.integrity) throw Error("\u4E0B\u8F7D\u5305\u5B8C\u6574\u6027\u6821\u9A8C\u5931\u8D25");
|
|
275
|
+
const candidate = path.join(this.stage, "candidate");
|
|
276
|
+
await unpack(bytes, candidate);
|
|
277
|
+
const m = await verifyPayload(candidate, this.publicKey, this.shellVersion, { requireShell: this.requireShell, electron: this.electron });
|
|
278
|
+
if (m.version !== metadata.version) throw Error("\u4E0B\u8F7D\u5305\u7248\u672C\u4E0D\u4E00\u81F4");
|
|
279
|
+
await this.authorize();
|
|
280
|
+
await write(path.join(this.home, "pending.json"), { version: m.version });
|
|
281
|
+
return this.emit({ status: "ready", progress: 100, latest: m.version });
|
|
282
|
+
} catch (error) {
|
|
283
|
+
await this.remove(this.stage);
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
async automatic() {
|
|
288
|
+
if (this.enabled && this.now() >= this.nextCheck) return this.check({ download: true });
|
|
289
|
+
return this.status();
|
|
290
|
+
}
|
|
291
|
+
async repair() {
|
|
292
|
+
if (this.running) throw Error("\u8BF7\u7B49\u5F85\u5F53\u524D\u66F4\u65B0\u5B8C\u6210");
|
|
293
|
+
await this.owned();
|
|
294
|
+
await this.remove(path.join(this.home, "pending.json"));
|
|
295
|
+
await this.remove(this.stage);
|
|
296
|
+
await this.remove(this.active);
|
|
297
|
+
return this.emit({ status: "recovered", version: this.shellVersion, error: "\u5DF2\u6E05\u7406\u66F4\u65B0\u6A21\u5757\uFF0C\u91CD\u542F\u540E\u4F7F\u7528\u5185\u7F6E\u7248\u672C" });
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// desktop/release-config.mjs
|
|
302
|
+
var releaseKey = "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA2BJOTyMdDPImrQnmxx0hgXqKdd/ocoU4MYW9iCPYEMM=\n-----END PUBLIC KEY-----\n";
|
|
303
|
+
|
|
304
|
+
// desktop/bootstrap-config.mjs
|
|
305
|
+
var baselines = Object.freeze([
|
|
306
|
+
{ platform: "darwin", version: "0.1.7", sha256: "eacbd3b36d51198154bc746e1921639b2ea83de879925158d0207721517f114f" },
|
|
307
|
+
{ platform: "win32", version: "0.1.0", sha256: "4955f9b4e7fc8ca3403adccd6a89707bdfd35725768cbd312f020097e24f9658" }
|
|
308
|
+
]);
|
|
309
|
+
|
|
310
|
+
// desktop/shell-install.mjs
|
|
311
|
+
var run = promisify(execFile);
|
|
312
|
+
var digest = (value) => createHash2("sha256").update(value).digest("hex");
|
|
313
|
+
var exists2 = async (file) => !!await fs2.lstat(file).catch((error) => {
|
|
314
|
+
if (error.code === "ENOENT") return null;
|
|
315
|
+
throw error;
|
|
316
|
+
});
|
|
317
|
+
async function plain2(file, directory = false) {
|
|
318
|
+
const value = await fs2.lstat(file);
|
|
319
|
+
if (value.isSymbolicLink() || !(directory ? value.isDirectory() : value.isFile())) throw Error("\u5B89\u88C5\u76EE\u6807\u542B\u94FE\u63A5\u6216\u7C7B\u578B\u4E0D\u6B63\u786E");
|
|
320
|
+
}
|
|
321
|
+
function installPaths(appPath, platform = process.platform) {
|
|
322
|
+
const app = path2.resolve(appPath);
|
|
323
|
+
if (!["darwin", "win32"].includes(platform)) throw Error("\u5F53\u524D\u5E73\u53F0\u5C1A\u672A\u652F\u6301\u5916\u58F3\u5F15\u5BFC");
|
|
324
|
+
const resources = platform === "darwin" ? path2.join(app, "Contents/Resources") : path2.join(app, "resources");
|
|
325
|
+
return { app, resources, current: path2.join(resources, "app.asar"), builtin: path2.join(resources, "omni-builtin.asar"), receipt: path2.join(resources, "omni-bootstrap.json"), candidate: path2.join(resources, "omni-bootstrap.next.asar") };
|
|
326
|
+
}
|
|
327
|
+
function defaultApp() {
|
|
328
|
+
return process.platform === "darwin" ? "/Applications/\u5C71\u6D77 \xB7 OMNI.app" : path2.join(process.env.LOCALAPPDATA || os.homedir(), "Programs/omni-desktop-shell");
|
|
329
|
+
}
|
|
330
|
+
async function stopped(app, platform) {
|
|
331
|
+
if (platform === "darwin") {
|
|
332
|
+
const { stdout } = await run("ps", ["-axo", "comm="]);
|
|
333
|
+
if (stdout.split("\n").some((line) => line.trim().startsWith(path2.join(app, "Contents/MacOS") + "/"))) throw Error("\u8BF7\u5148\u4FDD\u5B58\u5DE5\u4F5C\u5E76\u9000\u51FA\u5C71\u6D77\uFF0C\u518D\u542F\u7528\u5916\u58F3\u66F4\u65B0");
|
|
334
|
+
} else {
|
|
335
|
+
const encoded = Buffer.from(`$p=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${Buffer.from(app).toString("base64")}')); $n=@(Get-CimInstance Win32_Process | Where-Object {$_.ExecutablePath -and $_.ExecutablePath.StartsWith($p + [IO.Path]::DirectorySeparatorChar)}).Count; Write-Output $n`, "utf16le").toString("base64");
|
|
336
|
+
const { stdout } = await run("powershell.exe", ["-NoProfile", "-EncodedCommand", encoded]);
|
|
337
|
+
if (Number(stdout.trim()) > 0) throw Error("\u8BF7\u5148\u4FDD\u5B58\u5DE5\u4F5C\u5E76\u9000\u51FA\u5C71\u6D77\uFF0C\u518D\u542F\u7528\u5916\u58F3\u66F4\u65B0");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async function signMac(app, resources, archive) {
|
|
341
|
+
const header = await fs2.open(archive, "r");
|
|
342
|
+
let raw;
|
|
343
|
+
try {
|
|
344
|
+
const size = Buffer.alloc(8);
|
|
345
|
+
await header.read(size, 0, 8, 0);
|
|
346
|
+
const length = size.readUInt32LE(4);
|
|
347
|
+
if (length > 4 * 1024 * 1024) throw Error("ASAR \u6587\u4EF6\u5934\u5F02\u5E38");
|
|
348
|
+
const block = Buffer.alloc(length);
|
|
349
|
+
await header.read(block, 0, length, 8);
|
|
350
|
+
const count = block.readUInt32LE(4);
|
|
351
|
+
raw = block.subarray(8, 8 + count);
|
|
352
|
+
} finally {
|
|
353
|
+
await header.close();
|
|
354
|
+
}
|
|
355
|
+
const plist = path2.join(app, "Contents/Info.plist");
|
|
356
|
+
await run("/usr/libexec/PlistBuddy", ["-c", `Set :ElectronAsarIntegrity:Resources/app.asar:hash ${digest(raw)}`, plist]);
|
|
357
|
+
await run("/usr/bin/codesign", ["--force", "--deep", "--sign", "-", app], { maxBuffer: 1024 * 1024 });
|
|
358
|
+
await run("/usr/bin/codesign", ["--verify", "--deep", "--strict", app]);
|
|
359
|
+
}
|
|
360
|
+
async function shellStatus({ appPath = defaultApp(), platform = process.platform, key = releaseKey, allowedBaselines = baselines } = {}) {
|
|
361
|
+
const p = installPaths(appPath, platform);
|
|
362
|
+
await plain2(p.app, true);
|
|
363
|
+
await plain2(p.resources, true);
|
|
364
|
+
await plain2(p.current);
|
|
365
|
+
const currentHash = digest(await fs2.readFile(p.current));
|
|
366
|
+
if (await exists2(p.receipt)) {
|
|
367
|
+
await plain2(p.receipt);
|
|
368
|
+
await plain2(p.builtin);
|
|
369
|
+
const receipt = JSON.parse(await fs2.readFile(p.receipt, "utf8"));
|
|
370
|
+
if (receipt.owner !== "omni-shell-bootstrap" || receipt.contract !== 1 || !verify2(null, Buffer.from(JSON.stringify(receipt.manifest)), key, Buffer.from(receipt.signature, "base64")) || receipt.manifest.files?.["app/tools/bootstrap.bin"] !== currentHash) throw Error("\u5916\u58F3\u5F15\u5BFC\u8EAB\u4EFD\u6216\u5B8C\u6574\u6027\u68C0\u67E5\u5931\u8D25");
|
|
371
|
+
const builtinHash = digest(await fs2.readFile(p.builtin)), baseline2 = allowedBaselines.find((x) => x.platform === platform && x.sha256 === builtinHash);
|
|
372
|
+
if (!baseline2) throw Error("\u5185\u7F6E\u6062\u590D\u7A0B\u5E8F\u6821\u9A8C\u5931\u8D25");
|
|
373
|
+
return { enabled: true, contract: 1, baseline: baseline2.version, app: p.app };
|
|
374
|
+
}
|
|
375
|
+
const baseline = allowedBaselines.find((x) => x.platform === platform && x.sha256 === currentHash);
|
|
376
|
+
if (!baseline) throw Error("\u6B64\u5B89\u88C5\u7248\u672C\u5C1A\u65E0\u5DF2\u9A8C\u8BC1\u7684\u5F15\u5BFC\u5408\u540C\uFF0C\u4FDD\u7559\u539F\u7A0B\u5E8F");
|
|
377
|
+
return { enabled: false, baseline: baseline.version, app: p.app };
|
|
378
|
+
}
|
|
379
|
+
async function performEnable({ appPath = defaultApp(), payload, apply = false, platform = process.platform, key = releaseKey, allowedBaselines = baselines, userData, assertStopped = stopped, signApplication = signMac } = {}) {
|
|
380
|
+
const p = installPaths(appPath, platform);
|
|
381
|
+
const interrupted = await exists2(p.builtin) && !await exists2(p.receipt);
|
|
382
|
+
let state;
|
|
383
|
+
if (interrupted) {
|
|
384
|
+
await plain2(p.builtin);
|
|
385
|
+
const hash2 = digest(await fs2.readFile(p.builtin)), baseline = allowedBaselines.find((x) => x.platform === platform && x.sha256 === hash2);
|
|
386
|
+
if (!baseline) throw Error("\u4E2D\u65AD\u64CD\u4F5C\u7684\u6062\u590D\u7A0B\u5E8F\u8EAB\u4EFD\u4E0D\u5339\u914D");
|
|
387
|
+
state = { enabled: false, baseline: baseline.version, app: p.app };
|
|
388
|
+
} else state = await shellStatus({ appPath, platform, key, allowedBaselines });
|
|
389
|
+
const manifest = await verifyPayload(payload, key, state.baseline, { requireShell: true, electron: "45.3.2" });
|
|
390
|
+
if (!manifest.files["app/tools/bootstrap.bin"]) throw Error("\u66F4\u65B0\u5305\u7F3A\u5C11\u7B7E\u540D\u5F15\u5BFC\u7A0B\u5E8F");
|
|
391
|
+
if (state.enabled) return { ...state, changed: false };
|
|
392
|
+
if (!apply) return { ...state, ready: true, version: manifest.version, requiresClosedApp: true };
|
|
393
|
+
await assertStopped(p.app, platform);
|
|
394
|
+
if (!interrupted) {
|
|
395
|
+
for (const target of [p.builtin, p.receipt, p.candidate]) if (await exists2(target)) throw Error("\u5B58\u5728\u672A\u5B8C\u6210\u7684\u5F15\u5BFC\u6750\u6599\uFF0C\u8BF7\u5148\u68C0\u67E5\u5E76\u6062\u590D");
|
|
396
|
+
}
|
|
397
|
+
const directory = userData || (platform === "darwin" ? path2.join(os.homedir(), "Library/Application Support/Shanhai OMNI") : path2.join(process.env.APPDATA || os.homedir(), "Shanhai OMNI"));
|
|
398
|
+
const updater = new DesktopUpdater({ userData: directory, base: "unused", publicKey: key, shellVersion: state.baseline, requireShell: true, electron: "45.3.2" });
|
|
399
|
+
await updater.stagePayload(payload);
|
|
400
|
+
const bytes = await fs2.readFile(path2.join(payload, "app/tools/bootstrap.bin"));
|
|
401
|
+
if (digest(bytes) !== manifest.files["app/tools/bootstrap.bin"]) throw Error("\u5F15\u5BFC\u6587\u4EF6\u5DF2\u53D8\u5316");
|
|
402
|
+
const info = path2.join(p.app, "Contents/Info.plist"), savedInfo = path2.join(p.resources, "omni-builtin-info.plist");
|
|
403
|
+
if (platform === "darwin" && !interrupted && await exists2(savedInfo)) throw Error("\u6062\u590D\u5165\u53E3\u5DF2\u5B58\u5728\uFF0C\u4FDD\u7559\u539F\u6587\u4EF6");
|
|
404
|
+
if (platform === "darwin" && !interrupted) await fs2.copyFile(info, savedInfo, 1);
|
|
405
|
+
if (interrupted) {
|
|
406
|
+
for (const file of [p.current, p.candidate]) if (await exists2(file)) {
|
|
407
|
+
await plain2(file);
|
|
408
|
+
if (digest(await fs2.readFile(file)) !== digest(bytes)) throw Error("\u4E2D\u65AD\u64CD\u4F5C\u5305\u542B\u672A\u77E5\u7A0B\u5E8F\uFF0C\u4FDD\u7559\u73B0\u573A");
|
|
409
|
+
}
|
|
410
|
+
if (await exists2(p.candidate)) await fs2.unlink(p.candidate);
|
|
411
|
+
}
|
|
412
|
+
await fs2.writeFile(p.candidate, bytes, { flag: "wx", mode: 420 });
|
|
413
|
+
let renamed = interrupted;
|
|
414
|
+
try {
|
|
415
|
+
if (!interrupted) {
|
|
416
|
+
await fs2.rename(p.current, p.builtin);
|
|
417
|
+
renamed = true;
|
|
418
|
+
} else if (await exists2(p.current)) await fs2.unlink(p.current);
|
|
419
|
+
await fs2.rename(p.candidate, p.current);
|
|
420
|
+
const signature = await fs2.readFile(path2.join(payload, "release.sig"), "utf8");
|
|
421
|
+
await fs2.writeFile(p.receipt, JSON.stringify({ owner: "omni-shell-bootstrap", contract: 1, manifest, signature }), { flag: "wx", mode: 420 });
|
|
422
|
+
if (platform === "darwin") await signApplication(p.app, p.resources, p.current);
|
|
423
|
+
const verified = await shellStatus({ appPath, platform, key, allowedBaselines });
|
|
424
|
+
return { ...verified, changed: true, version: manifest.version };
|
|
425
|
+
} catch (error) {
|
|
426
|
+
if (renamed) {
|
|
427
|
+
if (await exists2(p.current)) await fs2.unlink(p.current);
|
|
428
|
+
await fs2.rename(p.builtin, p.current);
|
|
429
|
+
}
|
|
430
|
+
if (await exists2(p.receipt)) await fs2.unlink(p.receipt);
|
|
431
|
+
if (platform === "darwin" && await exists2(savedInfo)) {
|
|
432
|
+
await fs2.copyFile(savedInfo, info);
|
|
433
|
+
await fs2.unlink(savedInfo);
|
|
434
|
+
await signApplication(p.app, p.resources, p.current);
|
|
435
|
+
}
|
|
436
|
+
await updater.remove(path2.join(updater.home, "pending.json"));
|
|
437
|
+
await updater.remove(updater.stage);
|
|
438
|
+
throw error;
|
|
439
|
+
} finally {
|
|
440
|
+
if (await exists2(p.candidate)) await fs2.unlink(p.candidate);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
async function enableShellUpdates(options = {}) {
|
|
444
|
+
if (!options.apply) return performEnable(options);
|
|
445
|
+
const p = installPaths(options.appPath || defaultApp(), options.platform);
|
|
446
|
+
await plain2(p.resources, true);
|
|
447
|
+
const lock = path2.join(os.tmpdir(), "omni-bootstrap-" + digest(p.app) + ".lock");
|
|
448
|
+
let handle;
|
|
449
|
+
try {
|
|
450
|
+
handle = await fs2.open(lock, "wx", 384);
|
|
451
|
+
} catch (error) {
|
|
452
|
+
if (error.code !== "EEXIST") throw error;
|
|
453
|
+
await plain2(lock);
|
|
454
|
+
const prior = JSON.parse(await fs2.readFile(lock, "utf8"));
|
|
455
|
+
if (prior.owner !== "omni-shell-install" || !Number.isSafeInteger(prior.pid) || prior.pid < 1) throw Error("\u4FDD\u7559\u672A\u77E5\u5B89\u88C5\u9501");
|
|
456
|
+
try {
|
|
457
|
+
process.kill(prior.pid, 0);
|
|
458
|
+
throw Error("\u53E6\u4E00\u4E2A\u5916\u58F3\u5F15\u5BFC\u4EFB\u52A1\u6B63\u5728\u8FD0\u884C");
|
|
459
|
+
} catch (error2) {
|
|
460
|
+
if (error2.code !== "ESRCH") throw error2;
|
|
461
|
+
}
|
|
462
|
+
await fs2.unlink(lock);
|
|
463
|
+
handle = await fs2.open(lock, "wx", 384);
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
await handle.writeFile(JSON.stringify({ owner: "omni-shell-install", pid: process.pid }));
|
|
467
|
+
return await performEnable(options);
|
|
468
|
+
} finally {
|
|
469
|
+
await handle.close();
|
|
470
|
+
await fs2.unlink(lock);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
async function restoreBuiltinShell({ appPath = defaultApp(), platform = process.platform, key = releaseKey, allowedBaselines = baselines, assertStopped = stopped, signApplication = signMac } = {}) {
|
|
474
|
+
const p = installPaths(appPath, platform), state = await shellStatus({ appPath, platform, key, allowedBaselines });
|
|
475
|
+
if (!state.enabled) return { ...state, changed: false };
|
|
476
|
+
await assertStopped(p.app, platform);
|
|
477
|
+
if (await exists2(p.candidate)) throw Error("\u6062\u590D\u6682\u5B58\u6587\u4EF6\u5DF2\u5B58\u5728\uFF0C\u4FDD\u7559\u73B0\u573A");
|
|
478
|
+
const info = path2.join(p.app, "Contents/Info.plist"), savedInfo = path2.join(p.resources, "omni-builtin-info.plist");
|
|
479
|
+
if (platform === "darwin") await plain2(savedInfo);
|
|
480
|
+
const rollback = { entry: await fs2.readFile(p.current), receipt: await fs2.readFile(p.receipt), info: platform === "darwin" ? await fs2.readFile(savedInfo) : null };
|
|
481
|
+
await fs2.rename(p.current, p.candidate);
|
|
482
|
+
let restored = false;
|
|
483
|
+
try {
|
|
484
|
+
await fs2.rename(p.builtin, p.current);
|
|
485
|
+
restored = true;
|
|
486
|
+
if (platform === "darwin") await fs2.copyFile(savedInfo, info);
|
|
487
|
+
const hash2 = digest(await fs2.readFile(p.current));
|
|
488
|
+
if (!allowedBaselines.some((x) => x.platform === platform && x.sha256 === hash2)) throw Error("\u6062\u590D\u540E\u7A0B\u5E8F\u6821\u9A8C\u5931\u8D25");
|
|
489
|
+
await fs2.unlink(p.receipt);
|
|
490
|
+
await fs2.unlink(p.candidate);
|
|
491
|
+
if (platform === "darwin") await fs2.unlink(savedInfo);
|
|
492
|
+
if (platform === "darwin") await signApplication(p.app, p.resources, p.current);
|
|
493
|
+
return { enabled: false, changed: true, baseline: state.baseline, app: p.app };
|
|
494
|
+
} catch (error) {
|
|
495
|
+
if (restored) await fs2.rename(p.current, p.builtin);
|
|
496
|
+
if (await exists2(p.candidate)) await fs2.rename(p.candidate, p.current);
|
|
497
|
+
else await fs2.writeFile(p.current, rollback.entry, { flag: "wx", mode: 420 });
|
|
498
|
+
if (!await exists2(p.receipt)) await fs2.writeFile(p.receipt, rollback.receipt, { flag: "wx", mode: 420 });
|
|
499
|
+
if (platform === "darwin") {
|
|
500
|
+
if (!await exists2(savedInfo)) await fs2.writeFile(savedInfo, rollback.info, { flag: "wx", mode: 420 });
|
|
501
|
+
await signApplication(p.app, p.resources, p.current);
|
|
502
|
+
}
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// desktop/shell-cli.mjs
|
|
508
|
+
var args = process.argv.slice(2);
|
|
509
|
+
var command = args.shift();
|
|
510
|
+
var flags = /* @__PURE__ */ new Map();
|
|
511
|
+
for (let i = 0; i < args.length; i++) {
|
|
512
|
+
const arg = args[i];
|
|
513
|
+
if (arg === "--yes" || arg === "--json") flags.set(arg, true);
|
|
514
|
+
else if (["--app", "--payload"].includes(arg) && args[i + 1]) flags.set(arg, args[++i]);
|
|
515
|
+
else throw Error("\u4E0D\u652F\u6301\u7684\u53C2\u6570\uFF1A" + arg);
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
if (!["status", "enable-shell-updates", "restore-builtin"].includes(command)) throw Error("\u7528\u6CD5\uFF1Aomni-desktop status | enable-shell-updates [--app \u8DEF\u5F84] [--yes] [--json]");
|
|
519
|
+
const appPath = flags.get("--app") || defaultApp();
|
|
520
|
+
if (command === "restore-builtin" && !flags.get("--yes")) throw Error("\u6062\u590D\u5185\u7F6E\u7A0B\u5E8F\u9700\u8981 --yes");
|
|
521
|
+
const result = command === "restore-builtin" ? await restoreBuiltinShell({ appPath }) : command === "status" ? await shellStatus({ appPath }) : await enableShellUpdates({ appPath, payload: flags.get("--payload") || path3.resolve(path3.dirname(fileURLToPath(import.meta.url)), "../.."), apply: flags.get("--yes") === true });
|
|
522
|
+
console.log(JSON.stringify({ ok: true, ...result }));
|
|
523
|
+
} catch (error) {
|
|
524
|
+
console.error(JSON.stringify({ ok: false, code: "SHELL_BOOTSTRAP_FAILED", error: error.message }));
|
|
525
|
+
process.exitCode = 1;
|
|
526
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petercjl/omni-desktop-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Signed Shanhai OMNI desktop application module; installed by the desktop updater",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"files": [
|
|
7
7
|
"app/",
|
|
8
8
|
"release.json",
|
|
9
9
|
"release.sig",
|
|
10
|
-
"README.md"
|
|
10
|
+
"README.md",
|
|
11
|
+
"INSTALL.md",
|
|
12
|
+
"UPDATE.md"
|
|
11
13
|
],
|
|
12
14
|
"publishConfig": {
|
|
13
15
|
"access": "public"
|
|
@@ -17,5 +19,8 @@
|
|
|
17
19
|
"prepack": "node ../../scripts/verify-desktop-payload.mjs",
|
|
18
20
|
"version:set": "node ../../scripts/desktop-release.mjs version",
|
|
19
21
|
"check": "npm --prefix ../.. run desktop:typecheck"
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"omni-desktop": "app/tools/omni-desktop.mjs"
|
|
20
25
|
}
|
|
21
26
|
}
|