cc4-embedded-system 3.1.3 → 3.1.4
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/dist/gui.js +60 -19
- package/package.json +1 -1
package/dist/gui.js
CHANGED
|
@@ -64,7 +64,7 @@ import path from 'node:path';
|
|
|
64
64
|
import { fileURLToPath } from 'node:url';
|
|
65
65
|
import { runMakeFsData } from './makefsdata.js';
|
|
66
66
|
import { getPackageVersion } from './utils.js';
|
|
67
|
-
import {
|
|
67
|
+
import { execFile } from 'node:child_process';
|
|
68
68
|
import os from 'node:os';
|
|
69
69
|
// prevent socket errors
|
|
70
70
|
process.on('uncaughtException', (err) => {
|
|
@@ -98,6 +98,29 @@ const cancelShutdown = () => {
|
|
|
98
98
|
// console.log('🛡️ Shutdown cancelled (keep alive)');
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
|
+
const buildPowerShellArgs = (script) => {
|
|
102
|
+
const encodedCommand = Buffer.from(script, 'utf16le').toString('base64');
|
|
103
|
+
return [
|
|
104
|
+
'-NoProfile',
|
|
105
|
+
'-STA',
|
|
106
|
+
'-EncodedCommand',
|
|
107
|
+
encodedCommand
|
|
108
|
+
];
|
|
109
|
+
};
|
|
110
|
+
const runDialogCommand = (command, args) => {
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
execFile(command, args, {
|
|
113
|
+
windowsHide: false,
|
|
114
|
+
maxBuffer: 1024 * 1024
|
|
115
|
+
}, (error, stdout, stderr) => {
|
|
116
|
+
if (error) {
|
|
117
|
+
reject(new Error(stderr.trim() || error.message));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
resolve(stdout.trim());
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
101
124
|
app.get('/api/version', (_req, res) => {
|
|
102
125
|
cancelShutdown();
|
|
103
126
|
res.json({ version: getPackageVersion() });
|
|
@@ -173,30 +196,48 @@ app.post('/api/change-port', (req, res) => {
|
|
|
173
196
|
}
|
|
174
197
|
}, 100);
|
|
175
198
|
});
|
|
176
|
-
app.get('/api/browse', (req, res) => {
|
|
199
|
+
app.get('/api/browse', async (req, res) => {
|
|
200
|
+
cancelShutdown();
|
|
177
201
|
const isDir = req.query.type === 'dir';
|
|
178
202
|
const platform = os.platform();
|
|
179
|
-
let command = '';
|
|
180
203
|
try {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
204
|
+
let result = '';
|
|
205
|
+
if (platform === 'win32') {
|
|
206
|
+
const script = isDir
|
|
207
|
+
? [
|
|
208
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
209
|
+
'$dialog = New-Object System.Windows.Forms.FolderBrowserDialog',
|
|
210
|
+
'$dialog.Description = "Select Input Directory"',
|
|
211
|
+
'if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {',
|
|
212
|
+
' $dialog.SelectedPath',
|
|
213
|
+
'}'
|
|
214
|
+
].join('\n')
|
|
215
|
+
: [
|
|
216
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
217
|
+
'$dialog = New-Object System.Windows.Forms.SaveFileDialog',
|
|
218
|
+
'$dialog.Filter = "C Files (*.c)|*.c|All Files (*.*)|*.*"',
|
|
219
|
+
'$dialog.DefaultExt = "c"',
|
|
220
|
+
'$dialog.AddExtension = $true',
|
|
221
|
+
'$dialog.OverwritePrompt = $true',
|
|
222
|
+
'if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {',
|
|
223
|
+
' $dialog.FileName',
|
|
224
|
+
'}'
|
|
225
|
+
].join('\n');
|
|
226
|
+
result = await runDialogCommand('powershell.exe', buildPowerShellArgs(script));
|
|
186
227
|
}
|
|
187
|
-
else if (platform === 'darwin') {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
228
|
+
else if (platform === 'darwin') {
|
|
229
|
+
result = await runDialogCommand('osascript', [
|
|
230
|
+
'-e',
|
|
231
|
+
isDir
|
|
232
|
+
? 'POSIX path of (choose folder with prompt "Select Input Directory")'
|
|
233
|
+
: 'POSIX path of (choose file name with prompt "Select Output File")'
|
|
234
|
+
]);
|
|
192
235
|
}
|
|
193
|
-
else {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
command = `zenity --file-selection --title="Select Output File"`;
|
|
236
|
+
else {
|
|
237
|
+
result = await runDialogCommand('zenity', isDir
|
|
238
|
+
? ['--file-selection', '--directory', '--title=Select Input Directory']
|
|
239
|
+
: ['--file-selection', '--save', '--confirm-overwrite', '--title=Select Output File', '--filename=fsdata.c']);
|
|
198
240
|
}
|
|
199
|
-
const result = execSync(command).toString().trim();
|
|
200
241
|
res.json({ success: true, path: result || null });
|
|
201
242
|
}
|
|
202
243
|
catch (e) {
|