mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 09:19:56 -05:00
Fix: Added Download Toggles to Global-Store (#63)
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
|||||||
DEQUEUE_DOWNLOAD, DEQUEUE_CHAPTERS_DOWNLOAD,
|
DEQUEUE_DOWNLOAD, DEQUEUE_CHAPTERS_DOWNLOAD,
|
||||||
ENQUEUE_DOWNLOAD, REORDER_DOWNLOAD,
|
ENQUEUE_DOWNLOAD, REORDER_DOWNLOAD,
|
||||||
} from "@api/mutations";
|
} from "@api/mutations";
|
||||||
import { addToast, setActiveDownloads } from "@store/state.svelte";
|
import { addToast, setActiveDownloads, store, updateSettings } from "@store/state.svelte";
|
||||||
import { boot } from "@store/boot.svelte";
|
import { boot } from "@store/boot.svelte";
|
||||||
import type { DownloadStatus, DownloadQueueItem } from "@types/index";
|
import type { DownloadStatus, DownloadQueueItem } from "@types/index";
|
||||||
import {
|
import {
|
||||||
@@ -26,8 +26,8 @@ class DownloadStore {
|
|||||||
pagesPerSec: number | null = $state(null);
|
pagesPerSec: number | null = $state(null);
|
||||||
eta: number | null = $state(null);
|
eta: number | null = $state(null);
|
||||||
|
|
||||||
toastsEnabled = $state(true);
|
get toastsEnabled() { return store.settings.downloadToastsEnabled ?? true; }
|
||||||
autoRetryEnabled = $state(false);
|
get autoRetryEnabled() { return store.settings.downloadAutoRetry ?? false; }
|
||||||
|
|
||||||
private lastSample: SpeedSample | null = null;
|
private lastSample: SpeedSample | null = null;
|
||||||
private prevQueue: DownloadQueueItem[] = [];
|
private prevQueue: DownloadQueueItem[] = [];
|
||||||
@@ -39,18 +39,19 @@ class DownloadStore {
|
|||||||
get hasErrored() { return this.erroredIds.size > 0; }
|
get hasErrored() { return this.erroredIds.size > 0; }
|
||||||
|
|
||||||
toggleToasts() {
|
toggleToasts() {
|
||||||
this.toastsEnabled = !this.toastsEnabled;
|
const next = !this.toastsEnabled;
|
||||||
addToast({ kind: "info", title: this.toastsEnabled ? "Notifications enabled" : "Notifications muted", body: this.toastsEnabled ? "You'll be notified when chapters finish downloading" : "Download notifications are silenced", duration: 2500 });
|
updateSettings({ downloadToastsEnabled: next });
|
||||||
|
addToast({ kind: "info", title: next ? "Notifications enabled" : "Notifications muted", body: next ? "You'll be notified when chapters finish downloading" : "Download notifications are silenced", duration: 2500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleAutoRetry() {
|
toggleAutoRetry() {
|
||||||
if (this.autoRetryEnabled) {
|
if (this.autoRetryEnabled) {
|
||||||
this.autoRetryHnd?.stop();
|
this.autoRetryHnd?.stop();
|
||||||
this.autoRetryHnd = null;
|
this.autoRetryHnd = null;
|
||||||
this.autoRetryEnabled = false;
|
updateSettings({ downloadAutoRetry: false });
|
||||||
addToast({ kind: "info", title: "Auto-retry disabled", body: "Failed downloads will no longer retry automatically", duration: 2500 });
|
addToast({ kind: "info", title: "Auto-retry disabled", body: "Failed downloads will no longer retry automatically", duration: 2500 });
|
||||||
} else {
|
} else {
|
||||||
this.autoRetryEnabled = true;
|
updateSettings({ downloadAutoRetry: true });
|
||||||
this.autoRetryHnd = startAutoRetry(
|
this.autoRetryHnd = startAutoRetry(
|
||||||
() => this.queue,
|
() => this.queue,
|
||||||
() => this.isRunning,
|
() => this.isRunning,
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ export interface Settings {
|
|||||||
trackerRespectScanlatorFilter: boolean;
|
trackerRespectScanlatorFilter: boolean;
|
||||||
pinchZoom?: boolean;
|
pinchZoom?: boolean;
|
||||||
autoLinkOnOpen: boolean;
|
autoLinkOnOpen: boolean;
|
||||||
|
downloadToastsEnabled: boolean;
|
||||||
|
downloadAutoRetry: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: Settings = {
|
export const DEFAULT_SETTINGS: Settings = {
|
||||||
@@ -163,4 +165,6 @@ export const DEFAULT_SETTINGS: Settings = {
|
|||||||
trackerRespectScanlatorFilter: true,
|
trackerRespectScanlatorFilter: true,
|
||||||
pinchZoom: false,
|
pinchZoom: false,
|
||||||
autoLinkOnOpen: false,
|
autoLinkOnOpen: false,
|
||||||
|
downloadToastsEnabled: true,
|
||||||
|
downloadAutoRetry: false,
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user