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');
55const { 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
829app.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) {
80101const sessionArg = process.argv.find(arg => arg.startsWith('--session='));
81102const sessionName = sessionArg ? sessionArg.split('=')[1] : null;
82103if (sessionName) {
83- console . log ( `[Electron] Starting with isolated session: ${ sessionName } ` ) ;
104+ console.log(` [ Electron ] Starting with isolated session : ${ sessionName } `);
84105}
85106
86107let mainWindow = null;
@@ -116,7 +137,7 @@ const ensureDirectories = async () => {
116137
117138// Storage file paths
118139const 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
0 commit comments