send-to-pi 1.0.2 → 1.2.0
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.
- package/README.md +32 -12
- package/README_CN.md +40 -18
- package/chrome-extension/background.js +409 -30
- package/chrome-extension/manifest.json +13 -2
- package/package.json +1 -1
- package/pi-extension/README.md +4 -3
- package/pi-extension/index.ts +225 -59
- package/server/src/config.js +17 -1
- package/server/src/index.js +186 -42
- package/server/src/launchers/win32.js +39 -18
|
@@ -2,35 +2,56 @@
|
|
|
2
2
|
* Windows Terminal Launcher for send-to-pi
|
|
3
3
|
*
|
|
4
4
|
* Supports:
|
|
5
|
-
* -
|
|
5
|
+
* - Tern Terminal (D:\Tern\tern.exe)
|
|
6
|
+
* - Windows Terminal (wt.exe fallback)
|
|
6
7
|
* - PowerShell (powershell.exe fallback)
|
|
7
8
|
* - Command Prompt (cmd.exe fallback)
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
const { spawn } = require('child_process');
|
|
12
|
+
const fs = require('fs');
|
|
11
13
|
|
|
12
14
|
function launchWin32(workDir) {
|
|
13
15
|
return new Promise((resolve) => {
|
|
14
|
-
// 1.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
// 1. 优先尝试 Tern Terminal (主力终端)
|
|
17
|
+
const ternPath = 'D:\\Tern\\tern.exe';
|
|
18
|
+
if (fs.existsSync(ternPath)) {
|
|
19
|
+
try {
|
|
20
|
+
const ternArgs = ['-e', 'powershell', '-NoExit', '-Command', `Set-Location '${workDir}'; pi`];
|
|
21
|
+
const child = spawn(ternPath, ternArgs, {
|
|
22
|
+
detached: true,
|
|
23
|
+
stdio: 'ignore',
|
|
24
|
+
});
|
|
25
|
+
child.on('error', () => fallbackWT(workDir, resolve));
|
|
26
|
+
child.unref();
|
|
27
|
+
setTimeout(() => resolve({ success: true, terminal: 'Tern' }), 300);
|
|
28
|
+
return;
|
|
29
|
+
} catch (_e) {
|
|
30
|
+
// continue
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
fallbackWT(workDir, resolve);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
21
36
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
function fallbackWT(workDir, resolve) {
|
|
38
|
+
// 2. 回退尝试 Windows Terminal (wt.exe)
|
|
39
|
+
try {
|
|
40
|
+
const wtArgs = ['-d', workDir, 'powershell', '-NoExit', '-Command', 'pi'];
|
|
41
|
+
const child = spawn('wt.exe', wtArgs, {
|
|
42
|
+
detached: true,
|
|
43
|
+
stdio: 'ignore',
|
|
44
|
+
});
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
// 在 Windows 上若成功触发 spawn 且无即时报错即视为已拉起
|
|
29
|
-
setTimeout(() => resolve({ success: true, terminal: 'Windows Terminal' }), 300);
|
|
30
|
-
} catch (_e) {
|
|
46
|
+
child.on('error', (_err) => {
|
|
31
47
|
fallbackPowerShell(workDir, resolve);
|
|
32
|
-
}
|
|
33
|
-
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
child.unref();
|
|
51
|
+
setTimeout(() => resolve({ success: true, terminal: 'Windows Terminal' }), 300);
|
|
52
|
+
} catch (_e) {
|
|
53
|
+
fallbackPowerShell(workDir, resolve);
|
|
54
|
+
}
|
|
34
55
|
}
|
|
35
56
|
|
|
36
57
|
function fallbackPowerShell(workDir, resolve) {
|