Skip to content

Commit 7ba8c6d

Browse files
committed
feat: electron supporting apis for auto update in linux
1 parent 54ab29a commit 7ba8c6d

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

src-electron/main.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ function getSrcNodePath() {
7878
}
7979

8080
// In-memory key-value store shared across all windows (mirrors Tauri's put_item/get_all_items)
81-
// Used for multi-window storage synchronization
81+
// Used for multi-window storage synchronization - ONLY for use by storage.js
8282
const sharedStorageMap = new Map();
8383

84+
// Update scheduled flag - shared across all windows for app updater
85+
let updateScheduled = false;
86+
8487
// Hidden metrics window for Google Analytics
8588
let metricsWindow = null;
8689

@@ -248,20 +251,15 @@ ipcMain.handle('get-executable-path', (event) => {
248251
return process.execPath;
249252
});
250253

251-
// Run a shell command for update script execution
252-
ipcMain.handle('run-shell-command', async (event, command) => {
254+
// Update scheduled state - shared across windows for multi-window update persistence
255+
ipcMain.handle('set-update-scheduled', (event, scheduled) => {
253256
assertTrusted(event);
254-
const { exec } = require('child_process');
255-
return new Promise((resolve) => {
256-
exec(command, { shell: '/bin/bash' }, (error, stdout, stderr) => {
257-
if (error) {
258-
console.error('Shell command error:', error);
259-
resolve({ code: error.code || 1, stdout, stderr });
260-
} else {
261-
resolve({ code: 0, stdout, stderr });
262-
}
263-
});
264-
});
257+
updateScheduled = scheduled;
258+
});
259+
260+
ipcMain.handle('get-update-scheduled', (event) => {
261+
assertTrusted(event);
262+
return updateScheduled;
265263
});
266264

267265
// Handle quit request from renderer

src-electron/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
"electron": "^40.0.0",
2323
"electron-builder": "^24.13.3"
2424
}
25-
}
25+
}

src-electron/preload.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
7979
// Set zoom factor on the webview (mirrors Tauri's zoom_window)
8080
zoomWindow: (scaleFactor) => ipcRenderer.invoke('zoom-window', scaleFactor),
8181

82-
// In-memory storage for multi-window sync (mirrors Tauri's put_item/get_all_items)
82+
/**
83+
* In-memory storage for multi-window sync (mirrors Tauri's put_item/get_all_items)
84+
* WARNING: These APIs are ONLY for use by storage.js - do not use elsewhere
85+
*/
8386
putItem: (key, value) => ipcRenderer.invoke('put-item', key, value),
8487
getAllItems: () => ipcRenderer.invoke('get-all-items'),
8588

@@ -166,5 +169,6 @@ contextBridge.exposeInMainWorld('electronAPI', {
166169
getAppVersion: () => ipcRenderer.invoke('get-app-version'),
167170
isPackaged: () => ipcRenderer.invoke('is-packaged'),
168171
getExecutablePath: () => ipcRenderer.invoke('get-executable-path'),
169-
runShellCommand: (command) => ipcRenderer.invoke('run-shell-command', command)
172+
setUpdateScheduled: (scheduled) => ipcRenderer.invoke('set-update-scheduled', scheduled),
173+
getUpdateScheduled: () => ipcRenderer.invoke('get-update-scheduled')
170174
});

0 commit comments

Comments
 (0)