Fix: App Pin & Downloads (Filesystem Changes)

This commit is contained in:
Youwes09
2026-06-05 17:42:32 -05:00
parent 8aa92e6b54
commit 5dfbc80bbe
16 changed files with 577 additions and 490 deletions
+33 -24
View File
@@ -1,16 +1,14 @@
import { platformService } from '$lib/platform-service'
import { seriesState } from '$lib/state/series.svelte'
import { settingsState } from '$lib/state/settings.svelte'
import { addToast } from '$lib/state/notifications.svelte'
import type { Manga } from '$lib/types'
function sanitizeTitle(title: string): string {
return title.replace(/[\\/:*?"<>|]/g, '').replace(/\s+/g, ' ').trim()
function sanitize(s: string): string {
return s.replace(/[\\/:*?"<>|]/g, '').replace(/\s+/g, ' ').trim()
}
async function getDownloadsRoot(): Promise<string> {
let root = (seriesState.settings as any).downloadsPath?.trim() ?? ''
if (!root) root = await platformService.getDefaultDownloadsPath().catch(() => '')
return root
function getDownloadsRoot(): string {
return settingsState.settings?.serverDownloadsPath?.trim() ?? ''
}
function join(root: string, ...parts: string[]): string {
@@ -18,31 +16,42 @@ function join(root: string, ...parts: string[]): string {
return [root.replace(/[/\\]$/, ''), ...parts].join(sep)
}
export async function openMangaFolder(manga: Manga): Promise<void> {
function checkSupported(): boolean {
if (!platformService.isSupported('filesystem')) {
addToast({ kind: 'info', title: 'Desktop only', body: 'Opening folders requires the desktop app.' })
return
return false
}
const root = await getDownloadsRoot()
if (!root) return
await platformService.openPath(join(root, 'mangas', sanitizeTitle(manga.title))).catch(console.error)
return true
}
export async function openCustomFolder(path: string): Promise<void> {
if (!platformService.isSupported('filesystem')) {
addToast({ kind: 'info', title: 'Desktop only', body: 'Opening folders requires the desktop app.' })
return
function checkRoot(root: string): boolean {
if (!root) {
addToast({ kind: 'error', title: 'No downloads path set', body: 'Configure it in Settings → Storage' })
return false
}
if (!path?.trim()) return
return true
}
export async function openMangaFolder(manga: Manga): Promise<void> {
if (!checkSupported()) return
const root = getDownloadsRoot()
if (!checkRoot(root)) return
const source = (manga as any).source?.displayName ?? (manga as any).source?.name ?? ''
const path = source
? join(root, 'mangas', sanitize(source), sanitize(manga.title))
: join(root, 'mangas', sanitize(manga.title))
await platformService.openPath(path).catch(console.error)
}
export async function openDownloadsFolder(): Promise<void> {
if (!platformService.isSupported('filesystem')) {
addToast({ kind: 'info', title: 'Desktop only', body: 'Opening folders requires the desktop app.' })
return
}
const root = await getDownloadsRoot()
if (!root) return
await platformService.openPath(join(root, 'mangas')).catch(console.error)
if (!checkSupported()) return
const root = getDownloadsRoot()
if (!checkRoot(root)) return
await platformService.openPath(root).catch(console.error)
}
export async function openCustomFolder(path: string): Promise<void> {
if (!checkSupported()) return
if (!path?.trim()) return
await platformService.openPath(path).catch(console.error)
}