peer-term 1.3.3 → 1.3.5
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/package.json +1 -1
- package/src/index.js +36 -6
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -26,7 +26,7 @@ import crypto from 'crypto';
|
|
|
26
26
|
import path from 'path';
|
|
27
27
|
import net from 'net';
|
|
28
28
|
import readline from 'readline';
|
|
29
|
-
import {
|
|
29
|
+
import { execFile, spawn } from 'child_process';
|
|
30
30
|
import { fileURLToPath } from 'url';
|
|
31
31
|
import WebSocket from 'ws';
|
|
32
32
|
import pty from 'node-pty';
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
decrypt,
|
|
42
42
|
} from './crypto.js';
|
|
43
43
|
import { HostWebRTC } from './webrtc.js';
|
|
44
|
-
import logger
|
|
44
|
+
import logger from './logger.js';
|
|
45
45
|
import { printBanner, printSessionBox, printHelp, printVersion } from './ui.js';
|
|
46
46
|
|
|
47
47
|
// ─── File paths ──────────────────────────────────────────────────────────────
|
|
@@ -1151,14 +1151,44 @@ class Session {
|
|
|
1151
1151
|
|
|
1152
1152
|
const viewerScript = path.join(__dirname, 'session-viewer.js');
|
|
1153
1153
|
const platform = os.platform();
|
|
1154
|
+
const portStr = String(port);
|
|
1155
|
+
const nodeArgs = [viewerScript, portStr, this.code, token];
|
|
1154
1156
|
|
|
1155
1157
|
if (platform === 'win32') {
|
|
1156
|
-
|
|
1158
|
+
// spawn with 'cmd' to open a new window; arguments are passed as an
|
|
1159
|
+
// array so the install path is never interpreted by the shell.
|
|
1160
|
+
spawn('cmd', ['/c', 'start', `PeerTerm - ${this.code}`, 'cmd', '/c', 'node', ...nodeArgs], {
|
|
1161
|
+
stdio: 'ignore',
|
|
1162
|
+
detached: true,
|
|
1163
|
+
windowsHide: false,
|
|
1164
|
+
}).unref();
|
|
1157
1165
|
} else if (platform === 'darwin') {
|
|
1158
|
-
|
|
1166
|
+
// osascript receives the AppleScript source as a single -e argument;
|
|
1167
|
+
// node args are baked into the script string, but execFile does NOT
|
|
1168
|
+
// invoke a shell so the outer path cannot break out.
|
|
1169
|
+
const script = `tell app "Terminal" to do script "node '${viewerScript.replace(/'/g, "'\\''")}' ${portStr} ${this.code} ${token}"`;
|
|
1170
|
+
execFile('osascript', ['-e', script], { stdio: 'ignore' }, () => {});
|
|
1159
1171
|
} else {
|
|
1160
|
-
// Linux: try common terminal emulators
|
|
1161
|
-
|
|
1172
|
+
// Linux: try common terminal emulators in order, falling through on
|
|
1173
|
+
// failure. Each call uses execFile (no shell), so paths with
|
|
1174
|
+
// metacharacters are safe.
|
|
1175
|
+
const tryTerminals = [
|
|
1176
|
+
['x-terminal-emulator', ['-e', 'node', ...nodeArgs]],
|
|
1177
|
+
['gnome-terminal', ['--', 'node', ...nodeArgs]],
|
|
1178
|
+
['xterm', ['-e', 'node', ...nodeArgs]],
|
|
1179
|
+
];
|
|
1180
|
+
|
|
1181
|
+
const tryNext = (index) => {
|
|
1182
|
+
if (index >= tryTerminals.length) {
|
|
1183
|
+
this.log('Could not open any terminal emulator for viewer.');
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
const [cmd, args] = tryTerminals[index];
|
|
1187
|
+
execFile(cmd, args, { stdio: 'ignore' }, (err) => {
|
|
1188
|
+
if (err) tryNext(index + 1);
|
|
1189
|
+
});
|
|
1190
|
+
};
|
|
1191
|
+
tryNext(0);
|
|
1162
1192
|
}
|
|
1163
1193
|
this.log('Opening terminal viewer...');
|
|
1164
1194
|
}
|