Skip to content

Commit c0b390e

Browse files
committed
feat: Implement auto-update and custom protocol handling, and simplify build artifact names.
1 parent 23aa1a1 commit c0b390e

4 files changed

Lines changed: 149 additions & 24 deletions

File tree

electron-builder.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"package.json"
1212
],
1313
"mac": {
14+
"identity": null,
1415
"category": "public.app-category.productivity",
15-
"artifactName": "${productName}-${version}-mac-${arch}.${ext}",
16+
"artifactName": "${productName}-mac-${arch}.${ext}",
1617
"target": [
1718
{
1819
"target": "dmg",
@@ -32,7 +33,7 @@
3233
]
3334
},
3435
"win": {
35-
"artifactName": "${productName}-${version}-win-${arch}.${ext}",
36+
"artifactName": "${productName}-win-${arch}.${ext}",
3637
"target": [
3738
{
3839
"target": "nsis",
@@ -52,7 +53,7 @@
5253
]
5354
},
5455
"linux": {
55-
"artifactName": "${productName}-${version}-linux-${arch}.${ext}",
56+
"artifactName": "${productName}-linux-${arch}.${ext}",
5657
"target": [
5758
{
5859
"target": "AppImage",

electron/main.cjs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1-
const { app, BrowserWindow, ipcMain, shell, dialog, clipboard, Menu } = require('electron');
2-
const path = require('path');
3-
const fs = require('fs').promises;
4-
const fsSync = require('fs');
1+
```javascript
2+
const { app, BrowserWindow, ipcMain, shell, dialog, clipboard, Menu, protocol, session } = require('electron');
3+
const path = require('node:path');
4+
const fs = require('node:fs');
55
const { fork } = require('child_process');
6+
const { autoUpdater } = require('electron-updater');
7+
8+
// Configure autoUpdater
9+
autoUpdater.autoDownload = true;
10+
autoUpdater.autoInstallOnAppQuit = true;
11+
12+
// Basic logging
13+
autoUpdater.logger = require('electron-log');
14+
autoUpdater.logger.transports.file.level = 'info';
15+
16+
const DIST = path.join(__dirname, '../dist');
17+
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'];
18+
19+
// Protocol handling (Redstring)
20+
if (process.defaultApp) {
21+
if (process.argv.length >= 2) {
22+
app.setAsDefaultProtocolClient('redstring', process.execPath, [path.resolve(process.argv[1])]);
23+
}
24+
} else {
25+
app.setAsDefaultProtocolClient('redstring');
26+
}
627
728
// Set app name for proper display in menu bar/dock
829
app.setName('Redstring');
@@ -40,11 +61,11 @@ function startAgentServer() {
4061
});
4162
4263
agentServerProcess.stdout.on('data', (data) => {
43-
console.log(`[AgentServer] ${data.toString().trim()}`);
64+
console.log(`[AgentServer] ${ data.toString().trim() } `);
4465
});
4566
4667
agentServerProcess.stderr.on('data', (data) => {
47-
console.error(`[AgentServer] ${data.toString().trim()}`);
68+
console.error(`[AgentServer] ${ data.toString().trim() } `);
4869
});
4970
5071
agentServerProcess.on('error', (error) => {
@@ -53,7 +74,7 @@ function startAgentServer() {
5374
});
5475
5576
agentServerProcess.on('exit', (code, signal) => {
56-
console.log(`[Electron] Agent server exited with code ${code}, signal ${signal}`);
77+
console.log(`[Electron] Agent server exited with code ${ code }, signal ${ signal } `);
5778
agentServerProcess = null;
5879
});
5980
}
@@ -80,7 +101,7 @@ if (isTestMode) {
80101
const sessionArg = process.argv.find(arg => arg.startsWith('--session='));
81102
const sessionName = sessionArg ? sessionArg.split('=')[1] : null;
82103
if (sessionName) {
83-
console.log(`[Electron] Starting with isolated session: ${sessionName}`);
104+
console.log(`[Electron] Starting with isolated session: ${ sessionName } `);
84105
}
85106
86107
let mainWindow = null;
@@ -116,7 +137,7 @@ const ensureDirectories = async () => {
116137
117138
// Storage file paths
118139
const getStoragePath = (storeName) => {
119-
return path.join(getRedstringDataPath(), `${storeName}.json`);
140+
return path.join(getRedstringDataPath(), `${ storeName }.json`);
120141
};
121142
122143
// Read storage file
@@ -129,7 +150,7 @@ const readStorage = async (storeName) => {
129150
if (error.code === 'ENOENT') {
130151
return {}; // File doesn't exist yet
131152
}
132-
console.error(`[Electron] Failed to read storage ${storeName}:`, error);
153+
console.error(`[Electron] Failed to read storage ${ storeName }: `, error);
133154
return {};
134155
}
135156
};
@@ -141,7 +162,7 @@ const writeStorage = async (storeName, data) => {
141162
await fs.writeFile(filePath, JSON.stringify(data, null, 2), 'utf-8');
142163
return true;
143164
} catch (error) {
144-
console.error(`[Electron] Failed to write storage ${storeName}:`, error);
165+
console.error(`[Electron] Failed to write storage ${ storeName }: `, error);
145166
return false;
146167
}
147168
};
@@ -179,7 +200,7 @@ function createWindow() {
179200
let devUrl = 'http://localhost:4001';
180201
const params = [];
181202
if (isTestMode) params.push('test=true');
182-
if (sessionName) params.push(`session=${encodeURIComponent(sessionName)}`);
203+
if (sessionName) params.push(`session = ${ encodeURIComponent(sessionName) } `);
183204
184205
if (params.length > 0) {
185206
devUrl += '?' + params.join('&');
@@ -363,7 +384,7 @@ ipcMain.handle('file:read', async (event, filePath) => {
363384
const content = await fs.readFile(filePath, 'utf-8');
364385
return { content, path: filePath };
365386
} catch (error) {
366-
throw new Error(`Failed to read file: ${error.message}`);
387+
throw new Error(`Failed to read file: ${ error.message } `);
367388
}
368389
});
369390
@@ -372,7 +393,7 @@ ipcMain.handle('file:write', async (event, filePath, content) => {
372393
await fs.writeFile(filePath, content, 'utf-8');
373394
return { success: true, path: filePath };
374395
} catch (error) {
375-
throw new Error(`Failed to write file: ${error.message}`);
396+
throw new Error(`Failed to write file: ${ error.message } `);
376397
}
377398
});
378399

package-lock.json

Lines changed: 107 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
"@types/uuid": "^10.0.0",
7878
"cors": "^2.8.5",
7979
"dotenv": "^17.2.1",
80+
"electron-log": "^5.4.3",
81+
"electron-updater": "^6.7.3",
8082
"express": "^4.21.2",
8183
"framer-motion": "^11.5.4",
8284
"immer": "^10.1.1",
@@ -122,4 +124,4 @@
122124
"vitest": "^3.1.1",
123125
"wait-on": "^9.0.3"
124126
}
125-
}
127+
}

0 commit comments

Comments
 (0)