feat(desktop): upload progress on the taskbar button (cinny-desktop #10)
Upload atoms now also report into an app-wide `uploadProgressAtom`, and `aggregateUploadProgress` turns every in-flight upload into one taskbar state: byte-weighted percentage while uploading, indeterminate until a size is known, red after a failure (held 4 s, then cleared), none when done. Cancelled uploads just disappear. `useTauriTaskbarProgress` sends it to the native `set_taskbar_progress`, at most ~4 times a second, always ending on the latest state. Verified with a throttled 6 MB upload: 0% → 99% at 250 ms steps, then cleared; with the upload request aborted: 0% → error → cleared after 4 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
25fa0f6ef9
commit
146ba4d2ff
@@ -4,6 +4,7 @@ import { MatrixClient, UploadResponse, UploadProgress, MatrixError } from 'matri
|
||||
import { useCallback, useRef } from 'react';
|
||||
import { useThrottle } from '../hooks/useThrottle';
|
||||
import { uploadContent, TUploadContent } from '../utils/matrix';
|
||||
import { uploadProgressAtom } from './uploadProgress';
|
||||
|
||||
export enum UploadStatus {
|
||||
Idle = 'idle',
|
||||
@@ -61,7 +62,17 @@ export const createUploadAtom = (file: TUploadContent) => {
|
||||
(get) => get(baseUploadAtom),
|
||||
(get, set, update) => {
|
||||
const uploadState = get(baseUploadAtom);
|
||||
// [cinny-desktop #10] Mirror into the app-wide progress map for the
|
||||
// desktop taskbar bar. Cancelled uploads just disappear (no red bar).
|
||||
const track = (entry: { loaded: number; total: number; failed: boolean } | undefined) =>
|
||||
set(uploadProgressAtom, (prev) => {
|
||||
const next = new Map(prev);
|
||||
if (entry) next.set(file, { ...entry, updatedAt: Date.now() });
|
||||
else next.delete(file);
|
||||
return next;
|
||||
});
|
||||
if ('promise' in update) {
|
||||
track({ loaded: 0, total: file.size, failed: false });
|
||||
set(baseUploadAtom, {
|
||||
status: UploadStatus.Loading,
|
||||
file,
|
||||
@@ -71,6 +82,11 @@ export const createUploadAtom = (file: TUploadContent) => {
|
||||
return;
|
||||
}
|
||||
if ('progress' in update && uploadState.status === UploadStatus.Loading) {
|
||||
track({
|
||||
loaded: update.progress.loaded,
|
||||
total: update.progress.total || file.size,
|
||||
failed: false,
|
||||
});
|
||||
set(baseUploadAtom, {
|
||||
...uploadState,
|
||||
progress: update.progress,
|
||||
@@ -78,6 +94,7 @@ export const createUploadAtom = (file: TUploadContent) => {
|
||||
return;
|
||||
}
|
||||
if ('mxc' in update) {
|
||||
track(undefined);
|
||||
set(baseUploadAtom, {
|
||||
status: UploadStatus.Success,
|
||||
file,
|
||||
@@ -86,6 +103,11 @@ export const createUploadAtom = (file: TUploadContent) => {
|
||||
return;
|
||||
}
|
||||
if ('error' in update) {
|
||||
const cancelled =
|
||||
update.error?.name === 'AbortError' || /abort/i.test(update.error?.message ?? '');
|
||||
const loaded =
|
||||
uploadState.status === UploadStatus.Loading ? uploadState.progress.loaded : 0;
|
||||
track(cancelled ? undefined : { loaded, total: file.size, failed: true });
|
||||
set(baseUploadAtom, {
|
||||
status: UploadStatus.Error,
|
||||
file,
|
||||
|
||||
Reference in New Issue
Block a user