refactor(desktop): extract instance-URL helpers to instanceUrl.ts
Pure mechanical extraction — no behavior change. Enables recovery.ts to share these helpers without a circular import on main.ts.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { app } from 'electron';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
export function getInstanceUrlPath(): string {
|
||||
return path.join(app.getPath('userData'), 'instance-url.json');
|
||||
}
|
||||
|
||||
export function loadInstanceUrl(): string | null {
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(getInstanceUrlPath(), 'utf-8'));
|
||||
return typeof data.url === 'string' ? data.url : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveInstanceUrl(url: string): void {
|
||||
fs.writeFileSync(getInstanceUrlPath(), JSON.stringify({ url }));
|
||||
}
|
||||
|
||||
export function clearInstanceUrl(): void {
|
||||
try {
|
||||
fs.unlinkSync(getInstanceUrlPath());
|
||||
} catch {
|
||||
// File may not exist — ignore
|
||||
}
|
||||
}
|
||||
|
||||
export function getPickerPath(): string {
|
||||
return path.join(__dirname, '..', 'resources', 'instance-picker.html');
|
||||
}
|
||||
@@ -17,6 +17,12 @@ import os from 'os';
|
||||
import { startActivityDetection, stopActivityDetection, getCurrentActivity } from './activityDetector';
|
||||
import { KeybindManager } from './keybindManager';
|
||||
import { deriveStartMinimizedFromArgs, parseExecPathFromDesktopFile, shouldReapplyAppImage } from './autoLaunch';
|
||||
import {
|
||||
loadInstanceUrl,
|
||||
saveInstanceUrl,
|
||||
clearInstanceUrl,
|
||||
getPickerPath,
|
||||
} from './instanceUrl';
|
||||
|
||||
let mainWindow: BrowserWindow | null = null;
|
||||
const keybindManager = new KeybindManager();
|
||||
@@ -26,37 +32,6 @@ let pendingDeepLink: string | null = null;
|
||||
|
||||
const knownInstanceOrigins = new Set<string>();
|
||||
|
||||
// ─── Instance URL Persistence ────────────────────────────────────────────────
|
||||
|
||||
function getInstanceUrlPath(): string {
|
||||
return path.join(app.getPath('userData'), 'instance-url.json');
|
||||
}
|
||||
|
||||
function loadInstanceUrl(): string | null {
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(getInstanceUrlPath(), 'utf-8'));
|
||||
return typeof data.url === 'string' ? data.url : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function saveInstanceUrl(url: string): void {
|
||||
fs.writeFileSync(getInstanceUrlPath(), JSON.stringify({ url }));
|
||||
}
|
||||
|
||||
function clearInstanceUrl(): void {
|
||||
try {
|
||||
fs.unlinkSync(getInstanceUrlPath());
|
||||
} catch {
|
||||
// File may not exist — ignore
|
||||
}
|
||||
}
|
||||
|
||||
function getPickerPath(): string {
|
||||
return path.join(__dirname, '..', 'resources', 'instance-picker.html');
|
||||
}
|
||||
|
||||
// ─── Window State Persistence ───────────────────────────────────────────────
|
||||
|
||||
interface WindowState {
|
||||
|
||||
Reference in New Issue
Block a user