chore(frontend): introduce prettier + eslint and prune unused code
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports) - Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier - Add root scripts: format, format:check, lint, lint:fix - Reformat 257 files across admin-web, ops-web, desktop-client, packages - Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters - Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex - Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,66 +1,66 @@
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { app } from "electron/main";
|
||||
import { app } from 'electron/main'
|
||||
|
||||
export interface DesktopAppSettings {
|
||||
openAtLogin: boolean;
|
||||
keepRunningInBackground: boolean;
|
||||
openAtLogin: boolean
|
||||
keepRunningInBackground: boolean
|
||||
}
|
||||
|
||||
export type DesktopAppSettingKey = keyof DesktopAppSettings;
|
||||
export type DesktopAppSettingKey = keyof DesktopAppSettings
|
||||
|
||||
const DEFAULT_DESKTOP_APP_SETTINGS: DesktopAppSettings = {
|
||||
openAtLogin: false,
|
||||
keepRunningInBackground: true,
|
||||
};
|
||||
}
|
||||
|
||||
let cachedSettings: DesktopAppSettings = { ...DEFAULT_DESKTOP_APP_SETTINGS };
|
||||
let cachedSettings: DesktopAppSettings = { ...DEFAULT_DESKTOP_APP_SETTINGS }
|
||||
|
||||
function settingsPath(): string {
|
||||
return join(app.getPath("userData"), "desktop-settings.json");
|
||||
return join(app.getPath('userData'), 'desktop-settings.json')
|
||||
}
|
||||
|
||||
function normalizeSettings(input: unknown): DesktopAppSettings {
|
||||
if (!input || typeof input !== "object") {
|
||||
return { ...DEFAULT_DESKTOP_APP_SETTINGS };
|
||||
if (!input || typeof input !== 'object') {
|
||||
return { ...DEFAULT_DESKTOP_APP_SETTINGS }
|
||||
}
|
||||
|
||||
const candidate = input as Partial<Record<DesktopAppSettingKey, unknown>>;
|
||||
const candidate = input as Partial<Record<DesktopAppSettingKey, unknown>>
|
||||
return {
|
||||
openAtLogin:
|
||||
typeof candidate.openAtLogin === "boolean"
|
||||
typeof candidate.openAtLogin === 'boolean'
|
||||
? candidate.openAtLogin
|
||||
: DEFAULT_DESKTOP_APP_SETTINGS.openAtLogin,
|
||||
keepRunningInBackground:
|
||||
typeof candidate.keepRunningInBackground === "boolean"
|
||||
typeof candidate.keepRunningInBackground === 'boolean'
|
||||
? candidate.keepRunningInBackground
|
||||
: DEFAULT_DESKTOP_APP_SETTINGS.keepRunningInBackground,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function readPersistedSettings(): DesktopAppSettings {
|
||||
try {
|
||||
return normalizeSettings(JSON.parse(readFileSync(settingsPath(), "utf8")));
|
||||
return normalizeSettings(JSON.parse(readFileSync(settingsPath(), 'utf8')))
|
||||
} catch {
|
||||
return { ...DEFAULT_DESKTOP_APP_SETTINGS };
|
||||
return { ...DEFAULT_DESKTOP_APP_SETTINGS }
|
||||
}
|
||||
}
|
||||
|
||||
function persistSettings(settings: DesktopAppSettings): void {
|
||||
try {
|
||||
writeFileSync(settingsPath(), JSON.stringify(settings), "utf8");
|
||||
writeFileSync(settingsPath(), JSON.stringify(settings), 'utf8')
|
||||
} catch (error) {
|
||||
console.warn("[desktop-settings] persist failed", error);
|
||||
console.warn('[desktop-settings] persist failed', error)
|
||||
}
|
||||
}
|
||||
|
||||
function readSystemOpenAtLogin(fallback: boolean): boolean {
|
||||
try {
|
||||
return app.getLoginItemSettings().openAtLogin;
|
||||
return app.getLoginItemSettings().openAtLogin
|
||||
} catch (error) {
|
||||
console.warn("[desktop-settings] read login item failed", error);
|
||||
return fallback;
|
||||
console.warn('[desktop-settings] read login item failed', error)
|
||||
return fallback
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,30 +69,30 @@ function applyOpenAtLogin(openAtLogin: boolean): boolean {
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin,
|
||||
openAsHidden: false,
|
||||
});
|
||||
return readSystemOpenAtLogin(openAtLogin);
|
||||
})
|
||||
return readSystemOpenAtLogin(openAtLogin)
|
||||
} catch (error) {
|
||||
console.warn("[desktop-settings] apply login item failed", error);
|
||||
return openAtLogin;
|
||||
console.warn('[desktop-settings] apply login item failed', error)
|
||||
return openAtLogin
|
||||
}
|
||||
}
|
||||
|
||||
export function initDesktopAppSettings(): DesktopAppSettings {
|
||||
cachedSettings = readPersistedSettings();
|
||||
cachedSettings = readPersistedSettings()
|
||||
cachedSettings = {
|
||||
...cachedSettings,
|
||||
openAtLogin: applyOpenAtLogin(cachedSettings.openAtLogin),
|
||||
};
|
||||
persistSettings(cachedSettings);
|
||||
return getDesktopAppSettings();
|
||||
}
|
||||
persistSettings(cachedSettings)
|
||||
return getDesktopAppSettings()
|
||||
}
|
||||
|
||||
export function getDesktopAppSettings(): DesktopAppSettings {
|
||||
cachedSettings = {
|
||||
...cachedSettings,
|
||||
openAtLogin: readSystemOpenAtLogin(cachedSettings.openAtLogin),
|
||||
};
|
||||
return { ...cachedSettings };
|
||||
}
|
||||
return { ...cachedSettings }
|
||||
}
|
||||
|
||||
export function setDesktopAppSetting(
|
||||
@@ -102,13 +102,13 @@ export function setDesktopAppSetting(
|
||||
const next: DesktopAppSettings = {
|
||||
...cachedSettings,
|
||||
[key]: value,
|
||||
};
|
||||
|
||||
if (key === "openAtLogin") {
|
||||
next.openAtLogin = applyOpenAtLogin(value);
|
||||
}
|
||||
|
||||
cachedSettings = next;
|
||||
persistSettings(cachedSettings);
|
||||
return getDesktopAppSettings();
|
||||
if (key === 'openAtLogin') {
|
||||
next.openAtLogin = applyOpenAtLogin(value)
|
||||
}
|
||||
|
||||
cachedSettings = next
|
||||
persistSettings(cachedSettings)
|
||||
return getDesktopAppSettings()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user