diff --git a/ui/desktop/src/main.ts b/ui/desktop/src/main.ts index 813b8ad2..d7fe9849 100644 --- a/ui/desktop/src/main.ts +++ b/ui/desktop/src/main.ts @@ -426,6 +426,41 @@ ipcMain.handle('get-binary-path', (event, binaryName) => { return getBinaryPath(app, binaryName); }); +ipcMain.handle('read-file', (event, filePath) => { + return new Promise((resolve) => { + exec(`cat ${filePath}`, (error, stdout, stderr) => { + if (error) { + // File not found + resolve({ file: '', filePath, error: null, found: false }); + } + if (stderr) { + console.error('Error output:', stderr); + resolve({ file: '', filePath, error, found: false }); + } + resolve({ file: stdout, filePath, error: null, found: true }); + }); + }); +}); + +ipcMain.handle('write-file', (event, filePath, content) => { + return new Promise((resolve) => { + const command = `cat << 'EOT' > ${filePath} +${content} +EOT`; + exec(command, (error, stdout, stderr) => { + if (error) { + console.error('Error writing to file:', error); + resolve(false); + } + if (stderr) { + console.error('Error output:', stderr); + resolve(false); + } + resolve(true); + }); + }); +}); + app.whenReady().then(async () => { session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => { details.requestHeaders['Origin'] = 'http://localhost:5173'; @@ -647,41 +682,6 @@ app.whenReady().then(async () => { spawn('xdg-open', [url]); } }); - - ipcMain.handle('read-file', (event, filePath) => { - return new Promise((resolve) => { - exec(`cat ${filePath}`, (error, stdout, stderr) => { - if (error) { - // File not found - resolve({ file: '', filePath, error: null, found: false }); - } - if (stderr) { - console.error('Error output:', stderr); - resolve({ file: '', filePath, error, found: false }); - } - resolve({ file: stdout, filePath, error: null, found: true }); - }); - }); - }); - - ipcMain.handle('write-file', (event, filePath, content) => { - return new Promise((resolve) => { - const command = `cat << 'EOT' > ${filePath} -${content} -EOT`; - exec(command, (error, stdout, stderr) => { - if (error) { - console.error('Error writing to file:', error); - resolve(false); - } - if (stderr) { - console.error('Error output:', stderr); - resolve(false); - } - resolve(true); - }); - }); - }); }); // Quit when all windows are closed, except on macOS.