send-to-pi 1.1.0 → 1.3.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 +57 -105
- package/README_CN.md +57 -108
- package/chrome-extension/background.js +275 -56
- package/chrome-extension/manifest.json +10 -1
- package/chrome-extension/options.html +8 -2
- package/chrome-extension/options.js +22 -11
- package/chrome-extension/popup.html +160 -0
- package/chrome-extension/popup.js +145 -0
- package/package.json +3 -2
- package/pi-extension/README.md +9 -16
- package/pi-extension/index.ts +334 -37
- package/server/bin/send-to-pi.js +97 -42
- package/server/src/clipboard.js +53 -0
- package/server/src/config.js +107 -10
- package/server/src/index.js +190 -46
- package/server/src/launchers/custom.js +55 -0
- package/server/src/launchers/darwin.js +289 -45
- package/server/src/launchers/index.js +51 -8
- package/server/src/launchers/linux.js +60 -36
- package/server/src/launchers/win32.js +110 -43
|
@@ -1,68 +1,135 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Windows Terminal Launcher for send-to-pi
|
|
2
|
+
* Windows Adaptive Terminal Launcher for send-to-pi
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Resolution order:
|
|
5
|
+
* 1. Explicit preference (PI_TERMINAL / config.json) or last-terminal.json
|
|
6
|
+
* 2. Windows Terminal (wt.exe)
|
|
7
|
+
* 3. PowerShell (pwsh.exe / powershell.exe)
|
|
8
|
+
* 4. Command Prompt (cmd.exe)
|
|
9
|
+
* Also supports WezTerm, Alacritty, and Tern when configured or detected.
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
12
|
const { spawn } = require('child_process');
|
|
13
|
+
const fs = require('fs');
|
|
11
14
|
|
|
12
|
-
function
|
|
15
|
+
function spawnAndCheck(cmd, args) {
|
|
13
16
|
return new Promise((resolve) => {
|
|
14
|
-
// 1. 尝试 Windows Terminal (wt.exe)
|
|
15
17
|
try {
|
|
16
|
-
const
|
|
17
|
-
const child = spawn('wt.exe', wtArgs, {
|
|
18
|
+
const child = spawn(cmd, args, {
|
|
18
19
|
detached: true,
|
|
19
20
|
stdio: 'ignore',
|
|
20
21
|
});
|
|
21
|
-
|
|
22
|
-
child.on('error', (
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
let failed = false;
|
|
23
|
+
child.on('error', () => {
|
|
24
|
+
failed = true;
|
|
25
|
+
resolve(false);
|
|
25
26
|
});
|
|
26
|
-
|
|
27
27
|
child.unref();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
if (!failed) resolve(true);
|
|
30
|
+
}, 280);
|
|
31
|
+
} catch (_err) {
|
|
32
|
+
resolve(false);
|
|
32
33
|
}
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const child = spawn('powershell.exe', psArgs, {
|
|
40
|
-
detached: true,
|
|
41
|
-
stdio: 'ignore',
|
|
42
|
-
});
|
|
37
|
+
function escapePsSingle(str) {
|
|
38
|
+
return String(str).replace(/'/g, "''");
|
|
39
|
+
}
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
const ADAPTERS = {
|
|
42
|
+
wt: {
|
|
43
|
+
label: 'Windows Terminal',
|
|
44
|
+
launch: (workDir) =>
|
|
45
|
+
spawnAndCheck('wt.exe', ['-d', workDir, 'powershell', '-NoExit', '-Command', 'pi']),
|
|
46
|
+
},
|
|
47
|
+
wezterm: {
|
|
48
|
+
label: 'WezTerm',
|
|
49
|
+
launch: (workDir) =>
|
|
50
|
+
spawnAndCheck('wezterm-gui.exe', ['start', '--cwd', workDir, 'pi']),
|
|
51
|
+
},
|
|
52
|
+
alacritty: {
|
|
53
|
+
label: 'Alacritty',
|
|
54
|
+
launch: (workDir) =>
|
|
55
|
+
spawnAndCheck('alacritty.exe', [
|
|
56
|
+
'--working-directory',
|
|
57
|
+
workDir,
|
|
58
|
+
'-e',
|
|
59
|
+
'powershell',
|
|
60
|
+
'-NoExit',
|
|
61
|
+
'-Command',
|
|
62
|
+
'pi',
|
|
63
|
+
]),
|
|
64
|
+
},
|
|
65
|
+
tern: {
|
|
66
|
+
label: 'Tern',
|
|
67
|
+
launch: (workDir) => {
|
|
68
|
+
const ternPath = process.env.TERN_PATH || 'D:\\Tern\\tern.exe';
|
|
69
|
+
if (!fs.existsSync(ternPath)) return Promise.resolve(false);
|
|
70
|
+
return spawnAndCheck(ternPath, [
|
|
71
|
+
'-e',
|
|
72
|
+
'powershell',
|
|
73
|
+
'-NoExit',
|
|
74
|
+
'-Command',
|
|
75
|
+
`Set-Location '${escapePsSingle(workDir)}'; pi`,
|
|
76
|
+
]);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
pwsh: {
|
|
80
|
+
label: 'PowerShell 7',
|
|
81
|
+
launch: (workDir) =>
|
|
82
|
+
spawnAndCheck('pwsh.exe', [
|
|
83
|
+
'-NoExit',
|
|
84
|
+
'-Command',
|
|
85
|
+
`Set-Location '${escapePsSingle(workDir)}'; pi`,
|
|
86
|
+
]),
|
|
87
|
+
},
|
|
88
|
+
powershell: {
|
|
89
|
+
label: 'PowerShell',
|
|
90
|
+
launch: (workDir) =>
|
|
91
|
+
spawnAndCheck('powershell.exe', [
|
|
92
|
+
'-NoExit',
|
|
93
|
+
'-Command',
|
|
94
|
+
`Set-Location '${escapePsSingle(workDir)}'; pi`,
|
|
95
|
+
]),
|
|
96
|
+
},
|
|
97
|
+
cmd: {
|
|
98
|
+
label: 'cmd.exe',
|
|
99
|
+
launch: (workDir) =>
|
|
100
|
+
spawnAndCheck('cmd.exe', ['/k', `cd /d "${workDir}" && pi`]),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
47
103
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
104
|
+
function normalizeKey(name) {
|
|
105
|
+
const k = (name || '').trim().toLowerCase();
|
|
106
|
+
if (!k) return '';
|
|
107
|
+
if (k === 'windows-terminal' || k === 'windowsterminal') return 'wt';
|
|
108
|
+
return ADAPTERS[k] ? k : '';
|
|
53
109
|
}
|
|
54
110
|
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
111
|
+
async function launchWin32(workDir, options = {}) {
|
|
112
|
+
const preferred = normalizeKey(options.preferredTerminal || process.env.PI_TERMINAL);
|
|
113
|
+
const lastKey = normalizeKey(options.lastTerminal && options.lastTerminal.terminal);
|
|
114
|
+
const defaultOrder = ['wt', 'pwsh', 'powershell', 'cmd'];
|
|
115
|
+
|
|
116
|
+
const ordered = [];
|
|
117
|
+
const pushUnique = (k) => {
|
|
118
|
+
if (k && ADAPTERS[k] && !ordered.includes(k)) ordered.push(k);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
pushUnique(preferred);
|
|
122
|
+
pushUnique(lastKey);
|
|
123
|
+
for (const k of defaultOrder) pushUnique(k);
|
|
124
|
+
|
|
125
|
+
for (const key of ordered) {
|
|
126
|
+
const ok = await ADAPTERS[key].launch(workDir);
|
|
127
|
+
if (ok) {
|
|
128
|
+
return { success: true, terminal: ADAPTERS[key].label, key };
|
|
129
|
+
}
|
|
65
130
|
}
|
|
131
|
+
|
|
132
|
+
return { success: false, error: 'Failed to launch any supported Windows terminal.' };
|
|
66
133
|
}
|
|
67
134
|
|
|
68
135
|
module.exports = launchWin32;
|