aaden-cli 1.6.123 → 1.6.125

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.
@@ -0,0 +1,218 @@
1
+ #!/bin/bash
2
+ # Windows 门店(后端跑在 WSL 里):经 WSL interop 调 Windows 的 PowerShell,查看 / 升级桌面收银 Aaden Desktop。
3
+ # 云端设备命令 WINDOWS_PROBE(probe)和 DESKTOP_UPDATE(update)用,输出整段回传云端。
4
+ #
5
+ # bash windowsDesktop.sh probe 只读:装在哪、什么版本、谁在用、多久没人操作、有没有已下载待装的更新
6
+ # bash windowsDesktop.sh update 下载最新安装包 → 收银电脑 10 分钟没人操作才动手 → 关掉收银程序、静默安装、重新打开
7
+ #
8
+ # 起因(POS-129 / POS-148):1.2.160 以前的桌面端只在正常退出时才装更新,收银机全屏、没人正常退出,
9
+ # 75 台 Windows 停在旧版本。装上 1.2.160 以后它会自己更新,这里只需要推一次。
10
+ #
11
+ # WSL 是门店 Windows 登录用户的启动项(run_hidden.vbs → start-aaden-server.bat)拉起来的,
12
+ # 所以经 interop 起的 Windows 进程以这个登录用户、在他的桌面会话里运行,桌面端也装在他的 %LOCALAPPDATA%。
13
+ #
14
+ # 退出码:0 成功(探测成功 / 装好了 / 已是最新);3 不是 WSL;4 调不起 Windows 程序;
15
+ # 22 收银电脑有人在用,没动;其余是升级失败(见输出)
16
+ MODE=${1:-probe}
17
+ MIN_IDLE_SECONDS=600
18
+ PS=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
19
+
20
+ if [ "$MODE" != probe ] && [ "$MODE" != update ]; then
21
+ echo "用法: windowsDesktop.sh probe|update"
22
+ exit 2
23
+ fi
24
+
25
+ if ! grep -qi microsoft /proc/version 2>/dev/null; then
26
+ echo "不是 WSL 设备($(uname -r)),这条命令只对 Windows 门店"
27
+ exit 3
28
+ fi
29
+
30
+ echo "WSL: $(uname -r) 用户: $(id -un)"
31
+ echo "binfmt WSLInterop: $(head -1 /proc/sys/fs/binfmt_misc/WSLInterop 2>/dev/null || echo 没有)"
32
+ echo "WSL_INTEROP: ${WSL_INTEROP:-(未设置,cron 下正常)}"
33
+ ls -l /run/WSL/ 2>/dev/null | sed 's/^/ /'
34
+
35
+ if [ ! -e "$PS" ]; then
36
+ echo "找不到 $PS(C 盘没挂到 /mnt/c?)"
37
+ ls -ld /mnt/c 2>&1
38
+ exit 4
39
+ fi
40
+
41
+ PS_PREFIX=()
42
+ try_ps() { timeout 60 "${PS_PREFIX[@]}" "$PS" -NoProfile -NonInteractive -Command 'exit 0' </dev/null >/dev/null 2>&1; }
43
+
44
+ # cron 和命令执行进程里没有 WSL_INTEROP,直接调 .exe 可能起不来:依次试 /run/WSL 下的 interop socket,再试 sudo
45
+ setup_interop() {
46
+ try_ps && { echo "interop: 直接可用"; return 0; }
47
+ local s
48
+ for s in $(ls -t /run/WSL/*_interop 2>/dev/null); do
49
+ PS_PREFIX=(env WSL_INTEROP="$s")
50
+ try_ps && { echo "interop: 用 $s"; return 0; }
51
+ done
52
+ if [ -n "$AADEN_PW" ] && echo "$AADEN_PW" | sudo -S -p '' -v 2>/dev/null; then
53
+ for s in $(ls -t /run/WSL/*_interop 2>/dev/null); do
54
+ PS_PREFIX=(sudo -n env WSL_INTEROP="$s")
55
+ try_ps && { echo "interop: sudo + $s"; return 0; }
56
+ done
57
+ fi
58
+ PS_PREFIX=()
59
+ return 1
60
+ }
61
+
62
+ if ! setup_interop; then
63
+ echo "调不起 Windows 的 PowerShell(interop 没开,或者 socket 不可用),没法从这里管桌面端"
64
+ exit 4
65
+ fi
66
+
67
+ # 跑一段 PowerShell:用 -EncodedCommand 传,免得引号转义;Windows 输出的 \r 去掉
68
+ run_ps() {
69
+ local enc
70
+ enc=$(printf '%s' "$1" | iconv -f UTF-8 -t UTF-16LE | base64 -w0)
71
+ timeout "${2:-120}" "${PS_PREFIX[@]}" "$PS" -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand "$enc" </dev/null 2>&1 | tr -d '\r'
72
+ return "${PIPESTATUS[0]}"
73
+ }
74
+
75
+ # 两种模式共用:路径、版本、桌面会话、空闲时间
76
+ read -r -d '' PS_COMMON <<'EOF'
77
+ $ErrorActionPreference = 'Stop'
78
+ $ProgressPreference = 'SilentlyContinue'
79
+ $exe = Join-Path $env:LOCALAPPDATA 'Programs\aaden\Aaden Desktop.exe'
80
+ $mySession = [Diagnostics.Process]::GetCurrentProcess().SessionId
81
+ function Get-InstalledVersion {
82
+ if (-not (Test-Path $exe)) { return $null }
83
+ $v = (Get-Item $exe).VersionInfo.ProductVersion
84
+ if (-not $v) { return $null }
85
+ return (($v -split '[^0-9.]')[0].Split('.') | Select-Object -First 3) -join '.'
86
+ }
87
+ function Get-DesktopProcesses { @(Get-CimInstance Win32_Process -Filter "Name='Aaden Desktop.exe'") }
88
+ function Get-IdleSeconds {
89
+ if (-not ('AadenIdle' -as [type])) {
90
+ Add-Type -TypeDefinition @'
91
+ using System;
92
+ using System.Runtime.InteropServices;
93
+ public static class AadenIdle {
94
+ [StructLayout(LayoutKind.Sequential)] struct LastInput { public uint cbSize; public uint dwTime; }
95
+ [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LastInput info);
96
+ public static long Seconds() {
97
+ var info = new LastInput(); info.cbSize = (uint)Marshal.SizeOf(info);
98
+ if (!GetLastInputInfo(ref info)) return -1;
99
+ return (long)(((uint)Environment.TickCount - info.dwTime) / 1000);
100
+ }
101
+ }
102
+ '@
103
+ }
104
+ [AadenIdle]::Seconds()
105
+ }
106
+ # 最新版本:先读 S3(POS-36,发版 workflow 上传,和 GitHub Release 同一份 latest.yml);
107
+ # S3 读不到才退回 GitHub Releases(仓库改私有前的退路)。S3 的 latest.yml 带 sha512,下载后校验
108
+ function Get-LatestDesktop {
109
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
110
+ $base = 'https://aaden-backend.s3.eu-central-1.amazonaws.com/desktop/win/'
111
+ try {
112
+ $res = Invoke-WebRequest ($base + 'latest.yml') -UseBasicParsing -TimeoutSec 30
113
+ $yml = [Text.Encoding]::UTF8.GetString($res.RawContentStream.ToArray())
114
+ $version = [regex]::Match($yml, '(?m)^version:\s*(\S+)').Groups[1].Value
115
+ $name = [regex]::Match($yml, '(?m)^path:\s*(\S+)').Groups[1].Value
116
+ $sha512 = [regex]::Match($yml, '(?m)^sha512:\s*(\S+)').Groups[1].Value
117
+ $size = [regex]::Match($yml, '(?m)^\s+size:\s*(\d+)').Groups[1].Value
118
+ if ($version -and $name -and $sha512) {
119
+ return [pscustomobject]@{ Source = 's3'; Version = $version; Name = $name; Url = $base + $name; Sha512 = $sha512; Size = [long]$size }
120
+ }
121
+ } catch { }
122
+ $r = Invoke-RestMethod 'https://api.github.com/repos/innerken-gmbh/aaden-vue-app/releases/latest' -UseBasicParsing -TimeoutSec 30
123
+ $asset = $r.assets | Where-Object { $_.name -like '*.exe' } | Select-Object -First 1
124
+ if (-not $asset) { throw "release $($r.tag_name) has no .exe" }
125
+ [pscustomobject]@{ Source = 'github'; Version = $r.tag_name.TrimStart('v'); Name = $asset.name; Url = $asset.browser_download_url; Sha512 = $null; Size = [long]$asset.size }
126
+ }
127
+ function Get-Sha512Base64($path) {
128
+ $hex = (Get-FileHash $path -Algorithm SHA512).Hash
129
+ $bytes = [byte[]](0..($hex.Length / 2 - 1) | ForEach-Object { [Convert]::ToByte($hex.Substring($_ * 2, 2), 16) })
130
+ [Convert]::ToBase64String($bytes)
131
+ }
132
+ EOF
133
+
134
+ read -r -d '' PS_PROBE <<'EOF'
135
+ $ErrorActionPreference = 'Continue'
136
+ "windows_user=$env:USERDOMAIN\$env:USERNAME session=$mySession"
137
+ try { $os = Get-CimInstance Win32_OperatingSystem; "os=$($os.Caption) $($os.Version) boot=$($os.LastBootUpTime)" } catch { "os=? $_" }
138
+ "exe=$exe exists=$(Test-Path $exe) version=$(Get-InstalledVersion)"
139
+ $machineWide = Join-Path $env:ProgramFiles 'Aaden Desktop\Aaden Desktop.exe'
140
+ "program_files_install=$(Test-Path $machineWide)"
141
+ $procs = Get-DesktopProcesses
142
+ "desktop_processes=$($procs.Count)"
143
+ $procs | Group-Object SessionId, ExecutablePath | ForEach-Object { " session/path=$($_.Name) count=$($_.Count)" }
144
+ $main = $procs | Where-Object { $procs.ProcessId -notcontains $_.ParentProcessId } | Select-Object -First 1
145
+ if ($main) {
146
+ try { $o = Invoke-CimMethod -InputObject $main -MethodName GetOwner; " main pid=$($main.ProcessId) owner=$($o.Domain)\$($o.User) started=$($main.CreationDate)" } catch { " owner=? $_" }
147
+ }
148
+ try { "idle_seconds=$(Get-IdleSeconds)" } catch { "idle_seconds=? $_" }
149
+ $pending = Join-Path $env:LOCALAPPDATA 'aaden-updater\pending'
150
+ if (Test-Path $pending) { "updater_pending=$((Get-ChildItem $pending | ForEach-Object { $_.Name }) -join ',')" } else { 'updater_pending=none' }
151
+ $startup = [Environment]::GetFolderPath('Startup')
152
+ "startup_run_hidden=$(Test-Path (Join-Path $startup 'run_hidden.vbs'))"
153
+ try { $l = Get-LatestDesktop; "latest=$($l.Version) source=$($l.Source)" } catch { "latest=? $_" }
154
+ EOF
155
+
156
+ read -r -d '' PS_UPDATE <<'EOF'
157
+ $current = Get-InstalledVersion
158
+ "installed=$current"
159
+ if (-not $current) { "ABORT: Aaden Desktop is not installed at $exe"; exit 20 }
160
+ $other = @(Get-DesktopProcesses | Where-Object { $_.SessionId -ne $mySession })
161
+ if ($other.Count) { "ABORT: Aaden Desktop is running in another session ($(($other | ForEach-Object { $_.SessionId } | Sort-Object -Unique) -join ',')), ours is $mySession"; exit 21 }
162
+ $idle = Get-IdleSeconds
163
+ "idle_seconds=$idle"
164
+ if ($idle -lt __MIN_IDLE__) { "BUSY: last keyboard/mouse input $idle s ago (< __MIN_IDLE__ s), not touching it"; exit 22 }
165
+ $l = Get-LatestDesktop
166
+ $latest = $l.Version
167
+ "latest=$latest source=$($l.Source)"
168
+ if ($current -eq $latest) { 'UP_TO_DATE'; exit 0 }
169
+ $file = Join-Path $env:TEMP $l.Name
170
+ Invoke-WebRequest $l.Url -OutFile $file -UseBasicParsing -TimeoutSec 900
171
+ $size = (Get-Item $file).Length
172
+ "downloaded $($l.Name) $size bytes"
173
+ if ($l.Size -and $size -ne $l.Size) { "ABORT: size mismatch, expected $($l.Size)"; exit 23 }
174
+ if ($l.Sha512) {
175
+ if ((Get-Sha512Base64 $file) -ne $l.Sha512) { 'ABORT: sha512 mismatch, not installing'; exit 23 }
176
+ 'sha512 ok'
177
+ }
178
+ # 下载可能要几分钟,动手前再确认一次没人在用
179
+ $idle = Get-IdleSeconds
180
+ if ($idle -lt __MIN_IDLE__) { "BUSY after download: last input $idle s ago, not touching it"; exit 22 }
181
+ Stop-Process -Name 'Aaden Desktop' -Force -ErrorAction SilentlyContinue
182
+ Start-Sleep -Seconds 2
183
+ $installer = Start-Process $file -ArgumentList '/S' -PassThru
184
+ $null = $installer.Handle
185
+ $finished = $installer.WaitForExit(300000)
186
+ $after = Get-InstalledVersion
187
+ # 不管装没装好都把收银程序开回来;经 explorer 打开,不挂在这个进程下面
188
+ Start-Process explorer.exe -ArgumentList ('"' + $exe + '"')
189
+ if (-not $finished) { "FAILED: installer still running after 5 minutes"; exit 24 }
190
+ "installer_exit=$($installer.ExitCode) installed_after=$after"
191
+ if ($after -ne $latest) { "FAILED: version is $after, expected $latest"; exit 25 }
192
+ "INSTALLED $current -> $after"
193
+ exit 0
194
+ EOF
195
+
196
+ # 升级后过一会儿再看:收银程序没起来就再开一次
197
+ read -r -d '' PS_CHECK_RUNNING <<'EOF'
198
+ $n = (Get-DesktopProcesses).Count
199
+ "desktop_processes=$n installed=$(Get-InstalledVersion)"
200
+ if (-not $n) { Start-Process explorer.exe -ArgumentList ('"' + $exe + '"'); 'relaunched'; exit 1 }
201
+ EOF
202
+
203
+ case "$MODE" in
204
+ probe)
205
+ echo "--- Windows 侧"
206
+ run_ps "$PS_COMMON"$'\n'"$PS_PROBE" 180
207
+ exit $?
208
+ ;;
209
+ update)
210
+ echo "--- 升级(收银电脑 ${MIN_IDLE_SECONDS} 秒没人操作才动手)"
211
+ run_ps "$PS_COMMON"$'\n'"${PS_UPDATE//__MIN_IDLE__/$MIN_IDLE_SECONDS}" 1500
212
+ code=$?
213
+ [ "$code" -ne 0 ] && exit "$code"
214
+ sleep 20
215
+ echo "--- 20 秒后确认收银程序在运行"
216
+ run_ps "$PS_COMMON"$'\n'"$PS_CHECK_RUNNING" 120
217
+ ;;
218
+ esac
package/dist/index.js CHANGED
@@ -116,6 +116,9 @@ const COMMANDS = {
116
116
  // 诊断脚本在门店后端里(≥ 1.9.80):do-log 坏了的设备由云端经 ngrok 触发同一个脚本
117
117
  DIAGNOSE: () => 'S=/var/www/html/PHP/scripts/diagnose.sh; if [ -f "$S" ]; then bash "$S"; ' +
118
118
  'else echo "后端低于 1.9.80,没有诊断脚本:先下发「只更新后端」"; exit 2; fi',
119
+ // Windows 门店(后端在 WSL 里):经 interop 查看 / 升级 Windows 上的桌面收银(POS-148)
120
+ WINDOWS_PROBE: root => 'bash ' + JSON.stringify(path.join(root, 'AadenDeploy/windowsDesktop.sh')) + ' probe',
121
+ DESKTOP_UPDATE: root => 'bash ' + JSON.stringify(path.join(root, 'AadenDeploy/windowsDesktop.sh')) + ' update',
119
122
  }
120
123
 
121
124
  /** 每条命令最多跑多久;latest.zip 全量在慢网络上要 20 分钟 */
@@ -19352,7 +19355,7 @@ module.exports = JSON.parse('{"name":"axios","version":"0.19.2","description":"P
19352
19355
  /***/ ((module) => {
19353
19356
 
19354
19357
  "use strict";
19355
- module.exports = {"i8":"1.6.123"};
19358
+ module.exports = {"i8":"1.6.125"};
19356
19359
 
19357
19360
  /***/ })
19358
19361
 
@@ -29,6 +29,9 @@ const COMMANDS = {
29
29
  // 诊断脚本在门店后端里(≥ 1.9.80):do-log 坏了的设备由云端经 ngrok 触发同一个脚本
30
30
  DIAGNOSE: () => 'S=/var/www/html/PHP/scripts/diagnose.sh; if [ -f "$S" ]; then bash "$S"; ' +
31
31
  'else echo "后端低于 1.9.80,没有诊断脚本:先下发「只更新后端」"; exit 2; fi',
32
+ // Windows 门店(后端在 WSL 里):经 interop 查看 / 升级 Windows 上的桌面收银(POS-148)
33
+ WINDOWS_PROBE: root => 'bash ' + JSON.stringify(path.join(root, 'AadenDeploy/windowsDesktop.sh')) + ' probe',
34
+ DESKTOP_UPDATE: root => 'bash ' + JSON.stringify(path.join(root, 'AadenDeploy/windowsDesktop.sh')) + ' update',
32
35
  }
33
36
 
34
37
  /** 每条命令最多跑多久;latest.zip 全量在慢网络上要 20 分钟 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aaden-cli",
3
- "version": "1.6.123",
3
+ "version": "1.6.125",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {