Skip to content

The agent that grows with you

desktop: localize download ETA units and pause/resume failure toasts

ethernet79fa28ab441a
diff --git a/apps/desktop/src/app/settings/local-model-download-progress.test.tsx b/apps/desktop/src/app/settings/local-model-download-progress.test.tsx
index f5cc0bb3f83..a8212d1b6ff 100644
--- a/apps/desktop/src/app/settings/local-model-download-progress.test.tsx
+++ b/apps/desktop/src/app/settings/local-model-download-progress.test.tsx
@@ -123,6 +123,27 @@ describe('LocalModelDownloadActions', () => {
})
})
+ it('pause and resume failures name the action that failed, not a generic download failure', async () => {
+ const { notifyError } = await import('@/store/notifications')
+
+ vi.mocked(pauseLocalDownload).mockRejectedValue(new Error('offline'))
+ renderActions(job({ can_pause: true }))
+ fireEvent.click(screen.getByRole('button', { name: /pause/i }))
+ await waitFor(() => expect(notifyError).toHaveBeenCalledTimes(1))
+ const pauseTitle: string = vi.mocked(notifyError).mock.calls[0]?.[1] as string
+ cleanup()
+
+ vi.mocked(resumeLocalDownload).mockRejectedValue(new Error('offline'))
+ renderActions(job({ can_resume: true, status: 'paused' }))
+ fireEvent.click(screen.getByRole('button', { name: /resume/i }))
+ await waitFor(() => expect(notifyError).toHaveBeenCalledTimes(2))
+ const resumeTitle: string = vi.mocked(notifyError).mock.calls[1]?.[1] as string
+
+ expect(pauseTitle).toMatch(/pause/i)
+ expect(resumeTitle).toMatch(/resume/i)
+ expect(pauseTitle).not.toBe(resumeTitle)
+ })
+
it('no control on settled jobs', () => {
renderActions(job({ can_pause: true, status: 'done' }))
@@ -143,6 +164,9 @@ describe('isDownloadPhase', () => {
// The status copy as a locale supplies it; the composer only assembles it.
const statusCopy = {
downloadEta: (time: string) => `~${time} left`,
+ downloadEtaHours: (hours: number, minutes: number) => (minutes ? `${hours} h ${minutes} min` : `${hours} h`),
+ downloadEtaMinutes: (count: number) => `${count} min`,
+ downloadEtaSeconds: (count: number) => `${count} sec`,
downloadPausedLabel: 'Paused',
downloadProgress: (done: string, total: string) => `${done} of ${total}`,
downloadSpeed: (rate: string) => `${rate}`,
@@ -195,16 +219,28 @@ describe('speed and ETA formatting', () => {
it('reports nothing for an unknown or stalled rate', () => {
expect(formatSpeed(undefined)).toBe('')
expect(formatSpeed(0)).toBe('')
- expect(formatEta(null)).toBe('')
- expect(formatEta(0.4)).toBe('')
+ expect(formatEta(null, statusCopy)).toBe('')
+ expect(formatEta(0.4, statusCopy)).toBe('')
})
it('scales the rate unit and the ETA magnitude', () => {
expect(formatSpeed(24 * (1 << 20))).toBe('24 MB/s')
expect(formatSpeed(512 * (1 << 10))).toBe('0.5 MB/s')
expect(formatSpeed(2 * (1 << 30))).toBe('2.0 GB/s')
- expect(formatEta(45)).toBe('45 sec')
- expect(formatEta(120)).toBe('2 min')
- expect(formatEta(3_900)).toBe('1 h 5 min')
+ expect(formatEta(45, statusCopy)).toBe('45 sec')
+ expect(formatEta(120, statusCopy)).toBe('2 min')
+ expect(formatEta(3_900, statusCopy)).toBe('1 h 5 min')
+ expect(formatEta(7_200, statusCopy)).toBe('2 h')
+ })
+
+ it('spells the ETA in the locale’s words, not a hardcoded unit', () => {
+ const ja = {
+ downloadEtaHours: (hours: number, minutes: number) => `${hours}時間${minutes ? `${minutes}分` : ''}`,
+ downloadEtaMinutes: (count: number) => `${count}分`,
+ downloadEtaSeconds: (count: number) => `${count}秒`
+ }
+
+ expect(formatEta(45, ja)).toBe('45秒')
+ expect(formatEta(3_900, ja)).toBe('1時間5分')
})
})
diff --git a/apps/desktop/src/app/settings/local-model-download-progress.tsx b/apps/desktop/src/app/settings/local-model-download-progress.tsx
index 01f42a04cab..ad6fef3760c 100644
--- a/apps/desktop/src/app/settings/local-model-download-progress.tsx
+++ b/apps/desktop/src/app/settings/local-model-download-progress.tsx
@@ -63,8 +63,13 @@ export interface DownloadStatusCopy {
downloadProgress: (done: string, total: string) => string
downloadSpeed: (rate: string) => string
downloadEta: (time: string) => string
+ downloadEtaSeconds: (count: number) => string
+ downloadEtaMinutes: (count: number) => string
+ downloadEtaHours: (hours: number, minutes: number) => string
}
+export type DownloadEtaCopy = Pick<DownloadStatusCopy, 'downloadEtaHours' | 'downloadEtaMinutes' | 'downloadEtaSeconds'>
+
export function formatSpeed(bytesPerSec: number | null | undefined): string {
if (!bytesPerSec || bytesPerSec <= 0 || !Number.isFinite(bytesPerSec)) {
return ''
@@ -75,25 +80,24 @@ export function formatSpeed(bytesPerSec: number | null | undefined): string {
return mb >= 1024 ? `${(mb / 1024).toFixed(1)} GB/s` : mb >= 10 ? `${Math.round(mb)} MB/s` : `${mb.toFixed(1)} MB/s`
}
-export function formatEta(seconds: number | null | undefined): string {
+// Byte-rate units (MB/s, GB/s) are SI symbols and stay as-is; the duration
+// words are the locale's, so the ETA only picks the magnitude here.
+export function formatEta(seconds: number | null | undefined, copy: DownloadEtaCopy): string {
if (seconds == null || !Number.isFinite(seconds) || seconds < 1) {
return ''
}
if (seconds < 60) {
- return `${Math.max(1, Math.round(seconds))} sec`
+ return copy.downloadEtaSeconds(Math.max(1, Math.round(seconds)))
}
- const minutes = Math.round(seconds / 60)
+ const minutes: number = Math.round(seconds / 60)
if (minutes < 60) {
- return `${minutes} min`
+ return copy.downloadEtaMinutes(minutes)
}
- const hours = Math.floor(minutes / 60)
- const rest = minutes % 60
-
- return rest ? `${hours} h ${rest} min` : `${hours} h`
+ return copy.downloadEtaHours(Math.floor(minutes / 60), minutes % 60)
}
// One status line for every download surface: what it is doing, how far, how
@@ -125,7 +129,7 @@ export function downloadStatusText(job: LocalRuntimeJob, copy: DownloadStatusCop
if (speed) {
parts.push(copy.downloadSpeed(speed))
- const eta = formatEta(job.eta_seconds)
+ const eta: string = formatEta(job.eta_seconds, copy)
if (eta) {
parts.push(copy.downloadEta(eta))
@@ -197,7 +201,10 @@ export function LocalModelDownloadActions({
watchLocalRuntimeJobs(owner)
} catch (err) {
if (!owner || isCurrentLocalModelsOwner(owner)) {
- notifyError(err, copy.downloadFailed(job.target))
+ notifyError(
+ err,
+ kind === 'pause' ? copy.downloadPauseFailed(job.target) : copy.downloadResumeFailed(job.target)
+ )
}
} finally {
setBusy(false)
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index dda6bb5f653..f5e09a5f3d8 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -1493,6 +1493,9 @@ export const en: Translations = {
downloadStatusRunning: 'Downloading',
downloadSpeed: rate => `${rate}`,
downloadEta: time => `~${time} left`,
+ downloadEtaSeconds: count => `${count} sec`,
+ downloadEtaMinutes: count => `${count} min`,
+ downloadEtaHours: (hours, minutes) => (minutes ? `${hours} h ${minutes} min` : `${hours} h`),
downloadPausedLabel: 'Paused',
downloadPauseAction: 'Pause',
downloadResumeAction: 'Resume',
@@ -1543,6 +1546,8 @@ export const en: Translations = {
activateFailed: model => `Could not switch to ${model}`,
activateDoneToast: model => `New chats use ${model}.`,
downloadFailed: model => `Download of ${model} failed`,
+ downloadPauseFailed: model => `Couldn’t pause the download of ${model}`,
+ downloadResumeFailed: model => `Couldn’t resume the download of ${model}`,
pillFitsGpu: 'Fits your GPU',
pillUsesRam: 'Uses system RAM',
pillTooBig: 'Too big for this machine',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 09ba63e8937..d04a4568e36 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -1250,6 +1250,11 @@ export interface Translations {
downloadStatusRunning: string
downloadSpeed: (rate: string) => string
downloadEta: (time: string) => string
+ /** Duration units the ETA is composed from; hours carries its
+ * remainder so a locale orders the two parts itself. */
+ downloadEtaSeconds: (count: number) => string
+ downloadEtaMinutes: (count: number) => string
+ downloadEtaHours: (hours: number, minutes: number) => string
downloadPausedLabel: string
downloadPauseAction: string
downloadResumeAction: string
@@ -1295,6 +1300,8 @@ export interface Translations {
activateFailed: (model: string) => string
activateDoneToast: (model: string) => string
downloadFailed: (model: string) => string
+ downloadPauseFailed: (model: string) => string
+ downloadResumeFailed: (model: string) => string
pillFitsGpu: string
pillUsesRam: string
pillTooBig: string