Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
feat: Usenet settings in Speed & data limits, with an on/off switch (#229)
dxmoc 🐛211136de0114
diff --git a/e2e/nzb.spec.ts b/e2e/nzb.spec.tsindex 2ee7883..8ff5392 100644--- a/e2e/nzb.spec.ts+++ b/e2e/nzb.spec.ts@@ -1,10 +1,11 @@import { createServer, type Server } from 'node:http'import { connect as netConnect, createServer as createTcpServer, type AddressInfo } from 'node:net'-import { mkdtemp, rm, writeFile } from 'node:fs/promises'+import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'import { join } from 'node:path'import type { NzbDownloadState, UsenetServerInput } from '../src/shared/types'-import { expect, LAN_ADDRESS, test, type PlexoApp } from './fixtures'+import type { Locator } from '@playwright/test'+import { expect, expectNzb, LAN_ADDRESS, test, type PlexoApp } from './fixtures'import { NewsServer, type NewsServerOptions } from './newsServer'import { seededBytes } from './origin'@@ -386,6 +387,180 @@ test.describe('NZB downloads', () => {})})+/** Speed & data limits, on its Usenet page. */+async function openUsenetPage(plexo: PlexoApp): Promise<Locator> {+ await plexo.page.getByRole('button', { name: /^\d+ networks?/ }).click()+ await plexo.page.getByRole('button', { name: 'Speed & data limits', exact: true }).click()+ const dialog = plexo.page.getByRole('dialog', { name: 'Speed & data limits' })+ await dialog.getByRole('button', { name: /^Usenet/ }).click()+ return dialog+}++/** An indexer answering every request with `server`'s NZB, as an NZB. */+async function indexerFor(server: NewsServer): Promise<{ link: string; close: () => void }> {+ const indexer: Server = createServer((_request, response) => {+ response.writeHead(200, {+ 'Content-Type': 'application/x-nzb',+ 'Content-Disposition': 'attachment; filename="Indexer.Release.nzb"'+ })+ response.end(server.nzb())+ })+ await new Promise<void>((resolve) => indexer.listen(0, '127.0.0.1', resolve))+ const { port } = indexer.address() as AddressInfo+ return { link: `http://127.0.0.1:${port}/api?t=get&id=1`, close: () => indexer.close() }+}++test.describe('Usenet settings', () => {+ test('the switch in Speed & data limits is saved with the server and kept on restart', async ({+ plexo+ }) => {+ const server = await newsServer()+ const file = join(plexo.dirs.userData, 'usenet-server.json')+ // Saved before there was a switch: on. Its password sealed by a keychain this session can't+ // open (another login's, say), so it reads as none.+ const password = Buffer.from('sealed elsewhere').toString('base64')+ await writeFile(+ file,+ JSON.stringify({ host: '127.0.0.1', port: server.port, tls: false, connections: 3, password })+ )+ await plexo.relaunch()+ expect((await plexo.api.usenetServer())?.enabled).toBe(true)++ let dialog = await openUsenetPage(plexo)+ await expect(dialog.getByText(`127.0.0.1:${server.port}`)).toBeVisible()+ await dialog.getByRole('switch', { name: 'Usenet downloads' }).click()+ // Nothing changes until Save.+ expect((await plexo.api.usenetServer())?.enabled).toBe(true)+ await dialog.getByRole('button', { name: 'Save', exact: true }).click()+ await expect(dialog).toBeHidden()+ expect(await plexo.api.usenetServer()).toMatchObject({ enabled: false, connections: 3 })+ // Kept for a session that can unseal it.+ expect(JSON.parse(await readFile(file, 'utf-8')).password).toBe(password)++ await plexo.relaunch()+ expect((await plexo.api.usenetServer())?.enabled).toBe(false)+ dialog = await openUsenetPage(plexo)+ await expect(dialog.getByRole('switch', { name: 'Usenet downloads' })).not.toBeChecked()+ // Saving the server from its own form leaves the switch as it is.+ await dialog.getByRole('button', { name: 'Change server' }).click()+ const form = plexo.page.getByRole('dialog', { name: 'Usenet server' })+ await form.getByLabel('Connections').fill('5')+ await form.getByRole('button', { name: 'Save' }).click()+ await expect(form).toBeHidden()+ expect(await plexo.api.usenetServer()).toMatchObject({ enabled: false, connections: 5 })+ // Its password field left blank, which can't show a password this session can't unseal.+ expect(JSON.parse(await readFile(file, 'utf-8')).password).toBe(password)+ })++ test('off, an NZB is no Usenet download, and a running one stops connecting and waits', async ({+ plexo+ }) => {+ const server = await newsServer({ delayMs: 40 })+ await useServer(plexo, server, { connections: 2 })+ const nzb = await nzbOnDisk(server)+ const id = await plexo.start(nzb, server.expectedSha())+ await plexo.waitUntil((state) => state.kind === 'nzb' && countDone(state) >= 2)++ await useServer(plexo, server, { connections: 2, enabled: false })+ await expect+ .poll(async () => (await plexo.byId(id))?.status, { timeout: 10_000 })+ .toBe('queued')+ await new Promise((resolve) => setTimeout(resolve, 200))+ const served = server.served.length+ // Paused and resumed while off, it fails before it connects.+ await plexo.api.pauseDownload(id)+ await plexo.api.resumeDownload(id)+ await expect.poll(async () => (await plexo.byId(id))?.status, { timeout: 10_000 }).toBe('error')+ expect((await plexo.byId(id))?.error).toMatch(/Usenet downloads are off/)+ expect(server.served.length).toBe(served)++ // An NZB file can't be downloaded; one by link is a plain file, for another newsreader.+ await expect(plexo.api.probeUrl(nzb)).rejects.toThrow(/Usenet downloads are off/)+ const indexer = await indexerFor(server)+ try {+ const probe = await plexo.api.probeUrl(indexer.link)+ expect(probe.kind).toBe('http')+ expect(probe.suggestedFileName).toBe('Indexer.Release.nzb')+ } finally {+ indexer.close()+ }++ // Back on, the download picks up where it stopped.+ await useServer(plexo, server, { connections: 2, enabled: true })+ await plexo.api.resumeDownload(id)+ await plexo.waitForNzbStatus('completed', 30_000)+ })++ test('off, running and queued NZBs wait rather than fail, and start once it’s back on', async ({+ plexo+ }) => {+ await plexo.api.updateSettings({ downloadsAtOnce: 1 })+ const server = await newsServer({ delayMs: 40 })+ await useServer(plexo, server, { connections: 2 })+ const running = await plexo.start(+ await nzbOnDisk(server, 'First.Release.nzb'),+ server.expectedSha()+ )+ await plexo.waitUntil((state) => state.id === running && countDone(expectNzb(state)) >= 2)+ const queued = await plexo.start(+ await nzbOnDisk(server, 'Second.Release.nzb'),+ server.expectedSha()+ )+ expect((await plexo.byId(queued))?.status).toBe('queued')++ await useServer(plexo, server, { connections: 2, enabled: false })+ // The running one goes back in the queue, which makes room (see pause): the queued one still+ // waits.+ await expect+ .poll(async () => (await plexo.byId(running))?.status, { timeout: 10_000 })+ .toBe('queued')+ await new Promise((resolve) => setTimeout(resolve, 200))+ const waiting = expectNzb((await plexo.byId(queued))!)+ expect(waiting.status).toBe('queued')+ expect(countDone(waiting)).toBe(0)+ expect(waiting.streams).toHaveLength(0)+ expect((await plexo.byId(running))?.status).toBe('queued')++ // Back on, both start without being asked.+ await useServer(plexo, server, { connections: 2, enabled: true })+ for (const id of [running, queued]) {+ await expect+ .poll(async () => (await plexo.byId(id))?.status, { timeout: 30_000 })+ .toBe('completed')+ }+ })++ test('the news server is set up from Speed & data limits', async ({ plexo }) => {+ const server = await newsServer()+ const dialog = await openUsenetPage(plexo)+ await expect(dialog.getByText('No news server set up')).toBeVisible()+ await expect(dialog.getByRole('switch', { name: 'Usenet downloads' })).toBeDisabled()+ await dialog.getByRole('button', { name: 'Set up server' }).click()++ const form = plexo.page.getByRole('dialog', { name: 'Usenet server' })+ await form.getByLabel('Server').fill('127.0.0.1')+ await form.getByRole('switch').click()+ await form.getByLabel('Port').fill(String(server.port))+ await form.getByLabel('Connections').fill('2')+ await form.getByRole('button', { name: 'Save' }).click()+ await expect(form).toBeHidden()++ await expect(dialog.getByText(`127.0.0.1:${server.port}`)).toBeVisible()+ await expect(dialog.getByRole('switch', { name: 'Usenet downloads' })).toBeChecked()+ // Saved already: the server's own Save is what counts, not Cancel here.+ await dialog.getByRole('button', { name: 'Cancel' }).click()+ expect(await plexo.api.usenetServer()).toMatchObject({+ enabled: true,+ host: '127.0.0.1',+ port: server.port,+ tls: false,+ connections: 2+ })+ await plexo.start(await nzbOnDisk(server), server.expectedSha())+ await plexo.waitForNzbStatus('completed', 30_000)+ })+})+function countDone(state: NzbDownloadState): number {return state.blocks.filter((block) => block.status === 'completed').length}diff --git a/src/main/download/downloadManager.ts b/src/main/download/downloadManager.tsindex d5ffbec..c3ee78b 100644--- a/src/main/download/downloadManager.ts+++ b/src/main/download/downloadManager.ts@@ -77,7 +77,7 @@ import {type ParsedNzb} from './nzb/nzbFile'import { NzbTransfer } from './nzb/nzbTransfer'-import { loadUsenetServer } from './nzb/usenetServer'+import { loadUsenetServer, USENET_OFF, usenetEnabled } from './nzb/usenetServer'import {clearSpeeds,delay,@@ -437,6 +437,8 @@ export class DownloadManager {private awakeBlocker: number | null = null/** How many downloads may run at once; the rest wait, queued (see pump). */private downloadsAtOnce = DOWNLOADS_AT_ONCE.default+ /** The Usenet switch, as last saved: while it's off, queued NZBs wait rather than start. */+ private usenetOn = true/** Speed and data limits, for every download together. */readonly limits = new Limits(() => this.limitsChanged())@@ -445,12 +447,14 @@ export class DownloadManager {private networks: NetworkMonitor,private readonly telegram: TelegramServiceApi) {- this.initialization = Promise.all([this.restorePersistedDownloads(), this.limits.loaded]).then(- async () => {- // Read after recovery, including any settings saved while the manifests were loading.- await this.configureSettings(await loadSettings())- }- )+ this.initialization = Promise.all([+ this.restorePersistedDownloads(),+ this.limits.loaded,+ usenetEnabled().then((on) => (this.usenetOn = on))+ ]).then(async () => {+ // Read after recovery, including any settings saved while the manifests were loading.+ await this.configureSettings(await loadSettings())+ })}/** Takes up what the user set: how many run at once, and the limits. One running past a@@ -613,6 +617,8 @@ export class DownloadManager {.sort((a, b) => (a.state.queuedAt ?? 0) - (b.state.queuedAt ?? 0))for (const runtime of queued) {if (this.runningCount() >= this.downloadsAtOnce) return+ // Each would only fail on the switch, making room for the next to fail too.+ if (runtime.kind === 'nzb' && !this.usenetOn) continuethis.begin(runtime)}}@@ -1323,6 +1329,7 @@ export class DownloadManager {if (!nzbFile) throw new Error('Add the NZB again to start downloading.')const server = await loadUsenetServer()if (!server) throw new Error('Set up a news server to download from Usenet.')+ if (!server.enabled) throw new Error(USENET_OFF)const nzb = parseNzb(nzbFile)const usable = compatibleInterfaces(selected,@@ -1745,6 +1752,24 @@ export class DownloadManager {}}+ /** The Usenet switch was saved. Off, the NZBs running stop rather than keep connecting and go+ * back in the queue, as the download schedule does, to wait with the queued ones (see pump); a+ * paused one resumed fails before it connects (see NzbTransfer.reconcile). On, the queue+ * starts. */+ usenetSwitched(on: boolean): void {+ this.usenetOn = on+ if (on) {+ this.pump()+ return+ }+ for (const runtime of this.runtimes.values()) {+ if (runtime.kind !== 'nzb') continue+ void this.pause(runtime.state.id, true).catch((error) =>+ console.error('[plexo] Usenet switched off', error)+ )+ }+ }+/** The computer woke from sleep. Its sockets are likely dead, though nothing will say so until* a stall watchdog runs out, and every judgement made by the clock (a silent network, a* crawling connection) spans the sleep. All of it starts over. */@@ -2215,7 +2240,10 @@ export class DownloadManager {runtime.state.status = 'error'runtime.state.error = messageruntime.state.resumable = !discard- this.notify('Download failed', `${runtime.state.fileName}: ${describeError(message)}`)+ // Switched off by the user, who needs no telling; the download's error still says so.+ if (message !== USENET_OFF) {+ this.notify('Download failed', `${runtime.state.fileName}: ${describeError(message)}`)+ }this.stopRun(runtime)}diff --git a/src/main/download/nzb/nzbTransfer.ts b/src/main/download/nzb/nzbTransfer.tsindex 972cdd0..be317d7 100644--- a/src/main/download/nzb/nzbTransfer.ts+++ b/src/main/download/nzb/nzbTransfer.ts@@ -22,7 +22,7 @@ import {} from '../transfer'import { ArticleMissingError, NntpAuthError, NntpConnection, NntpRefusedError } from './nntp'import type { NzbSegment } from './nzbFile'-import type { UsenetServerConfig } from './usenetServer'+import { USENET_OFF, type UsenetServerConfig } from './usenetServer'import { decodeYenc, YencError } from './yenc'// Set PLEXO_DEBUG=1 to log every article's outcome.@@ -120,6 +120,10 @@ export class NzbTransfer implements Transfer {this.host.failDownload('Set up a news server in Plexo to download from Usenet.')return}+ if (!server.enabled) {+ this.host.failDownload(USENET_OFF)+ return+ }this.server = serverthis.allowed = server.connectionsthis.host.reconcile()diff --git a/src/main/download/nzb/usenetServer.ts b/src/main/download/nzb/usenetServer.tsindex 8536309..e39deda 100644--- a/src/main/download/nzb/usenetServer.ts+++ b/src/main/download/nzb/usenetServer.ts@@ -12,6 +12,8 @@ export interface UsenetServerConfig extends Omit<UsenetServer, 'hasPassword' | 'export const MAX_CONNECTIONS = 100export const DEFAULT_CONNECTIONS = 8+export const USENET_OFF = 'Usenet downloads are off. Turn them on in Speed & data limits.'+function serverPath(): string {return join(app.getPath('userData'), 'usenet-server.json')}@@ -42,6 +44,8 @@ export function checkedServer(value: unknown): Omit<UsenetServerConfig, 'passworconst username = typeof value.username === 'string' ? value.username.trim() : ''if (/[\r\n]/.test(username)) return nullreturn {+ // Saved before there was a switch: on.+ enabled: value.enabled !== false,host: host.replace(/^\[|\]$/g, ''),port: Number.isInteger(port) && port > 0 && port < 65536 ? port : tls ? 563 : 119,tls,@@ -75,15 +79,26 @@ export function viewOf(server: UsenetServerConfig): UsenetServer {return { ...rest, hasPassword: password !== '', ...(!canSeal() && { passwordInMemory: true }) }}-/** The server as `input` sets it: the password it gives, or the one saved when it gives none. */+/** Whether NZBs download from Usenet: on until switched off, which takes a server set up. */+export async function usenetEnabled(): Promise<boolean> {+ // Only the switch: no password to unseal for it.+ return checkedServer(await readJson(serverPath()).catch(() => undefined))?.enabled !== false+}++/** The server as `input` sets it: the password and switch it gives, or the ones saved when it+ * gives none. */export async function serverFromInput(input: UsenetServerInput): Promise<UsenetServerConfig> {const server = checkedServer(input)if (!server) throw new Error('Enter the news server’s address')if (input.password !== undefined && /[\r\n]/.test(input.password)) {throw new Error('A password can’t span lines')}- const password = input.password ?? (await loadUsenetServer())?.password ?? ''- return { ...server, password }+ const saved = await loadUsenetServer()+ return {+ ...server,+ enabled: input.enabled === undefined ? (saved?.enabled ?? true) : server.enabled,+ password: input.password ?? saved?.password ?? ''+ }}export async function saveUsenetServer(input: UsenetServerInput): Promise<UsenetServer> {@@ -98,6 +113,12 @@ export async function saveUsenetServer(input: UsenetServerInput): Promise<Usenet}}inMemory = sealed === undefined ? password || undefined : undefined- await updateJson(serverPath(), () => ({ ...rest, ...(sealed && { password: sealed }) }))+ await updateJson(serverPath(), (current) => {+ // No password given and none to seal: the stored one stays, for a session that can unseal it+ // (one with the keyring this one lacks).+ const stored = input.password === undefined && isRecord(current) ? current.password : undefined+ const kept = sealed ?? (typeof stored === 'string' ? stored : undefined)+ return { ...rest, ...(kept && { password: kept }) }+ })return viewOf(server)}diff --git a/src/main/download/probe.ts b/src/main/download/probe.tsindex b9a1c20..6840e59 100644--- a/src/main/download/probe.ts+++ b/src/main/download/probe.ts@@ -7,6 +7,7 @@ import { testKnobs } from '../testKnobs'import { requestHeaders } from './browserContext'import { parseContentDispositionFilename } from './contentDisposition'import { describeNzb, downloadNzbFile, indexerError, readNzbFile, sniffXml } from './nzb/nzbFile'+import { USENET_OFF, usenetEnabled } from './nzb/usenetServer'import { normalizeEtag } from './fileVersion'import {describeTorrent,@@ -184,6 +185,7 @@ export async function probeUrl(rawUrl: string, browser?: BrowserContext): Promisreturn describeTorrent(await readTorrentFile(rawUrl), rawUrl)}if (isAbsolute(rawUrl) && /\.nzb$/i.test(rawUrl)) {+ if (!(await usenetEnabled())) throw new Error(USENET_OFF)return describeNzb(await readNzbFile(rawUrl), rawUrl, basename(rawUrl))}@@ -224,7 +226,8 @@ export async function probeUrl(rawUrl: string, browser?: BrowserContext): Promis}const suggestedFileName = fileNameFromHeaders(response.headers, current)- if (isNzbLink(response.headers, current, suggestedFileName)) {+ // Off, an NZB is a file like any other: for another newsreader to take.+ if (isNzbLink(response.headers, current, suggestedFileName) && (await usenetEnabled())) {const finalUrl = current.toString()const nzbFile = await downloadNzbFile(finalUrl,@@ -241,7 +244,7 @@ export async function probeUrl(rawUrl: string, browser?: BrowserContext): Promisconst start = await sniffXml(finalUrl, PROBE_TIMEOUT_MS, headers)const refusal = indexerError(start)if (refusal) throw new Error(refusal)- if (/<(?:[\w-]+:)?nzb\b/i.test(start)) {+ if (/<(?:[\w-]+:)?nzb\b/i.test(start) && (await usenetEnabled())) {const nzbFile = await downloadNzbFile(finalUrl, PROBE_TIMEOUT_MS, headers)return describeNzb(nzbFile, finalUrl, suggestedFileName)}diff --git a/src/main/ipc/handlers.ts b/src/main/ipc/handlers.tsindex d07c714..6a9d85a 100644--- a/src/main/ipc/handlers.ts+++ b/src/main/ipc/handlers.ts@@ -287,7 +287,11 @@ export function registerIpcHandlers(getWindow: () => BrowserWindow | null): Downconst server = await loadUsenetServer()return server && viewOf(server)})- handle('saveUsenetServer', async (_event, input) => saveUsenetServer(input))+ handle('saveUsenetServer', async (_event, input) => {+ const server = await saveUsenetServer(input)+ manager.usenetSwitched(server.enabled)+ return server+ })handle('testUsenetServer', async (_event, input) =>testUsenetServer(await serverFromInput(input)))diff --git a/src/renderer/src/components/LimitsDialog.tsx b/src/renderer/src/components/LimitsDialog.tsxindex b53a337..4721992 100644--- a/src/renderer/src/components/LimitsDialog.tsx+++ b/src/renderer/src/components/LimitsDialog.tsx@@ -6,7 +6,8 @@ import {DOWNLOADS_AT_ONCE,type AppSettings,type DataLimitPeriod,- type NetworkPreference+ type NetworkPreference,+ type UsenetServer} from '@shared/types'import { Minus, Plus } from 'lucide-react'import { useEffect, useId, useRef, useState } from 'react'@@ -31,6 +32,10 @@ import { Dialog, DialogContent, DialogTitle } from './ui/dialog'import { Input } from './ui/input'import { Switch } from './ui/switch'import { ToggleGroup, ToggleGroupItem } from './ui/toggle-group'+import { UsenetServerDialog } from './UsenetServerDialog'++/** The page key for Usenet, beside networks' interface ids. */+const USENET_PAGE = 'usenet'/** What the dialog edits: a copy taken when it opens, written back only on Save. */type Draft = Pick<@@ -499,6 +504,93 @@ function NetworkPage({)}+function UsenetPage({+ server,+ enabled,+ onEnabledChange,+ onServerSaved+}: {+ /** As saved; null when there's none, undefined until loaded. */+ server: UsenetServer | null | undefined+ enabled: boolean+ onEnabledChange: (enabled: boolean) => void+ onServerSaved: (server: UsenetServer) => void+}): React.JSX.Element {+ const [editing, setEditing] = useState(false)+ const rows: [string, string][] = server+ ? [+ ['Server', `${server.host}:${server.port}`],+ ['SSL', server.tls ? 'On' : 'Off'],+ ['Username', server.username || 'None'],+ ['Connections', String(server.connections)]+ ]+ : []+ return (+ <>+ <div className="flex flex-col gap-1 pb-3">+ <h3 className="font-sans text-[18px] leading-none font-semibold">Usenet</h3>+ <div className="font-mono text-[12px] text-muted-foreground">+ {server ? server.host : 'No news server set up'}+ </div>+ </div>++ <section className={sectionClass}>+ <h4 className={headingClass}>Usenet downloads</h4>+ <p className={hintClass}>+ {server === null+ ? 'NZB links and files download from your news server, once it’s set up.'+ : 'NZB links and files download from your news server. When off, an NZB link downloads as a plain file.'}+ </p>+ <label className="flex w-fit items-center gap-2 text-[13px]">+ Enabled+ <Switch+ aria-label="Usenet downloads"+ checked={enabled}+ // Kept with the server: nothing to switch until there is one.+ disabled={!server}+ onCheckedChange={onEnabledChange}+ />+ </label>+ </section>++ <section className={sectionClass}>+ <h4 className={headingClass}>News server</h4>+ <p className={hintClass}>+ Where NZB downloads come from, as your Usenet provider gives it. Changes to the server are+ saved in its own window, right away.+ </p>+ {rows.length > 0 && (+ <dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 text-[13px]">+ {rows.map(([label, value]) => (+ <div key={label} className="contents">+ <dt className="text-[var(--text-secondary)]">{label}</dt>+ <dd className="truncate font-mono">{value}</dd>+ </div>+ ))}+ </dl>+ )}+ <div>+ <Button+ type="button"+ variant="secondary"+ size="sm"+ disabled={server === undefined}+ onClick={() => setEditing(true)}+ >+ {server ? 'Change server' : 'Set up server'}+ </Button>+ </div>+ </section>+ <UsenetServerDialog+ open={editing}+ server={server ?? null}+ onOpenChange={setEditing}+ onSaved={onServerSaved}+ />+ </>+ )+}+/** "5.00 of 5 GB this month", with a bar that turns red once the limit is reached. */function UsageBar({used,@@ -545,9 +637,9 @@ function describeLimits(return lines.length > 0 ? lines : ['No limit']}-/** Speed & data limits: every download's together, and each network's. Nothing changes until- * Save; Cancel (or Escape) leaves everything as it was. Resetting data usage is the exception:- * it's an action, not a setting, so it happens once confirmed. */+/** Speed & data limits: every download's together, Usenet's, and each network's. Nothing changes+ * until Save; Cancel (or Escape) leaves everything as it was. Resetting data usage and the news+ * server are the exceptions: each is saved once confirmed in its own dialog. */export function LimitsDialog({showSchedule = false,open,@@ -558,7 +650,7 @@ export function LimitsDialog({showSchedule?: booleanopen: booleanonOpenChange: (open: boolean) => void- /** The network shown, by interface id; null for General. */+ /** The network shown, by interface id; USENET_PAGE for Usenet, null for General. */page: string | nullonPageChange: (page: string | null) => void}): React.JSX.Element {@@ -630,6 +722,16 @@ function LimitsEditor({[id]: { ...previous.networkPreferences[id], ...patch }}}))+ const [usenet, setUsenet] = useState<UsenetServer | null | undefined>(undefined)+ // The switch as drafted; the server's own until changed.+ const [usenetEnabled, setUsenetEnabled] = useState<boolean | undefined>(undefined)+ const shownUsenetEnabled = usenetEnabled ?? usenet?.enabled ?? true+ useEffect(() => {+ void window.plexo+ .usenetServer()+ .then(setUsenet)+ .catch(() => setUsenet(null))+ }, [])const [saving, setSaving] = useState(false)const [error, setError] = useState<string | null>(null)const valid = draft.downloadSchedule === undefined || validSchedule(draft.downloadSchedule)@@ -655,6 +757,11 @@ function LimitsEditor({try {await window.plexo.updateSettings(patch)useAppStore.setState(patch)+ // Last, as switching off stops running NZBs: not done when the rest failed to save.+ if (usenet && usenetEnabled !== undefined && usenetEnabled !== usenet.enabled) {+ // The server as it is, every field kept. No password given: the saved one stays.+ setUsenet(await window.plexo.saveUsenetServer({ ...usenet, enabled: usenetEnabled }))+ }onClose()} catch (cause) {setError(describeError(cause))@@ -721,6 +828,15 @@ function LimitsEditor({]: [])])}+ {navItem(+ USENET_PAGE,+ 'var(--text-secondary)',+ 'Usenet',+ // Still loading: no line rather than a guess.+ usenet === undefined+ ? []+ : [usenet === null ? 'No server' : shownUsenetEnabled ? 'On' : 'Off']+ )}<div className={navLabelClass}>Networks</div>{interfaces.map((iface) => {const visual = networkVisual(iface.id, iface.kind, iface.displayName)@@ -739,7 +855,14 @@ function LimitsEditor({})}</nav><fieldset disabled={saving} className="min-h-0 min-w-0 flex-1 overflow-y-auto px-4 py-3">- {shown ? (+ {page === USENET_PAGE ? (+ <UsenetPage+ server={usenet}+ enabled={shownUsenetEnabled}+ onEnabledChange={setUsenetEnabled}+ onServerSaved={setUsenet}+ />+ ) : shown ? (<NetworkPagekey={shown.id}id={shown.id}diff --git a/src/renderer/src/components/UsenetServerDialog.tsx b/src/renderer/src/components/UsenetServerDialog.tsxindex b74838c..68af29b 100644--- a/src/renderer/src/components/UsenetServerDialog.tsx+++ b/src/renderer/src/components/UsenetServerDialog.tsx@@ -98,7 +98,8 @@ function UsenetServerForm({tls,username: username.trim(),connections: Number(connections),- password: password === '' && server?.hasPassword ? undefined : password+ // Blank keeps the stored password, also one this session can't unseal (hasPassword false).+ password: password === '' ? undefined : password})const valid =host.trim() !== '' &&diff --git a/src/shared/types.ts b/src/shared/types.tsindex 6327cb0..4a5e492 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -660,6 +660,8 @@ export type StartDownloadRequest =/** The news server NZB downloads come from, as the window sees it: never its password. */export interface UsenetServer {+ /** NZBs download from it; off, an NZB link downloads as a plain file. */+ enabled: booleanhost: stringport: numbertls: boolean@@ -673,9 +675,10 @@ export interface UsenetServer {passwordInMemory?: boolean}-/** What the window sends to set the news server, or to test one. `password` left out keeps the- * one already saved. */+/** What the window sends to set the news server, or to test one. `password` or `enabled` left out+ * keeps the one already saved. */export interface UsenetServerInput {+ enabled?: booleanhost: stringport: numbertls: boolean