完成启动项目功能、排查一些灵异问题

This commit is contained in:
2026-03-29 00:26:49 +08:00
parent cabb2f65da
commit 6002ac1418
17 changed files with 222 additions and 78 deletions

View File

@@ -2,7 +2,8 @@ import type {
checkIDEResultDto,
checkIDEsResultDto,
checkIDEsVersionDto,
checkIDEVersionDto
checkIDEVersionDto,
IDECode
} from '@my-type/settings'
import { execSync } from 'node:child_process'
import { BrowserWindow, screen, shell, Tray } from 'electron'
@@ -31,11 +32,7 @@ const JETBRAINS_TOOLBOX_STATE_JSON_PATH = path.join(
* @param command IDE 的命令行别名,例如 `code`。
* @param code JetBrains IDE的产品代号对于其他 IDE 为空字符串
*/
function checkIDE(
display: string,
command: string,
code: JetBrainsProductCode | '' = ''
): checkIDEResultDto | null {
function checkIDE(display: string, command: string, code: IDECode): checkIDEResultDto | null {
try {
const paths = execSync(`where.exe ${command}`).toString().split('\n').slice(0, -1)
return { code, display: display, command: command, paths: paths }
@@ -45,7 +42,7 @@ function checkIDE(
}
/**
* 检查 JerBrains IDEs 是否安装可用。
* 检查 JetBrains IDEs 是否安装可用。
*/
async function checkJetBrainsIDEs(): Promise<checkIDEsResultDto> {
// 构建数据结构的辅助函数
@@ -58,11 +55,11 @@ async function checkJetBrainsIDEs(): Promise<checkIDEsResultDto> {
}
}
const result: checkIDEsResultDto = {
pycharm: _('pycharm', 'PY'),
clion: _('clion', 'CL'),
webstorm: _('webstorm', 'WS'),
phpstorm: _('phpstorm', 'PS'),
idea: _('idea', 'IU')
PY: _('pycharm', 'PY'),
CL: _('clion', 'CL'),
WS: _('webstorm', 'WS'),
PS: _('phpstorm', 'PS'),
IU: _('idea', 'IU')
}
// 优先从 JBTState.json 查找
if (settingsManager._settings?.codeLaunchpadIDESearchPolicy.includes('JBTState.json')) {
@@ -115,7 +112,7 @@ export async function getIDEs(): Promise<checkIDEsResultDto> {
export async function checkIDEs(): Promise<checkIDEsResultDto> {
console.log('在系统中查找已安装的 IDE ...')
const vscodeIDEs = {
vscode: checkIDE('Visual Studio Code', 'code')
VSC: checkIDE('Visual Studio Code', 'code', 'VSC')
}
global.installedIDEs = { ...vscodeIDEs, ...(await checkJetBrainsIDEs()) }
return global.installedIDEs
@@ -135,7 +132,7 @@ async function checkVSCodeVersion(): Promise<checkIDEVersionDto> {
console.error('获取 VSCode 版本列表时出现错误。错误提供如下。')
console.error(error)
}
return { code: '', install, latest, display: 'Visual Studio Code' }
return { code: 'VSC', install, latest, display: 'Visual Studio Code' }
}
/**
@@ -152,11 +149,11 @@ export async function checkJetBrainsIDEsVersion(): Promise<checkIDEsVersionDto>
}
}
const result: checkIDEsVersionDto = {
pycharm: _('pycharm', 'PY'),
clion: _('clion', 'CL'),
webstorm: _('webstorm', 'WS'),
phpstorm: _('phpstorm', 'PS'),
idea: _('idea', 'IU')
PY: _('pycharm', 'PY'),
CL: _('clion', 'CL'),
WS: _('webstorm', 'WS'),
PS: _('phpstorm', 'PS'),
IU: _('idea', 'IU')
}
// 尝试从 JBTState.json 获取已安装的 JetBrains IDEs 的版本
@@ -227,8 +224,8 @@ export async function checkIDEsVersion(): Promise<checkIDEsVersionDto> {
let result: checkIDEsVersionDto = {}
for (const ide in await getIDEs()) {
switch (ide) {
case 'vscode':
result['vscode'] = await checkVSCodeVersion()
case 'VSC':
result['VSC'] = await checkVSCodeVersion()
break
}
}