Skip to content

Commit f744539

Browse files
committed
feat: 将安装过程中的消息本地化为中文,增强用户体验
1 parent 22795e1 commit f744539

File tree

1 file changed

+75
-30
lines changed

1 file changed

+75
-30
lines changed

src/webviews/settings_env.ts

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function installLinuxEnv(webview: vscode.Webview) {
5252
webview.postMessage({
5353
command: 'installProgress',
5454
type: 'error',
55-
message: 'Env already installed at ' + envPath
55+
message: 'Env 已安装在 ' + envPath
5656
});
5757
return;
5858
}
@@ -107,7 +107,7 @@ async function installLinuxEnv(webview: vscode.Webview) {
107107
webview.postMessage({
108108
command: 'installProgress',
109109
type: 'error',
110-
message: `Installation failed: ${error}`
110+
message: `安装失败: ${error}`
111111
});
112112
}
113113
}
@@ -120,7 +120,7 @@ async function installWindowsEnv(webview: vscode.Webview) {
120120
webview.postMessage({
121121
command: 'installProgress',
122122
type: 'error',
123-
message: 'Env already installed at ' + envPath
123+
message: 'Env 已安装在 ' + envPath
124124
});
125125
return;
126126
}
@@ -134,48 +134,90 @@ async function installWindowsEnv(webview: vscode.Webview) {
134134
const scriptPath = path.join(os.tmpdir(), 'install_windows.ps1');
135135

136136
try {
137+
// Show info message
137138
webview.postMessage({
138-
command: 'installProgress',
139-
type: 'info',
140-
message: '正在下载安装脚本...'
139+
command: 'installProgress',
140+
type: 'info',
141+
message: '开始安装 RT-Thread Env...'
141142
});
142-
await executeCommand(`wget "${installScriptUrl}" -O "${scriptPath}"`, webview);
143143

144-
webview.postMessage({
144+
try {
145+
// Step 1: Download installation script
146+
webview.postMessage({
145147
command: 'installProgress',
146148
type: 'info',
147-
message: '设置 PowerShell 执行策略...'
148-
});
149-
await executeCommand(`powershell -Command "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force"`, webview);
149+
message: '步骤 1: 正在下载安装脚本...'
150+
});
151+
await executeCommand(
152+
`powershell -Command wget "${installScriptUrl}" -O install_windows.ps1`,
153+
webview
154+
);
150155

151-
webview.postMessage({
156+
// Step 2: Set execution policy
157+
webview.postMessage({
152158
command: 'installProgress',
153159
type: 'info',
154-
message: `正在执行安装脚本${giteeArg ? '(--gitee)' : ''}...`
155-
});
156-
await executeCommand(`powershell -ExecutionPolicy RemoteSigned -File "${scriptPath}"${giteeArg}`, webview);
160+
message: '步骤 2: 正在设置执行策略...'
161+
});
162+
await executeCommand(
163+
'powershell -Command Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force',
164+
webview
165+
);
157166

158-
webview.postMessage({
167+
// Step 3: Run installation script
168+
webview.postMessage({
159169
command: 'installProgress',
160170
type: 'info',
161-
message: '清理安装脚本...'
162-
});
163-
await executeCommand(`del "${scriptPath}"`, webview);
171+
message: '步骤 3: 正在运行安装脚本(自动模式)...'
172+
});
173+
await executeCommand(
174+
`powershell -Command .\\install_windows.ps1 ${giteeArg} -y`,
175+
webview
176+
);
164177

165-
webview.postMessage({
178+
// Step 4: Activate virtual environment
179+
webview.postMessage({
166180
command: 'installProgress',
167-
type: 'success',
168-
message: 'RT-Thread Env 安装成功!'
169-
});
181+
type: 'info',
182+
message: '步骤 4: 正在激活虚拟环境...'
183+
});
184+
await executeCommand(
185+
`powershell -Command ~\\.env\\env.ps1`,
186+
webview
187+
);
188+
189+
// Step 5: Clean up installation script
190+
webview.postMessage({
191+
command: 'installProgress',
192+
type: 'info',
193+
message: '步骤 5: 正在清理安装脚本...'
194+
});
195+
await executeCommand(`powershell -Command del .\\install_windows.ps1`, webview);
196+
197+
webview.postMessage({
198+
command: 'installProgress',
199+
type: 'success',
200+
message: 'RT-Thread Env 安装成功完成!'
201+
});
202+
203+
} catch (error) {
204+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
205+
// vscode.window.showErrorMessage(`RT-Thread Env installation failed: ${errorMessage}`);
206+
207+
webview.postMessage({
208+
command: 'installProgress',
209+
type: 'error',
210+
message: `RT-Thread Env 安装失败: ${errorMessage}`
211+
});
212+
}
170213

171214
const envStatus = await checkEnvStatus();
172215
webview.postMessage({ command: 'envStatus', status: envStatus });
173-
174216
} catch (error) {
175217
webview.postMessage({
176218
command: 'installProgress',
177219
type: 'error',
178-
message: `Installation failed: ${error}`
220+
message: `安装失败: ${error}`
179221
});
180222
}
181223
}
@@ -244,22 +286,25 @@ function executeCommand(command: string, webview: vscode.Webview, cwd?: string):
244286
const cmd = parts[0];
245287
const args = parts.slice(1);
246288
const proc = spawn(cmd, args, { shell: true, cwd });
247-
proc.stdout.on('data', (data) => {
289+
290+
webview.postMessage({ command: 'installProgress', type: 'info', message: command });
291+
proc.stdout.on('data', (data: Buffer) => {
248292
webview.postMessage({ command: 'installProgress', type: 'info', message: data.toString() });
249293
});
250-
proc.stderr.on('data', (data) => {
251-
webview.postMessage({ command: 'installProgress', type: 'warning', message: data.toString() });
294+
proc.stderr.on('data', (data: Buffer) => {
295+
const msg = data.toString();
296+
webview.postMessage({ command: 'installProgress', type: 'warning', message: msg });
252297
});
253298
proc.on('close', (code) => {
254299
if (code === 0) {
255300
resolve();
256301
} else {
257-
webview.postMessage({ command: 'installProgress', type: 'error', message: `Command exited with code ${code}` });
302+
webview.postMessage({ command: 'installProgress', type: 'error', message: `命令执行失败,退出代码 ${code}` });
258303
reject(new Error(`Command exited with code ${code}`));
259304
}
260305
});
261306
proc.on('error', (err) => {
262-
webview.postMessage({ command: 'installProgress', type: 'error', message: `Command failed: ${err.message}` });
307+
webview.postMessage({ command: 'installProgress', type: 'error', message: `命令执行失败: ${err.message}` });
263308
reject(err);
264309
});
265310
});

0 commit comments

Comments
 (0)