add reset functionality in settings
This commit is contained in:
parent
1fa04fa4d9
commit
ff01fc8503
5 changed files with 49 additions and 14 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
|
1
src/relayManager.d.ts
vendored
1
src/relayManager.d.ts
vendored
|
@ -10,6 +10,7 @@ interface RelayBridge {
|
|||
stop: () => Promise<void>;
|
||||
getStatus: () => Promise<RelayStatus>;
|
||||
getLogs: () => Promise<string[]>;
|
||||
reset: () => Promise<void>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
|
|
@ -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`<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-fieldset>
|
||||
</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>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue