cdp-saw 1.1.4 → 1.1.6
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/index.js +38 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -65,9 +65,45 @@ function selectBestKey(isHighCost) {
|
|
|
65
65
|
return bestKey;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
const readline = require('readline');
|
|
69
|
+
|
|
70
|
+
function logToFile(msg) {
|
|
71
|
+
const logPath = path.join(process.cwd(), 'cdp-debug.log');
|
|
72
|
+
fs.appendFileSync(logPath, `[${new Date().toISOString()}] ${msg}\n`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function pauseAndExit(msg) {
|
|
76
|
+
console.error(msg);
|
|
77
|
+
logToFile('CRITICAL ERROR: ' + msg);
|
|
78
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
79
|
+
rl.question('\n❌ Error occurred. Press ENTER to close...', () => {
|
|
80
|
+
rl.close();
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function findTestpadPath() {
|
|
86
|
+
const commonPaths = [
|
|
87
|
+
process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'Programs', 'testpad', 'testpad.exe') : null,
|
|
88
|
+
process.env.ProgramFiles ? path.join(process.env.ProgramFiles, 'testpad', 'testpad.exe') : null,
|
|
89
|
+
process.env['ProgramFiles(x86)'] ? path.join(process.env['ProgramFiles(x86)'], 'testpad', 'testpad.exe') : null,
|
|
90
|
+
'C:\\Program Files\\testpad\\testpad.exe',
|
|
91
|
+
'C:\\Program Files (x86)\\testpad\\testpad.exe',
|
|
92
|
+
path.join(process.env.USERPROFILE || '', 'AppData', 'Local', 'Programs', 'testpad', 'testpad.exe')
|
|
93
|
+
];
|
|
94
|
+
for (const p of commonPaths) {
|
|
95
|
+
if (p && fs.existsSync(p)) return p;
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const TESTPAD_PATH = findTestpadPath();
|
|
101
|
+
if (!TESTPAD_PATH) {
|
|
102
|
+
pauseAndExit('[cdp] ❌ ERROR: testpad.exe not found! Please make sure Testpad is installed.');
|
|
103
|
+
}
|
|
104
|
+
|
|
68
105
|
function launchBrowser() {
|
|
69
|
-
const
|
|
70
|
-
const p = path.join(userProfile, "AppData\\Local\\Programs\\testpad\\testpad.exe");
|
|
106
|
+
const p = TESTPAD_PATH;
|
|
71
107
|
if (fs.existsSync(p)) {
|
|
72
108
|
console.log(`[cdp] 🚀 Launching: ${p}`);
|
|
73
109
|
cleanupProcesses();
|