Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
Notify users when a newer release is available
Anmol Kapilf03aeddb9305
diff --git a/src/main/ipc/handlers.ts b/src/main/ipc/handlers.tsindex 6f506c9..b26f607 100644--- a/src/main/ipc/handlers.ts+++ b/src/main/ipc/handlers.ts@@ -1,5 +1,6 @@import { is } from '@electron-toolkit/utils'import {+ app,clipboard,dialog,ipcMain,@@ -17,7 +18,13 @@ import { probeUrl } from '../download/probe'import { measureLatencies } from '../network/latency'import { listActiveInterfaces } from '../network/interfaces'import { loadNetworkPreferences, saveNetworkPreference } from '../network/preferences'-import { saveThemeSource } from '../settings'+import {+ loadDismissedUpdateVersion,+ saveDismissedUpdateVersion,+ saveThemeSource+} from '../settings'+import { testKnobs } from '../testKnobs'+import { checkForUpdate, UPDATE_PAGE_URL } from '../updateCheck'async function openNetworkSettings(): Promise<void> {if (process.platform === 'win32') {@@ -145,5 +152,22 @@ export function registerIpcHandlers(getWindow: () => BrowserWindow | null): Downmanager.remove(id)})+ // Kicked off once at startup, not per-call — later renderer calls (e.g. a remount) just await+ // the same in-flight/settled check instead of re-hitting the GitHub API.+ const updateCheckPromise = (async () => {+ const info = testKnobs.forceUpdateVersion+ ? { version: testKnobs.forceUpdateVersion, url: UPDATE_PAGE_URL }+ : await checkForUpdate(app.getVersion())+ if (!info) return null+ const dismissedVersion = await loadDismissedUpdateVersion()+ return { ...info, dismissed: info.version === dismissedVersion }+ })()++ handle('checkForUpdate', async () => updateCheckPromise)++ handle('dismissUpdate', async (_event, version) => {+ await saveDismissedUpdateVersion(version)+ })+return manager}diff --git a/src/main/settings.ts b/src/main/settings.tsindex 96e699f..53ad4c5 100644--- a/src/main/settings.ts+++ b/src/main/settings.ts@@ -9,6 +9,7 @@ function settingsPath(): string {interface AppSettings {themeSource?: ThemeSource+ dismissedUpdateVersion?: string}async function loadSettings(): Promise<AppSettings> {@@ -35,3 +36,17 @@ export async function saveThemeSource(themeSource: ThemeSource): Promise<void> {const settings = await loadSettings()await writeFile(settingsPath(), JSON.stringify({ ...settings, themeSource }, null, 2), 'utf-8')}++export async function loadDismissedUpdateVersion(): Promise<string | undefined> {+ const settings = await loadSettings()+ return settings.dismissedUpdateVersion+}++export async function saveDismissedUpdateVersion(version: string): Promise<void> {+ const settings = await loadSettings()+ await writeFile(+ settingsPath(),+ JSON.stringify({ ...settings, dismissedUpdateVersion: version }, null, 2),+ 'utf-8'+ )+}diff --git a/src/main/testKnobs.ts b/src/main/testKnobs.tsindex 5f858cd..da1ed64 100644--- a/src/main/testKnobs.ts+++ b/src/main/testKnobs.ts@@ -16,7 +16,10 @@ export const testKnobs = {hideWindow: env['PLEXO_E2E_HIDE_WINDOW'] === '1',blockBytes: positiveNumber('PLEXO_E2E_BLOCK_BYTES', 8 * 1024 * 1024),retryBaseDelayMs: positiveNumber('PLEXO_E2E_RETRY_BASE_MS', 1000),- stallTimeoutMs: positiveNumber('PLEXO_E2E_STALL_MS', 20_000)+ stallTimeoutMs: positiveNumber('PLEXO_E2E_STALL_MS', 20_000),+ /** Skips the real GitHub check and pretends this version is available, for exercising the+ * update banner without needing an actual newer release published. */+ forceUpdateVersion: env['PLEXO_FORCE_UPDATE_VERSION']}/** `PLEXO_E2E_INTERFACES=a=127.0.0.1,b=192.168.1.5` replaces the real interface list. Read ondiff --git a/src/main/updateCheck.ts b/src/main/updateCheck.tsnew file mode 100644index 0000000..5e81829--- /dev/null+++ b/src/main/updateCheck.ts@@ -0,0 +1,45 @@+import { net } from 'electron'+import type { UpdateInfo } from '../shared/types'++type ReleaseInfo = Omit<UpdateInfo, 'dismissed'>++const REPO = 'anmolkapil/plexo'+export const UPDATE_PAGE_URL = 'https://anmolkapil.github.io/plexo/'++function parseVersion(version: string): number[] {+ // ponytail: naive numeric-segment compare, not full semver (a "1.0.0-rc.2" pre-release tag+ // reads as a plain 4th segment) — swap for the `semver` package if pre-release ordering ever+ // needs to be exact.+ return version+ .replace(/^v/, '')+ .split(/[.-]/)+ .map((part) => parseInt(part, 10) || 0)+}++function isNewer(latest: string, current: string): boolean {+ const a = parseVersion(latest)+ const b = parseVersion(current)+ for (let i = 0; i < Math.max(a.length, b.length); i++) {+ const diff = (a[i] ?? 0) - (b[i] ?? 0)+ if (diff !== 0) return diff > 0+ }+ return false+}++/** Checks the repo's latest GitHub release against the running app version. Same data source the+ * landing page's downloads list already reads, so there's no separate update feed to stand up. */+export async function checkForUpdate(currentVersion: string): Promise<ReleaseInfo | null> {+ try {+ const response = await net.fetch(`https://api.github.com/repos/${REPO}/releases/latest`)+ if (!response.ok) return null+ const data = (await response.json()) as { tag_name?: string }+ if (!data.tag_name) return null+ const version = data.tag_name.replace(/^v/, '')+ if (!isNewer(version, currentVersion)) return null+ return { version, url: UPDATE_PAGE_URL }+ } catch {+ // Offline, rate-limited, or GitHub is down — silently skip the notification rather than+ // surface a startup error for a non-essential check.+ return null+ }+}diff --git a/src/preload/index.ts b/src/preload/index.tsindex b0da9ef..c2930ed 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -39,6 +39,8 @@ const plexoApi = {resumeDownload: (downloadId: string) => invoke('resumeDownload', downloadId),cancelDownload: (downloadId: string) => invoke('cancelDownload', downloadId),removeDownload: (downloadId: string) => invoke('removeDownload', downloadId),+ checkForUpdate: () => invoke('checkForUpdate'),+ dismissUpdate: (version: string) => invoke('dismissUpdate', version),onDownloadUpdated: (callback: (state: DownloadState) => void): (() => void) => {const listener = (_event: IpcRendererEvent, state: DownloadState): void => callback(state)diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsxindex aa1bfbe..e7a8eed 100644--- a/src/renderer/src/App.tsx+++ b/src/renderer/src/App.tsx@@ -2,6 +2,7 @@ import type { DownloadState } from '@shared/types'import { useEffect } from 'react'import { DevToolsPanel } from './components/DevToolsPanel'import { TitleBar, type TitleBarStatus } from './components/TitleBar'+import { UpdateDialog } from './components/UpdateDialog'import { TooltipProvider } from './components/ui/tooltip'import { useDownloadEvents } from './hooks/useDownloadEvents'import { CompleteScreen } from './screens/CompleteScreen'@@ -76,12 +77,14 @@ function App(): React.JSX.Element {const loadNetworkPreferences = useAppStore((store) => store.loadNetworkPreferences)const loadThemeSource = useAppStore((store) => store.loadThemeSource)const loadInitialPaths = useAppStore((store) => store.loadInitialPaths)+ const checkForUpdate = useAppStore((store) => store.checkForUpdate)useEffect(() => {loadNetworkPreferences()loadThemeSource()loadInitialPaths()- }, [loadNetworkPreferences, loadThemeSource, loadInitialPaths])+ checkForUpdate()+ }, [loadNetworkPreferences, loadThemeSource, loadInitialPaths, checkForUpdate])const handleNewDownload = (): void => {if (currentDownload) void window.plexo.removeDownload(currentDownload.id)@@ -120,6 +123,7 @@ function App(): React.JSX.Element {<TitleBar status={titleBarStatus} /><div className="min-h-0 flex-1">{screen}</div><DevToolsPanel />+ <UpdateDialog /></div></TooltipProvider>)diff --git a/src/renderer/src/components/TitleBar.tsx b/src/renderer/src/components/TitleBar.tsxindex 5a9cd1c..4a12eff 100644--- a/src/renderer/src/components/TitleBar.tsx+++ b/src/renderer/src/components/TitleBar.tsx@@ -1,5 +1,6 @@import { ColorBadge } from './ColorBadge'import { ThemeToggle } from './ThemeToggle'+import { UpdateIndicator } from './UpdateIndicator'export type TitleBarStatus =| { kind: 'none' }@@ -82,6 +83,7 @@ export function TitleBar({ status }: { status: TitleBarStatus }): React.JSX.ElemOffline</ColorBadge>)}+ <UpdateIndicator /><ThemeToggle /></div>)diff --git a/src/renderer/src/components/UpdateDialog.tsx b/src/renderer/src/components/UpdateDialog.tsxnew file mode 100644index 0000000..acb5116--- /dev/null+++ b/src/renderer/src/components/UpdateDialog.tsx@@ -0,0 +1,47 @@+import { DownloadIcon } from 'lucide-react'+import { useAppStore } from '../store/useAppStore'+import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle+} from './ui/alert-dialog'+import { buttonVariants } from './ui/button'++export function UpdateDialog(): React.JSX.Element | null {+ const availableUpdate = useAppStore((store) => store.availableUpdate)+ const dismissUpdate = useAppStore((store) => store.dismissUpdate)++ if (!availableUpdate) return null++ return (+ <AlertDialog+ open={!availableUpdate.dismissed}+ onOpenChange={(open) => {+ if (!open) dismissUpdate()+ }}+ >+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Plexo {availableUpdate.version} is available</AlertDialogTitle>+ <AlertDialogDescription>A new version is ready to download.</AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel>Not now</AlertDialogCancel>+ {/* target="_blank" routes through the main process's window-open handler, which hands+ * http(s) links to the OS browser instead of opening a second app window. */}+ <AlertDialogAction+ className={buttonVariants({ size: 'sm' })}+ render={<a href={availableUpdate.url} target="_blank" rel="noreferrer" />}+ >+ <DownloadIcon /> Download+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ )+}diff --git a/src/renderer/src/components/UpdateIndicator.tsx b/src/renderer/src/components/UpdateIndicator.tsxnew file mode 100644index 0000000..232ab8f--- /dev/null+++ b/src/renderer/src/components/UpdateIndicator.tsx@@ -0,0 +1,32 @@+import { CircleArrowUp } from 'lucide-react'+import { useAppStore } from '../store/useAppStore'+import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip'++/** Sits next to ThemeToggle once the banner has been dismissed — same size/shape, so it reads as+ * part of the same row of controls rather than a separate alert. */+export function UpdateIndicator(): React.JSX.Element | null {+ const availableUpdate = useAppStore((store) => store.availableUpdate)++ if (!availableUpdate?.dismissed) return null++ return (+ <Tooltip>+ <TooltipTrigger+ render={+ // target="_blank" routes through the main process's window-open handler, which hands+ // http(s) links to the OS browser instead of opening a second app window.+ <a+ href={availableUpdate.url}+ target="_blank"+ rel="noreferrer"+ aria-label={`Update available: ${availableUpdate.version}`}+ className="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded-[6px] border-[0.5px] border-border bg-secondary text-[var(--text-secondary)] [-webkit-app-region:no-drag]"+ >+ <CircleArrowUp size={15} strokeWidth={1.3} />+ </a>+ }+ />+ <TooltipContent>New update available</TooltipContent>+ </Tooltip>+ )+}diff --git a/src/renderer/src/store/useAppStore.ts b/src/renderer/src/store/useAppStore.tsindex 7bd9186..119094c 100644--- a/src/renderer/src/store/useAppStore.ts+++ b/src/renderer/src/store/useAppStore.ts@@ -3,7 +3,8 @@ import type {NetworkInterfaceInfo,NetworkPreference,NetworkPreferences,- ThemeSource+ ThemeSource,+ UpdateInfo} from '@shared/types'import { create } from 'zustand'import { groupChunksByInterface } from '../utils/format'@@ -28,6 +29,10 @@ interface AppStore {/** Persisted in the main process alongside nativeTheme.themeSource. */themeSource: ThemeSource+ /** Null until the one-time startup check resolves, or if it found nothing worth showing+ * (already up to date, already dismissed, or the check failed). */+ availableUpdate: UpdateInfo | null+homeDir: stringdownloadsDir: stringpathsStatus: LoadStatus@@ -55,6 +60,8 @@ interface AppStore {setNetworkPreference: (id: string, patch: NetworkPreference) => Promise<void>loadThemeSource: () => Promise<void>setThemeSource: (source: ThemeSource) => Promise<void>+ checkForUpdate: () => Promise<void>+ dismissUpdate: () => voidsetCurrentDownload: (state: DownloadState) => voidclearCurrentDownload: () => voidsetDraftUrl: (url: string) => void@@ -68,6 +75,7 @@ export const useAppStore = create<AppStore>((set, get) => ({latencies: {},networkPreferences: {},themeSource: 'light',+ availableUpdate: null,homeDir: '',downloadsDir: '',@@ -163,6 +171,23 @@ export const useAppStore = create<AppStore>((set, get) => ({}},+ checkForUpdate: async () => {+ try {+ const availableUpdate = await window.plexo.checkForUpdate()+ set({ availableUpdate })+ } catch {+ // Best-effort — a failed check just leaves the banner hidden.+ }+ },++ dismissUpdate: () => {+ const update = get().availableUpdate+ if (!update) return+ // Keeps the update visible as a quiet titlebar icon rather than clearing it outright.+ set({ availableUpdate: { ...update, dismissed: true } })+ void window.plexo.dismissUpdate(update.version)+ },+setCurrentDownload: (download) => {const previous = get().currentDownloadconst isNewDownload = !previous || previous.id !== download.iddiff --git a/src/shared/ipc-channels.ts b/src/shared/ipc-channels.tsindex f5180ec..42327ce 100644--- a/src/shared/ipc-channels.ts+++ b/src/shared/ipc-channels.ts@@ -20,5 +20,7 @@ export const IpcChannels = {cancelDownload: 'download:cancel',removeDownload: 'download:remove',downloadUpdated: 'download:updated',- toggleDevToolsPanel: 'dev:toggle-panel'+ toggleDevToolsPanel: 'dev:toggle-panel',+ checkForUpdate: 'update:check',+ dismissUpdate: 'update:dismiss'} as constdiff --git a/src/shared/ipc-contract.ts b/src/shared/ipc-contract.tsindex 21135c8..8ab5680 100644--- a/src/shared/ipc-contract.ts+++ b/src/shared/ipc-contract.ts@@ -7,7 +7,8 @@ import type {ProbeResult,StartDownloadRequest,StartSimulatedDownloadRequest,- ThemeSource+ ThemeSource,+ UpdateInfo} from './types'/** The request/response half of the IPC surface (every IpcChannels entry except the two@@ -38,4 +39,6 @@ export interface IpcContract {resumeDownload: { args: [id: string]; result: void }cancelDownload: { args: [id: string]; result: void }removeDownload: { args: [id: string]; result: void }+ checkForUpdate: { args: []; result: UpdateInfo | null }+ dismissUpdate: { args: [version: string]; result: void }}diff --git a/src/shared/types.ts b/src/shared/types.tsindex 03fabc6..3818704 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -134,6 +134,15 @@ export interface StartSimulatedDownloadRequest {assembleSpeedBytesPerSec?: number}+export interface UpdateInfo {+ version: string+ /** Where clicking the notification should take the user — the landing page's downloads. */+ url: string+ /** True once the user has dismissed the banner for this exact version (persisted, so it stays+ * dismissed across relaunches) — the app then falls back to a quiet titlebar icon instead. */+ dismissed: boolean+}+export interface InitialPaths {homeDir: stringdownloadsDir: string