From 29981e123293ccc92fc01f2271cfd26451210cfc Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Sat, 31 Jan 2026 15:51:04 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=89=93=E5=8C=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9482455..b353404 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,9 +21,25 @@ jobs: - name: Install Node.js uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22.12 cache: 'npm' + - name: Configure Windows SDK WinMD + shell: powershell + run: | + $sdkRoot = Join-Path ${env:ProgramFiles(x86)} "Windows Kits\\10" + $unionRoot = Join-Path $sdkRoot "UnionMetadata" + $refsRoot = Join-Path $sdkRoot "References" + if (!(Test-Path $unionRoot)) { throw "UnionMetadata not found at $unionRoot" } + $winmdDir = Get-ChildItem $unionRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1 + if (!$winmdDir) { throw "No UnionMetadata version directory found" } + $refsDir = Get-ChildItem $refsRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1 + if (!$refsDir) { throw "No References version directory found" } + $libPath = "$($winmdDir.FullName);$($refsDir.FullName)" + "LIBPATH=$libPath" | Out-File -FilePath $env:GITHUB_ENV -Append + "WindowsSdkDir=$sdkRoot\\" | Out-File -FilePath $env:GITHUB_ENV -Append + "WindowsSdkVersion=$($winmdDir.Name)\\" | Out-File -FilePath $env:GITHUB_ENV -Append + - name: Install Dependencies run: npm ci @@ -58,4 +74,4 @@ jobs: [点击加入 Telegram 群](https://t.me/+hn3QzNc4DbA0MzNl) EOF - gh release edit "$GITHUB_REF_NAME" --notes-file release_notes.md \ No newline at end of file + gh release edit "$GITHUB_REF_NAME" --notes-file release_notes.md From baa949a301fd64c62d3f189aa0c6d23d105a6717 Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Sat, 31 Jan 2026 15:56:27 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=91=83=E5=91=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b353404..958ba50 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,7 +21,7 @@ jobs: - name: Install Node.js uses: actions/setup-node@v4 with: - node-version: 22.12 + node-version: 20.20.0 cache: 'npm' - name: Configure Windows SDK WinMD From 2cfe0d8ee84b2adec5a5d32dbb6206e48e777da4 Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Sat, 31 Jan 2026 16:01:21 +0800 Subject: [PATCH 3/6] ee --- .github/workflows/release.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 958ba50..a9c565c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,14 +31,20 @@ jobs: $unionRoot = Join-Path $sdkRoot "UnionMetadata" $refsRoot = Join-Path $sdkRoot "References" if (!(Test-Path $unionRoot)) { throw "UnionMetadata not found at $unionRoot" } - $winmdDir = Get-ChildItem $unionRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1 - if (!$winmdDir) { throw "No UnionMetadata version directory found" } - $refsDir = Get-ChildItem $refsRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1 + $platformWinmd = Get-ChildItem $unionRoot -Recurse -Filter platform.winmd -ErrorAction SilentlyContinue | + Sort-Object FullName -Descending | Select-Object -First 1 + if (!$platformWinmd) { throw "platform.winmd not found under $unionRoot" } + $platformDir = Split-Path $platformWinmd.FullName -Parent + $versionDir = $platformWinmd.Directory.Name + $refsDir = Join-Path $refsRoot $versionDir + if (!(Test-Path $refsDir)) { + $refsDir = Get-ChildItem $refsRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1 + } if (!$refsDir) { throw "No References version directory found" } - $libPath = "$($winmdDir.FullName);$($refsDir.FullName)" - "LIBPATH=$libPath" | Out-File -FilePath $env:GITHUB_ENV -Append - "WindowsSdkDir=$sdkRoot\\" | Out-File -FilePath $env:GITHUB_ENV -Append - "WindowsSdkVersion=$($winmdDir.Name)\\" | Out-File -FilePath $env:GITHUB_ENV -Append + $libPath = "$platformDir;$($refsDir.FullName)" + Add-Content -Path $env:GITHUB_ENV -Value "LIBPATH=$libPath" -Encoding utf8 + Add-Content -Path $env:GITHUB_ENV -Value "WindowsSdkDir=$sdkRoot\\" -Encoding utf8 + Add-Content -Path $env:GITHUB_ENV -Value "WindowsSdkVersion=$versionDir\\" -Encoding utf8 - name: Install Dependencies run: npm ci From cf292ca9e25ee4cb14ff246c4813a04a2bfcfba9 Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Sat, 31 Jan 2026 16:06:36 +0800 Subject: [PATCH 4/6] hh --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a9c565c..5eedc11 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ permissions: jobs: release: - runs-on: windows-latest + runs-on: windows-2022 steps: - name: Check out git repository From 97f0077e95df5148fa15309a3b76b70794163ab8 Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Sat, 31 Jan 2026 16:14:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E6=89=93=E5=8C=85=E4=BD=A0=E5=BF=AB?= =?UTF-8?q?=E4=BF=AE=E5=A5=BD=E5=95=8A=20=E6=88=91=E6=9C=8D=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 26 ++------------------------ package-lock.json | 13 +------------ package.json | 5 ++--- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5eedc11..9f2fcc9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ permissions: jobs: release: - runs-on: windows-2022 + runs-on: windows-latest steps: - name: Check out git repository @@ -21,31 +21,9 @@ jobs: - name: Install Node.js uses: actions/setup-node@v4 with: - node-version: 20.20.0 + node-version: 22.12 cache: 'npm' - - name: Configure Windows SDK WinMD - shell: powershell - run: | - $sdkRoot = Join-Path ${env:ProgramFiles(x86)} "Windows Kits\\10" - $unionRoot = Join-Path $sdkRoot "UnionMetadata" - $refsRoot = Join-Path $sdkRoot "References" - if (!(Test-Path $unionRoot)) { throw "UnionMetadata not found at $unionRoot" } - $platformWinmd = Get-ChildItem $unionRoot -Recurse -Filter platform.winmd -ErrorAction SilentlyContinue | - Sort-Object FullName -Descending | Select-Object -First 1 - if (!$platformWinmd) { throw "platform.winmd not found under $unionRoot" } - $platformDir = Split-Path $platformWinmd.FullName -Parent - $versionDir = $platformWinmd.Directory.Name - $refsDir = Join-Path $refsRoot $versionDir - if (!(Test-Path $refsDir)) { - $refsDir = Get-ChildItem $refsRoot -Directory | Sort-Object Name -Descending | Select-Object -First 1 - } - if (!$refsDir) { throw "No References version directory found" } - $libPath = "$platformDir;$($refsDir.FullName)" - Add-Content -Path $env:GITHUB_ENV -Value "LIBPATH=$libPath" -Encoding utf8 - Add-Content -Path $env:GITHUB_ENV -Value "WindowsSdkDir=$sdkRoot\\" -Encoding utf8 - Add-Content -Path $env:GITHUB_ENV -Value "WindowsSdkVersion=$versionDir\\" -Encoding utf8 - - name: Install Dependencies run: npm ci diff --git a/package-lock.json b/package-lock.json index 6a7f552..7a5223f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "weflow", - "version": "1.4.2", + "version": "1.4.3", "lockfileVersion": 3, "requires": true, "packages": { @@ -9,7 +9,6 @@ "version": "1.4.2", "hasInstallScript": true, "dependencies": { - "@nodert-win10-rs4/windows.security.credentials.ui": "^0.4.4", "better-sqlite3": "^12.5.0", "echarts": "^5.5.1", "echarts-for-react": "^3.0.2", @@ -1949,16 +1948,6 @@ "node": ">= 10.0.0" } }, - "node_modules/@nodert-win10-rs4/windows.security.credentials.ui": { - "version": "0.4.4", - "resolved": "https://registry.npmmirror.com/@nodert-win10-rs4/windows.security.credentials.ui/-/windows.security.credentials.ui-0.4.4.tgz", - "integrity": "sha512-P+EsJw5MCQXTxp7mwXfNDvIzIYsB6ple+HNg01QjPWg/PJfAodPuxL6XM7l0sPtYHsDYnfnvoefZMdZRa2Z1ig==", - "hasInstallScript": true, - "license": "Apache-2.0", - "dependencies": { - "nan": "latest" - } - }, "node_modules/@npmcli/agent": { "version": "3.0.0", "resolved": "https://registry.npmmirror.com/@npmcli/agent/-/agent-3.0.0.tgz", diff --git a/package.json b/package.json index ae8d645..6950122 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "weflow", - "version": "1.4.2", + "version": "1.4.3", "description": "WeFlow", "main": "dist-electron/main.js", "author": "cc", @@ -15,7 +15,6 @@ "electron:build": "npm run build" }, "dependencies": { - "@nodert-win10-rs4/windows.security.credentials.ui": "^0.4.4", "better-sqlite3": "^12.5.0", "echarts": "^5.5.1", "echarts-for-react": "^3.0.2", @@ -127,4 +126,4 @@ } ] } -} \ No newline at end of file +} From 014f57f152f14e4748736ca79be12aa942af6607 Mon Sep 17 00:00:00 2001 From: xuncha <1658671838@qq.com> Date: Sat, 31 Jan 2026 17:44:52 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A7=98=E9=92=A5=E8=8E=B7=E5=8F=96=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/services/keyService.ts | 71 ++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/electron/services/keyService.ts b/electron/services/keyService.ts index de123ca..e17c285 100644 --- a/electron/services/keyService.ts +++ b/electron/services/keyService.ts @@ -43,6 +43,7 @@ export class KeyService { private GetWindowThreadProcessId: any = null private IsWindowVisible: any = null private EnumChildWindows: any = null + private PostMessageW: any = null private WNDENUMPROC_PTR: any = null // Advapi32 @@ -57,6 +58,7 @@ export class KeyService { private readonly HKEY_LOCAL_MACHINE = 0x80000002 private readonly HKEY_CURRENT_USER = 0x80000001 private readonly ERROR_SUCCESS = 0 + private readonly WM_CLOSE = 0x0010 private getDllPath(): string { const isPackaged = typeof app !== 'undefined' && app ? app.isPackaged : process.env.NODE_ENV === 'production' @@ -224,6 +226,7 @@ export class KeyService { this.EnumWindows = this.user32.func('EnumWindows', 'bool', [this.WNDENUMPROC_PTR, 'intptr_t']) this.EnumChildWindows = this.user32.func('EnumChildWindows', 'bool', ['void*', this.WNDENUMPROC_PTR, 'intptr_t']) + this.PostMessageW = this.user32.func('PostMessageW', 'bool', ['void*', 'uint32', 'uintptr_t', 'intptr_t']) this.GetWindowTextW = this.user32.func('GetWindowTextW', 'int', ['void*', this.koffi.out('uint16*'), 'int']) this.GetWindowTextLengthW = this.user32.func('GetWindowTextLengthW', 'int', ['void*']) @@ -437,14 +440,55 @@ export class KeyService { return fallbackPid ?? null } - private async killWeChatProcesses() { + private async waitForWeChatExit(timeoutMs = 8000): Promise { + const start = Date.now() + while (Date.now() - start < timeoutMs) { + const weixinPid = await this.findPidByImageName('Weixin.exe') + const wechatPid = await this.findPidByImageName('WeChat.exe') + if (!weixinPid && !wechatPid) return true + await new Promise(r => setTimeout(r, 400)) + } + return false + } + + private async closeWeChatWindows(timeoutMs = 8000): Promise { + if (!this.ensureUser32()) return false + let requested = false + + const enumWindowsCallback = this.koffi.register((hWnd: any, lParam: any) => { + if (!this.IsWindowVisible(hWnd)) return true + const title = this.getWindowTitle(hWnd) + const className = this.getClassName(hWnd) + const classLower = (className || '').toLowerCase() + const isWeChatWindow = this.isWeChatWindowTitle(title) || classLower.includes('wechat') || classLower.includes('weixin') + if (!isWeChatWindow) return true + + requested = true + try { + this.PostMessageW?.(hWnd, this.WM_CLOSE, 0, 0) + } catch { } + return true + }, this.WNDENUMPROC_PTR) + + this.EnumWindows(enumWindowsCallback, 0) + this.koffi.unregister(enumWindowsCallback) + + if (!requested) return true + return await this.waitForWeChatExit(timeoutMs) + } + + private async killWeChatProcesses(): Promise { + const gracefulOk = await this.closeWeChatWindows(8000) + if (gracefulOk) return true + try { - await execFileAsync('taskkill', ['/F', '/IM', 'Weixin.exe']) - await execFileAsync('taskkill', ['/F', '/IM', 'WeChat.exe']) + await execFileAsync('taskkill', ['/F', '/T', '/IM', 'Weixin.exe']) + await execFileAsync('taskkill', ['/F', '/T', '/IM', 'WeChat.exe']) } catch (e) { // Ignore if not found } - await new Promise(r => setTimeout(r, 1000)) + + return await this.waitForWeChatExit(5000) } // --- Window Detection --- @@ -605,15 +649,24 @@ export class KeyService { } // 2. Restart WeChat - onStatus?.('正在重启微信以进行获取...', 0) - await this.killWeChatProcesses() + onStatus?.('正在关闭微信以进行获取...', 0) + const closed = await this.killWeChatProcesses() + if (!closed) { + const err = '无法自动关闭微信,请手动退出后重试' + onStatus?.(err, 2) + return { success: false, error: err } + } - // 3. Launch +// 3. Launch onStatus?.('正在启动微信...', 0) - const sub = spawn(wechatPath, { detached: true, stdio: 'ignore' }) + const sub = spawn(wechatPath, { + detached: true, + stdio: 'ignore', + cwd: dirname(wechatPath) + }) sub.unref() - // 4. Wait for Window & Get PID (Crucial change: discover PID from window) +// 4. Wait for Window & Get PID (Crucial change: discover PID from window) onStatus?.('等待微信界面就绪...', 0) const pid = await this.waitForWeChatWindow() if (!pid) {