add reset functionality in settings

This commit is contained in:
Danny Morabito 2025-04-03 20:32:20 +02:00
parent 1fa04fa4d9
commit ff01fc8503
Signed by: dannym
GPG key ID: 7CC8056A5A04557E
5 changed files with 49 additions and 14 deletions

View file

@ -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 { is, optimizer } from '@electron-toolkit/utils';
import { BrowserWindow, app, ipcMain, shell } from 'electron'; import { BrowserWindow, app, ipcMain, shell } from 'electron';
import fs from 'node:fs';
import path from 'node:path';
import { RelayManager } from './relayManager'; import { RelayManager } from './relayManager';
const relay = new RelayManager(); const relay = new RelayManager();
@ -10,16 +9,9 @@ const relay = new RelayManager();
ipcMain.handle('relay:writeSeed', async (_, ...args: string[]) => { ipcMain.handle('relay:writeSeed', async (_, ...args: string[]) => {
if (!args[0]) throw new Error('No seed provided'); if (!args[0]) throw new Error('No seed provided');
const seed = args[0] as string; const seed = args[0] as string;
let configPath: string; const configPath = relay.getRelayConfigPath();
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');
fs.mkdirSync(configPath, { recursive: true }); fs.mkdirSync(configPath, { recursive: true });
fs.writeFileSync(seedPath, seed); fs.writeFileSync(path.join(configPath, 'ccn.seed'), seed);
}); });
ipcMain.handle('relay:start', (_, ...args: string[]) => { ipcMain.handle('relay:start', (_, ...args: string[]) => {
@ -32,6 +24,10 @@ ipcMain.handle('relay:stop', () => {
return relay.stop(); return relay.stop();
}); });
ipcMain.handle('relay:reset', () => {
return relay.reset();
});
ipcMain.handle('relay:status', () => { ipcMain.handle('relay:status', () => {
return { return {
running: relay.isRunning, running: relay.isRunning,

View file

@ -10,6 +10,7 @@ if (process.contextIsolated) {
stop: () => ipcRenderer.invoke('relay:stop'), stop: () => ipcRenderer.invoke('relay:stop'),
getStatus: () => ipcRenderer.invoke('relay:status'), getStatus: () => ipcRenderer.invoke('relay:status'),
getLogs: () => ipcRenderer.invoke('relay:logs'), getLogs: () => ipcRenderer.invoke('relay:logs'),
reset: () => ipcRenderer.invoke('relay:reset'),
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);

View file

@ -1,6 +1,8 @@
import { type ChildProcess, spawn } from 'node:child_process';
import { join } from 'node:path';
import { is } from '@electron-toolkit/utils'; 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'; 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 { private handleProcessExit(code: number | null): void {
this.process = null; this.process = null;
console.log(`Relay exited with code ${code}`); console.log(`Relay exited with code ${code}`);
@ -241,4 +253,14 @@ export class RelayManager {
public getLogs(): string[] { public getLogs(): string[] {
return [...this.relayLogs]; 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 });
}
} }

View file

@ -10,6 +10,7 @@ interface RelayBridge {
stop: () => Promise<void>; stop: () => Promise<void>;
getStatus: () => Promise<RelayStatus>; getStatus: () => Promise<RelayStatus>;
getLogs: () => Promise<string[]>; getLogs: () => Promise<string[]>;
reset: () => Promise<void>;
} }
declare global { declare global {

View file

@ -117,6 +117,12 @@ export class EveSettings extends LitElement {
document.body.classList.toggle('dark', this.darkMode); 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() { override render() {
if (this.error) return html`<arx-error-view .error=${this.error}></arx-error-view>`; if (this.error) return html`<arx-error-view .error=${this.error}></arx-error-view>`;
@ -196,6 +202,15 @@ export class EveSettings extends LitElement {
<arx-relay-logs .logs=${this.relayStatus.logs}></arx-relay-logs> <arx-relay-logs .logs=${this.relayStatus.logs}></arx-relay-logs>
</arx-fieldset> </arx-fieldset>
</arx-card> </arx-card>
<arx-card >
<arx-fieldset legend="Reset">
<p>
This will delete all the data stored on this device, and you will be sent back to the setup
screen.
</p>
<arx-button @click=${this.reset} label="Reset" variant="accent" fullWidth></arx-button>
</arx-fieldset>
</arx-card>
`; `;
} }
} }