fix: save goosehints in the UI (#1983)

This commit is contained in:
Yingjie He
2025-04-01 12:59:31 -07:00
committed by GitHub
parent efabdbd397
commit 052e96cb69

View File

@@ -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.