mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-06 17:38:06 +00:00
feat(ui): modernize desktop interactions
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
canPauseDownload,
|
||||
canRedownload,
|
||||
canStartDownload,
|
||||
isIdentityLocked,
|
||||
isTransferLocked,
|
||||
startActionLabel,
|
||||
} from './downloadActions';
|
||||
|
||||
describe('download action policy', () => {
|
||||
it('keeps start and pause actions mutually exclusive', () => {
|
||||
for (const status of ['ready', 'paused', 'failed'] as const) {
|
||||
expect(canStartDownload(status)).toBe(true);
|
||||
expect(canPauseDownload(status)).toBe(false);
|
||||
}
|
||||
for (const status of ['queued', 'downloading', 'processing', 'retrying'] as const) {
|
||||
expect(canPauseDownload(status)).toBe(true);
|
||||
expect(canStartDownload(status)).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it('limits redownload to terminal or paused states', () => {
|
||||
expect(canRedownload('completed')).toBe(true);
|
||||
expect(canRedownload('failed')).toBe(true);
|
||||
expect(canRedownload('paused')).toBe(true);
|
||||
expect(canRedownload('downloading')).toBe(false);
|
||||
});
|
||||
|
||||
it('provides consistent labels and edit locks', () => {
|
||||
expect(startActionLabel('ready')).toBe('Start');
|
||||
expect(startActionLabel('failed')).toBe('Start');
|
||||
expect(startActionLabel('paused')).toBe('Resume');
|
||||
expect(isTransferLocked('processing')).toBe(true);
|
||||
expect(isIdentityLocked('completed')).toBe(true);
|
||||
expect(isTransferLocked('completed')).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { DownloadStatus } from '../bindings/DownloadStatus';
|
||||
|
||||
const STARTABLE_STATUSES: ReadonlySet<DownloadStatus> = new Set([
|
||||
'ready',
|
||||
'paused',
|
||||
'failed',
|
||||
]);
|
||||
|
||||
const PAUSABLE_STATUSES: ReadonlySet<DownloadStatus> = new Set([
|
||||
'queued',
|
||||
'downloading',
|
||||
'processing',
|
||||
'retrying',
|
||||
]);
|
||||
|
||||
const REDOWNLOADABLE_STATUSES: ReadonlySet<DownloadStatus> = new Set([
|
||||
'completed',
|
||||
'failed',
|
||||
'paused',
|
||||
]);
|
||||
|
||||
export const canStartDownload = (status: DownloadStatus): boolean =>
|
||||
STARTABLE_STATUSES.has(status);
|
||||
|
||||
export const canPauseDownload = (status: DownloadStatus): boolean =>
|
||||
PAUSABLE_STATUSES.has(status);
|
||||
|
||||
export const canRedownload = (status: DownloadStatus): boolean =>
|
||||
REDOWNLOADABLE_STATUSES.has(status);
|
||||
|
||||
export const startActionLabel = (status: DownloadStatus): 'Start' | 'Resume' =>
|
||||
status === 'ready' || status === 'failed' ? 'Start' : 'Resume';
|
||||
|
||||
export const isTransferLocked = (status: DownloadStatus): boolean =>
|
||||
status === 'downloading' || status === 'processing' || status === 'retrying';
|
||||
|
||||
export const isIdentityLocked = (status: DownloadStatus): boolean =>
|
||||
isTransferLocked(status) || status === 'completed';
|
||||
@@ -3,7 +3,7 @@ import type { DownloadStatus } from '../bindings/DownloadStatus';
|
||||
import type { DownloadItem } from '../bindings/DownloadItem';
|
||||
export type { DownloadCategory } from '../bindings/DownloadCategory';
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { invokeCommand as invoke } from '../ipc';
|
||||
|
||||
let MEDIA_DOMAINS = [
|
||||
'youtube.com',
|
||||
@@ -47,7 +47,7 @@ export const normalizeSpeedLimitForBackend = (value?: string | null): string | n
|
||||
|
||||
export const initMediaDomains = async () => {
|
||||
try {
|
||||
const domains = await invoke<string[]>('get_supported_media_domains');
|
||||
const domains = await invoke('get_supported_media_domains');
|
||||
if (domains && domains.length > 0) {
|
||||
MEDIA_DOMAINS = domains;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user