Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
fix: settings failures can't block launch, desync the theme, or wipe the file
Anmol Kapila669eb3c33f8
diff --git a/src/main/index.ts b/src/main/index.tsindex 20bb718..52e1b2a 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -97,7 +97,10 @@ app.whenReady().then(async () => {// Applied before the window is created so the initial background/icon already match —// the saved preference otherwise only takes effect on the next 'updated' event.- await migrateLegacyNetworkPreferences()+ // A failed move keeps the old file, to retry next launch — it must never stop the window opening.+ await migrateLegacyNetworkPreferences().catch((error) =>+ console.error('[plexo] failed to migrate network-preferences.json', error)+ )nativeTheme.themeSource = await loadThemeSource()app.on('browser-window-created', (_, window) => {diff --git a/src/main/ipc/handlers.ts b/src/main/ipc/handlers.tsindex 515e970..16fc6d7 100644--- a/src/main/ipc/handlers.ts+++ b/src/main/ipc/handlers.ts@@ -85,11 +85,12 @@ export function registerIpcHandlers(getWindow: () => BrowserWindow | null): DownnativeTheme.themeSource === 'dark' ? 'dark' : 'light'handle('updateSettings', async (_event, patch) => {- const saved = await saveSettings(patch)- // The one setting main also applies — sanitized first, so only 'light'/'dark' reach it.- if (patch?.themeSource !== undefined && saved.themeSource) {- nativeTheme.themeSource = saved.themeSource+ // The one setting main also applies — before saving, so a failed write still switches the+ // window to the theme the toggle now shows.+ if (patch?.themeSource === 'light' || patch?.themeSource === 'dark') {+ nativeTheme.themeSource = patch.themeSource}+ await saveSettings(patch)})// Answered via sendSync from the preload, which blocks the page until returnValue is set — so adiff --git a/src/main/jsonFile.ts b/src/main/jsonFile.tsindex adf5c26..7ab6e34 100644--- a/src/main/jsonFile.ts+++ b/src/main/jsonFile.ts@@ -1,11 +1,15 @@import { readFile, rename, writeFile } from 'node:fs/promises'-/** Parsed contents, or undefined when the file is missing (first run) or unreadable/corrupt. */+/** Parsed contents, or undefined when the file is missing (first run) or corrupt. Any other+ * failure (a lock, too many open files) throws, so a save never overwrites what it couldn't read. */export async function readJson(path: string): Promise<unknown> {try {return JSON.parse(await readFile(path, 'utf-8'))- } catch {- return undefined+ } catch (error) {+ if (error instanceof SyntaxError || (error as NodeJS.ErrnoException).code === 'ENOENT') {+ return undefined+ }+ throw error}}diff --git a/src/main/settings.ts b/src/main/settings.tsindex 8442fc1..ec4f3ef 100644--- a/src/main/settings.ts+++ b/src/main/settings.ts@@ -62,7 +62,8 @@ function sanitizeSettings(parsed: unknown): AppSettings {}export async function loadSettings(): Promise<AppSettings> {- return sanitizeSettings(await readJson(settingsPath()))+ // Reading can fall back to defaults; only a save must not act on a failed read.+ return sanitizeSettings(await readJson(settingsPath()).catch(() => undefined))}/** Merges `patch` over what's saved and returns the result as written. */