From a068c74307674a2e92872b602232b693c53e317d Mon Sep 17 00:00:00 2001 From: Memory <134070804+Memory2314@users.noreply.github.com> Date: Sat, 28 Mar 2026 00:22:05 +0800 Subject: [PATCH] feat: detect PowerShell version synchronously before Electron init using mshta --- src/main/index.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/index.ts b/src/main/index.ts index 20f31f2..1d19dd2 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,5 +1,30 @@ +import { execSync } from 'child_process' import { electronApp, optimizer } from '@electron-toolkit/utils' import { app, dialog } from 'electron' + +if (process.platform === 'win32') { + try { + const stdout = execSync('powershell -NoProfile -Command "$PSVersionTable.PSVersion.Major"', { + encoding: 'utf8', + timeout: 5000 + }) + const major = parseInt(stdout.trim(), 10) + if (!isNaN(major) && major < 5) { + const isZh = Intl.DateTimeFormat().resolvedOptions().locale?.startsWith('zh') + const title = isZh ? '需要更新 PowerShell' : 'PowerShell Update Required' + const message = isZh + ? `检测到您的 PowerShell 版本为 ${major}.x,部分功能需要 PowerShell 5.1 才能正常运行。\\n\\n请访问 Microsoft 官网下载并安装 Windows Management Framework 5.1。` + : `Detected PowerShell version ${major}.x. Some features require PowerShell 5.1.\\n\\nPlease install Windows Management Framework 5.1 from the Microsoft website.` + execSync( + `mshta "javascript:var sh=new ActiveXObject('WScript.Shell');sh.Popup('${message}',0,'${title}',48);close()"`, + { timeout: 60000 } + ) + process.exit(0) + } + } catch { + // ignore + } +} import i18next from 'i18next' import { initI18n } from '../shared/i18n' import { registerIpcMainHandlers } from './utils/ipc'