diff --git a/src/electron/main.ts b/src/electron/main.ts index fd1a856..c2eb3d8 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -1,8 +1,7 @@ -import fs from 'node:fs'; -import os from 'node:os'; -import path from 'node:path'; import { is, optimizer } from '@electron-toolkit/utils'; import { BrowserWindow, app, ipcMain, shell } from 'electron'; +import fs from 'node:fs'; +import path from 'node:path'; import { RelayManager } from './relayManager'; const relay = new RelayManager(); @@ -10,16 +9,9 @@ const relay = new RelayManager(); ipcMain.handle('relay:writeSeed', async (_, ...args: string[]) => { if (!args[0]) throw new Error('No seed provided'); const seed = args[0] as string; - let configPath: string; - if (process.platform === 'darwin') { - configPath = path.join(app.getPath('userData'), 'arx', 'Eve'); - } else { - configPath = path.join(os.homedir(), '.config', 'arx', 'Eve'); - } - - const seedPath = path.join(configPath, 'ccn.seed'); + const configPath = relay.getRelayConfigPath(); fs.mkdirSync(configPath, { recursive: true }); - fs.writeFileSync(seedPath, seed); + fs.writeFileSync(path.join(configPath, 'ccn.seed'), seed); }); ipcMain.handle('relay:start', (_, ...args: string[]) => { @@ -32,6 +24,10 @@ ipcMain.handle('relay:stop', () => { return relay.stop(); }); +ipcMain.handle('relay:reset', () => { + return relay.reset(); +}); + ipcMain.handle('relay:status', () => { return { running: relay.isRunning, diff --git a/src/electron/preload.ts b/src/electron/preload.ts index 475f6a7..7382cfe 100644 --- a/src/electron/preload.ts +++ b/src/electron/preload.ts @@ -10,6 +10,7 @@ if (process.contextIsolated) { stop: () => ipcRenderer.invoke('relay:stop'), getStatus: () => ipcRenderer.invoke('relay:status'), getLogs: () => ipcRenderer.invoke('relay:logs'), + reset: () => ipcRenderer.invoke('relay:reset'), }); } catch (error) { console.error(error); diff --git a/src/electron/relayManager.ts b/src/electron/relayManager.ts index 4b5bf46..5be64b9 100644 --- a/src/electron/relayManager.ts +++ b/src/electron/relayManager.ts @@ -1,6 +1,8 @@ -import { type ChildProcess, spawn } from 'node:child_process'; -import { join } from 'node:path'; import { is } from '@electron-toolkit/utils'; +import { app } from 'electron'; +import { type ChildProcess, spawn } from 'node:child_process'; +import { existsSync, rmdirSync } from 'node:fs'; +import { join } from 'node:path'; type PackageEnvironment = 'flatpak' | 'appimage' | 'system' | 'mac' | 'dev'; @@ -77,6 +79,16 @@ export class RelayManager { } } + public getRelayConfigPath(): string { + const environment = this.detectEnvironment(); + const xdgConfigHome = process.env.XDG_CONFIG_HOME ?? join(app.getPath('home'), '.config'); + const isLinux = environment in ['dev', 'system', 'appimage', 'flatpak']; + const configPath = isLinux + ? join(xdgConfigHome, 'arx', 'Eve') + : join(app.getPath('home'), 'Library', 'Application Support', 'eve', 'arx', 'Eve'); + return configPath; + } + private handleProcessExit(code: number | null): void { this.process = null; console.log(`Relay exited with code ${code}`); @@ -241,4 +253,14 @@ export class RelayManager { public getLogs(): string[] { return [...this.relayLogs]; } + + public reset(): void { + this.stop(); + this.process = null; + this.relayLogs = []; + this.restartAttempts = 0; + this.restartTimeout = null; + const configPath = this.getRelayConfigPath(); + if (existsSync(configPath)) rmdirSync(configPath, { recursive: true }); + } } diff --git a/src/relayManager.d.ts b/src/relayManager.d.ts index c16961d..d9937df 100644 --- a/src/relayManager.d.ts +++ b/src/relayManager.d.ts @@ -10,6 +10,7 @@ interface RelayBridge { stop: () => Promise; getStatus: () => Promise; getLogs: () => Promise; + reset: () => Promise; } declare global { diff --git a/src/routes/Settings.ts b/src/routes/Settings.ts index 32edf75..ab245d3 100644 --- a/src/routes/Settings.ts +++ b/src/routes/Settings.ts @@ -117,6 +117,12 @@ export class EveSettings extends LitElement { document.body.classList.toggle('dark', this.darkMode); } + private reset() { + if (!confirm('Are you sure you want to reset the app?')) return; + localStorage.clear(); + window.location.reload(); + } + override render() { if (this.error) return html``; @@ -196,6 +202,15 @@ export class EveSettings extends LitElement { + + +

+ This will delete all the data stored on this device, and you will be sent back to the setup + screen. +

+ +
+
`; } }