multi-terminals 0.5.5 → 0.5.6

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
@@ -1,7 +1,7 @@
1
1
  # MultiTerminals(多端)
2
2
 
3
3
  轻量的 Windows 多项目终端工作台:左侧组织工作区和项目,右侧运行终端,支持标签、分屏、
4
- 搜索、文件链接与 agent 会话恢复。
4
+ 文件链接与 agent 会话恢复。
5
5
 
6
6
  **关窗口不会结束终端;关终端标签会结束对应进程。** 终端由独立进程 daemon 持有,
7
7
  所以关掉窗口、升级应用,里面正在跑的构建和 agent 会话都还在。
@@ -33,8 +33,8 @@ npx multi-terminals
33
33
  ## 命令
34
34
 
35
35
  ```powershell
36
- multi-terminals # 启动;还没装就先装再启动
37
- multi-terminals install # 打开安装向导(已安装则是升级)
36
+ multi-terminals # 启动;还没装就先装再启动,装了旧版就先覆盖升级
37
+ multi-terminals install # 安装;已安装则直接覆盖升级(不需要先卸载)
38
38
  multi-terminals install --silent # 无人值守安装,装完直接启动
39
39
  multi-terminals uninstall # 卸载
40
40
  multi-terminals --version
@@ -42,10 +42,24 @@ multi-terminals --help
42
42
  ```
43
43
 
44
44
  `--dry-run` 只打印将要执行的命令行,不真的执行任何东西。
45
+ `-y` / `--yes` 跳过升级前的确认;非交互环境(管道、CI)本来就不问。
46
+
45
47
 
46
48
  ## 升级
47
49
 
48
- 再跑一次 `multi-terminals install` 即可,它会装成同一个包的最新版本。
50
+ 装上新版本就行,**不需要先卸载**:
51
+
52
+ ```powershell
53
+ npm i -g multi-terminals # 装上新版本
54
+ multi-terminals # 检测到旧版本会问一句,然后覆盖安装并启动
55
+ ```
56
+
57
+ `multi-terminals install` 也一样:检测到已安装就直接覆盖(`-y` 不问,`--silent` 不弹向导)。
58
+ 覆盖安装用的是安装包自带的 `/S /UPDATE`——跳过安装向导、不调用旧卸载器,程序、daemon、
59
+ 卸载器都由新包按名字替换,旧版本不会残留,快捷方式保持原样。
60
+
61
+ 直接双击 `MultiTerminals_<版本>_x64-setup.exe` 也一样:「已安装」那一页默认选中
62
+ 「覆盖安装(推荐,无需卸载)」,点下一步即可。
49
63
 
50
64
  **安装和升级会关闭正在运行的 MultiTerminals 窗口**(交互模式会先问一句,`--silent` 下不问)。
51
65
  **终端不会因此中断**:安装程序只会结束界面进程,而终端由另一个进程 daemon 持有,
@@ -1,7 +1,7 @@
1
1
  // Install and launch MultiTerminals — the npm face of a Windows desktop app.
2
2
  //
3
- // multi-terminals # launch it, installing first if it is not there yet
4
- // multi-terminals install # run the installer this package carries
3
+ // multi-terminals # launch it, installing or upgrading first
4
+ // multi-terminals install # install, or overwrite an existing install
5
5
  // multi-terminals install --silent # unattended install, then launch
6
6
  // multi-terminals uninstall # run the installed uninstaller
7
7
  // multi-terminals --dry-run # print the command lines, touch nothing
@@ -11,19 +11,29 @@
11
11
  // nothing an npm package does replaces that — so the installer rides along inside the
12
12
  // tarball and this script runs it.
13
13
  //
14
- // Two installer behaviours shape the flags here. Both come from Tauri's NSIS template
15
- // (`CheckIfAppIsRunning` in `utils.nsh`, the finish page in `installer.nsi`):
14
+ // Upgrades are why the flags below look the way they do. Tauri's NSIS template answers
15
+ // "a previous version is installed" with a maintenance page whose default is *uninstall
16
+ // first*, which drags the user through the old uninstaller's own dialogs. `/UPDATE` is
17
+ // the template's flag for the other path: replace the installation in place. So an
18
+ // installed older version is upgraded by asking once here and then running the installer
19
+ // with `/S /UPDATE` — no wizard, no uninstall step, and the files the installer owns
20
+ // (app, daemon sidecar, uninstaller) are replaced by name, leaving nothing of the old
21
+ // version behind. Under `/S` a running window is closed without asking; the terminals
22
+ // survive because the daemon is a different process outside the install directory.
23
+ //
24
+ // Two more installer behaviours shape the rest (both from `utils.nsh` / `installer.nsi`):
16
25
  //
17
- // - It closes a running MultiTerminals window. Interactively it asks first; under
18
- // `/S` it does not ask. Either way your terminals survive — the daemon is a
19
- // different process and does not run from the install directory.
20
26
  // - It offers to launch the app from its finish page, and that page is skipped under
21
- // `/S`. So only the silent path needs a launch from here; launching after an
27
+ // `/S`. So only the silent paths need a launch from here; launching after an
22
28
  // interactive install would race the finish page and start two windows.
29
+ // - Under `/S` it also creates a desktop shortcut. That is the second reason upgrades
30
+ // pass `/UPDATE` (which creates no shortcuts): an upgrade must not add an icon the
31
+ // user never asked for, and the existing Start Menu shortcut already works.
23
32
 
24
33
  import { execFileSync, spawn, spawnSync } from 'node:child_process'
25
34
  import { existsSync, readFileSync, readdirSync } from 'node:fs'
26
35
  import path from 'node:path'
36
+ import { createInterface } from 'node:readline/promises'
27
37
  import { fileURLToPath } from 'node:url'
28
38
 
29
39
  const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
@@ -43,8 +53,8 @@ const dryRun = flag('--dry-run')
43
53
  const USAGE = `MultiTerminals ${version} —— Windows 多项目终端工作台
44
54
 
45
55
  用法:
46
- multi-terminals 启动应用;还没装就先装再启动
47
- multi-terminals install 运行本包携带的安装程序
56
+ multi-terminals 启动应用;没装就先装,装了旧版本就先覆盖升级
57
+ multi-terminals install 安装,或覆盖已有安装(不需要先卸载)
48
58
  multi-terminals install --silent
49
59
  无人值守安装,装完直接启动
50
60
  multi-terminals uninstall 运行已装好的卸载程序
@@ -53,9 +63,12 @@ const USAGE = `MultiTerminals ${version} —— Windows 多项目终端工作台
53
63
 
54
64
  选项:
55
65
  -s, --silent 安装时不弹向导(等价于 NSIS 的 /S)
66
+ -y, --yes 检测到旧版本时不再询问,直接覆盖升级
56
67
  --dry-run 只打印将要执行的命令行,不真的执行
57
68
 
58
69
  说明:
70
+ 升级是覆盖安装:检测到旧版本时先问一句,然后用安装包的 /S /UPDATE 直接覆盖,
71
+ 不需要手动卸载,也不会留下旧版本的文件(程序、daemon、卸载器按名字替换)。
59
72
  安装程序会关闭正在运行的 MultiTerminals 窗口(交互模式会先问一句,--silent 下不问)。
60
73
  终端不会因此中断:终端由独立进程 daemon 持有,安装程序不会碰它。
61
74
  工作区、标签和布局保存在 %APPDATA%\\MultiTerminals,安装、升级、卸载都不会删除。`
@@ -101,15 +114,66 @@ function installedApp() {
101
114
  return existsSync(exe) ? exe : null
102
115
  }
103
116
 
104
- function runInstaller({ silent }) {
117
+ /** What Add/Remove Programs says is installed, or null when the registry stays quiet. */
118
+ function installedVersion() {
119
+ try {
120
+ const out = execFileSync('reg', ['query', UNINSTALL_KEY, '/v', 'DisplayVersion'], { encoding: 'utf8' })
121
+ const match = /DisplayVersion\s+REG_SZ\s+(.*)/.exec(out)
122
+ return match ? match[1].trim() : null
123
+ } catch {
124
+ return null
125
+ }
126
+ }
127
+
128
+ /** Enough semver for `x.y.z`: three numbers, anything unreadable counts as zero. */
129
+ function compareVersions(left, right) {
130
+ const parts = (value) =>
131
+ String(value ?? '')
132
+ .split(/[.+-]/)
133
+ .slice(0, 3)
134
+ .map((chunk) => Number.parseInt(chunk, 10) || 0)
135
+ const a = parts(left)
136
+ const b = parts(right)
137
+ for (let i = 0; i < 3; i += 1) {
138
+ if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1
139
+ }
140
+ return 0
141
+ }
142
+
143
+ /**
144
+ * Ask before replacing a working install. Non-interactive callers, `--yes` and
145
+ * `--silent` all mean "yes": a scripted install must not hang on a question.
146
+ */
147
+ async function confirmUpgrade(installed) {
148
+ if (dryRun || flag('--yes', '-y') || flag('--silent', '-s') || !process.stdin.isTTY) return true
149
+ const prompt =
150
+ `检测到已安装 MultiTerminals ${installed ?? '(版本未知)'},当前包是 ${version}。\n` +
151
+ '将直接覆盖安装,不需要手动卸载;程序窗口会被关闭再重开,终端和工作区不受影响。\n' +
152
+ '继续?[Y/n] '
153
+ const rl = createInterface({ input: process.stdin, output: process.stdout })
154
+ try {
155
+ const answer = (await rl.question(prompt)).trim().toLowerCase()
156
+ return answer === '' || answer.startsWith('y') || answer === '是'
157
+ } finally {
158
+ rl.close()
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Run the installer: the wizard for a first install, or the silent in-place overwrite
164
+ * for an upgrade (`update`). Under `/S` NSIS shows no pages at all, which is what makes
165
+ * the upgrade click-free; `/UPDATE` additionally keeps the shortcuts untouched.
166
+ */
167
+ function runInstaller({ silent, update = false }) {
105
168
  const installer = findInstaller()
106
- const installerArgs = silent ? ['/S'] : []
169
+ const installerArgs = [...(silent ? ['/S'] : []), ...(update ? ['/UPDATE'] : [])]
107
170
  const line = [installer, ...installerArgs].join(' ')
108
171
  if (dryRun) {
109
172
  console.log(`[dry-run] ${line}`)
110
173
  return
111
174
  }
112
- console.log(silent ? 'installing (silent)…' : '正在打开安装向导…')
175
+ if (update) console.log(`正在覆盖安装 MultiTerminals ${version}(不需要先卸载)…`)
176
+ else console.log(silent ? 'installing (silent)…' : '正在打开安装向导…')
113
177
  const result = spawnSync(installer, installerArgs, { stdio: 'inherit', windowsHide: false })
114
178
  if (result.error) fail(`could not run the installer: ${result.error.message}`)
115
179
  // NSIS reports its own failures in a dialog and still exits 0 often enough that the
@@ -117,6 +181,20 @@ function runInstaller({ silent }) {
117
181
  // and the caller makes it.
118
182
  }
119
183
 
184
+ /**
185
+ * Install this package's version over the one that is there, with no uninstall step.
186
+ * Returns the installed executable, or null under `--dry-run`.
187
+ */
188
+ function overwriteInstall() {
189
+ runInstaller({ silent: true, update: true })
190
+ if (dryRun) return null
191
+ const now = installedApp()
192
+ if (!now) {
193
+ fail('覆盖安装似乎没有完成:注册表里没有 MultiTerminals,默认目录下也没有可执行文件。请重新执行一次,或手动运行安装包。', 1)
194
+ }
195
+ return now
196
+ }
197
+
120
198
  function launch(exe) {
121
199
  if (dryRun) {
122
200
  console.log(`[dry-run] ${exe}`)
@@ -144,6 +222,17 @@ switch (command) {
144
222
  case 'run': {
145
223
  const already = installedApp()
146
224
  if (already) {
225
+ const current = installedVersion()
226
+ if (compareVersions(current, version) < 0) {
227
+ console.log(`检测到已安装 ${current ?? '(版本未知)'},将覆盖升级到 ${version}。`)
228
+ if (!(await confirmUpgrade(current))) {
229
+ console.log('已取消,什么都没有改动。')
230
+ break
231
+ }
232
+ const now = overwriteInstall()
233
+ if (now) launch(now)
234
+ break
235
+ }
147
236
  launch(already)
148
237
  break
149
238
  }
@@ -157,12 +246,26 @@ switch (command) {
157
246
  break
158
247
  }
159
248
  case 'install': {
160
- runInstaller({ silent: flag('--silent', '-s') })
249
+ const silent = flag('--silent', '-s')
250
+ if (installedApp()) {
251
+ const current = installedVersion()
252
+ if (compareVersions(current, version) < 0) {
253
+ console.log(`检测到已安装 ${current ?? '(版本未知)'},将覆盖升级到 ${version}。`)
254
+ }
255
+ if (!(await confirmUpgrade(current))) {
256
+ console.log('已取消,什么都没有改动。')
257
+ break
258
+ }
259
+ const now = overwriteInstall()
260
+ if (now) launch(now)
261
+ break
262
+ }
263
+ runInstaller({ silent })
161
264
  if (dryRun) break
162
265
  const now = installedApp()
163
266
  if (!now) fail('安装似乎没有完成:注册表里没有 MultiTerminals,默认目录下也没有可执行文件。', 1)
164
267
  // The finish page is skipped under `/S`, so a silent install leaves nothing running.
165
- if (flag('--silent', '-s')) launch(now)
268
+ if (silent) launch(now)
166
269
  else console.log(`已安装到 ${now}`)
167
270
  break
168
271
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multi-terminals",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "轻量的 Windows 多项目终端工作台:关窗口不会结束终端",
5
5
  "keywords": [
6
6
  "terminal",
Binary file