vanspod 0.4.9 → 0.4.11

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/README.md CHANGED
@@ -38,20 +38,20 @@ npm run dist
38
38
  npm pack --pack-destination dist
39
39
  ```
40
40
 
41
- exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.9.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
41
+ exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.11.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
42
42
 
43
43
  exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vanspod`](https://www.npmjs.com/package/vanspod) 套件。更新時不要執行完整移除,否則會清除課堂資料。
44
44
 
45
45
  ## GitHub Actions 發佈
46
46
 
47
- 一般 push 不發佈;推送 `v*` tag 會在 Windows runner 安裝 Node.js 24、檢查型別、執行測試、打包並驗證 exe/npm 生命週期,全部通過後才建立 GitHub Release,最後發佈 npm 套件。學生從 Release 下載 `VansPod.exe`,同頁提供 `SHA256SUMS.txt`。
47
+ 一般 push 不發佈;推送 `v*` tag 會在 Windows runner 安裝 Node.js 24、檢查型別、執行測試、打包並驗證 exe/npm 生命週期,全部通過後才建立 GitHub Release,最後發佈 npm 套件。學生從 Release 下載 `VansPod.exe`,同頁提供 `SHA256SUMS.txt`。Release 另附 brotli 壓縮的 `VansPod.exe.br`(約三分之一大小),程式內更新只下載這份,解壓後再比對 `VansPod.exe` 的 SHA-256;SHA256SUMS 沒列出它的舊版 Release 則下載完整 exe。
48
48
 
49
- 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.9` 為例:
49
+ 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.11` 為例:
50
50
 
51
51
  ```powershell
52
52
  git push origin master
53
- git tag -a v0.4.9 -m "VansPod 0.4.9"
54
- git push origin v0.4.9
53
+ git tag -a v0.4.11 -m "VansPod 0.4.11"
54
+ git push origin v0.4.11
55
55
  ```
56
56
 
57
57
  新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "0.4.9";
4
+ exports.VERSION = "0.4.11";
@@ -8,8 +8,12 @@ exports.compareVersions = compareVersions;
8
8
  exports.downloadExe = downloadExe;
9
9
  exports.createVersionUpdate = createVersionUpdate;
10
10
  const node_crypto_1 = require("node:crypto");
11
+ const node_fs_1 = require("node:fs");
11
12
  const promises_1 = __importDefault(require("node:fs/promises"));
12
13
  const node_path_1 = __importDefault(require("node:path"));
14
+ const node_stream_1 = require("node:stream");
15
+ const promises_2 = require("node:stream/promises");
16
+ const node_zlib_1 = require("node:zlib");
13
17
  const desktop_1 = require("./desktop");
14
18
  const exitGuard_1 = require("./exitGuard");
15
19
  const instance_1 = require("./instance");
@@ -83,14 +87,18 @@ function createUpdateChecker() {
83
87
  },
84
88
  };
85
89
  }
86
- function checksumFor(sums, name) {
90
+ function listedChecksum(sums, name) {
87
91
  for (const line of sums.split(/\r?\n/)) {
88
92
  const match = /^([a-f0-9]{64})\s+\*?(.+)$/i.exec(line.trim());
89
93
  if (match && match[2] === name)
90
94
  return match[1].toLowerCase();
91
95
  }
92
- throw new Error(`SHA256SUMS.txt 沒有 ${name}`);
96
+ return undefined;
93
97
  }
98
+ const EXE = "VansPod.exe";
99
+ const COMPRESSED_EXE = "VansPod.exe.br";
100
+ /** 讓每段資料經過時順手做一件事(算進度、算雜湊),資料原樣往下傳。 */
101
+ const tap = (each) => new node_stream_1.Transform({ transform(chunk, _encoding, done) { each(chunk); done(null, chunk); } });
94
102
  /** 從 GitHub Release 下載新版 exe 到原檔旁的 `.new`;SHA-256 不符就刪掉並失敗。 */
95
103
  async function downloadExe(version, file, onProgress, fetcher = fetch) {
96
104
  const get = async (name) => {
@@ -99,34 +107,44 @@ async function downloadExe(version, file, onProgress, fetcher = fetch) {
99
107
  throw new Error(`下載 ${name} 失敗(${response.status})`);
100
108
  return response;
101
109
  };
102
- const expected = checksumFor(await (await get("SHA256SUMS.txt")).text(), "VansPod.exe");
103
- const response = await get("VansPod.exe");
104
- const total = Number(response.headers.get("content-length")) || 0;
110
+ const sums = await (await get("SHA256SUMS.txt")).text();
111
+ const expected = listedChecksum(sums, EXE);
112
+ if (!expected)
113
+ throw new Error(`SHA256SUMS.txt 沒有 ${EXE}`);
105
114
  const target = `${file}.new`;
106
- const hash = (0, node_crypto_1.createHash)("sha256");
107
- const handle = await promises_1.default.open(target, "w");
108
- let received = 0;
109
- try {
110
- const reader = response.body.getReader();
111
- for (;;) {
112
- const { done, value } = await reader.read();
113
- if (done)
114
- break;
115
- hash.update(value);
116
- await handle.write(value);
117
- received += value.length;
118
- if (total)
119
- onProgress(Math.min(100, Math.floor(received * 100 / total)));
115
+ const save = async (name, compressed) => {
116
+ const response = await get(name);
117
+ const total = Number(response.headers.get("content-length")) || 0;
118
+ const hash = (0, node_crypto_1.createHash)("sha256");
119
+ let received = 0;
120
+ try {
121
+ await (0, promises_2.pipeline)([
122
+ node_stream_1.Readable.fromWeb(response.body),
123
+ tap(chunk => { received += chunk.length; if (total)
124
+ onProgress(Math.min(100, Math.floor(received * 100 / total))); }),
125
+ ...(compressed ? [(0, node_zlib_1.createBrotliDecompress)()] : []),
126
+ tap(chunk => hash.update(chunk)),
127
+ (0, node_fs_1.createWriteStream)(target),
128
+ ]);
120
129
  }
130
+ catch (error) {
131
+ await promises_1.default.rm(target, { force: true });
132
+ throw error;
133
+ }
134
+ if (hash.digest("hex") !== expected) {
135
+ await promises_1.default.rm(target, { force: true });
136
+ throw new Error(`下載的 ${EXE} 驗證失敗,已刪除。`);
137
+ }
138
+ return target;
139
+ };
140
+ // 壓縮版只有完整 exe 的三分之一左右,驗證一律比對解壓後的 exe;舊 Release 沒列出它,或它下載、解壓、驗證任一步失敗,就改下載完整 exe。
141
+ if (listedChecksum(sums, COMPRESSED_EXE)) {
142
+ try {
143
+ return await save(COMPRESSED_EXE, true);
144
+ }
145
+ catch { }
121
146
  }
122
- finally {
123
- await handle.close();
124
- }
125
- if (hash.digest("hex") !== expected) {
126
- await promises_1.default.rm(target, { force: true });
127
- throw new Error("下載的 VansPod.exe 驗證失敗,已刪除。");
128
- }
129
- return target;
147
+ return save(EXE, false);
130
148
  }
131
149
  async function folderWritable(file) {
132
150
  const probe = node_path_1.default.join(node_path_1.default.dirname(file), `.vanspod-write-${process.pid}.tmp`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanspod",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "bin": { "vanspod": "bin/vanspod.cjs" },
5
5
  "engines": { "node": ">=24" },
6
6
  "os": ["win32"],
package/scripts/tray.ps1 CHANGED
@@ -15,7 +15,7 @@ $notify = New-Object System.Windows.Forms.NotifyIcon
15
15
  $notify.Icon = New-Object System.Drawing.Icon($IconPath)
16
16
  $notify.Text = "VansPod"
17
17
  $notify.Visible = $true
18
- $notify.add_Click($openPage)
18
+ $notify.add_MouseClick({ if ($_.Button -eq [System.Windows.Forms.MouseButtons]::Left) { & $openPage } }.GetNewClosure())
19
19
 
20
20
  $menu = New-Object System.Windows.Forms.ContextMenuStrip
21
21
  $open = $menu.Items.Add("開啟 VansPod")