mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-14 01:39:56 -05:00
Fix: Filesystem Platform-based Folder Buttons
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
MagnifyingGlass, Books, DownloadSimple, Folder, FolderSimple,
|
MagnifyingGlass, Books, DownloadSimple, Folder, FolderSimple,
|
||||||
SortAscending, CaretUp, CaretDown, ArrowsClockwise, Star, X, CheckSquare,
|
SortAscending, CaretUp, CaretDown, ArrowsClockwise, Star, X, CheckSquare,
|
||||||
} from "phosphor-svelte";
|
} from "phosphor-svelte";
|
||||||
|
import { canOpenFolder } from "$lib/core/filesystem";
|
||||||
import LibraryFilters from "./LibraryFilters.svelte";
|
import LibraryFilters from "./LibraryFilters.svelte";
|
||||||
import type { Category } from "$lib/types";
|
import type { Category } from "$lib/types";
|
||||||
import type { LibrarySortOption, LibrarySortDir, LibraryStatusFilter, LibraryContentFilter } from "$lib/state/library.svelte";
|
import type { LibrarySortOption, LibrarySortDir, LibraryStatusFilter, LibraryContentFilter } from "$lib/state/library.svelte";
|
||||||
@@ -165,9 +166,11 @@
|
|||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if canOpenFolder()}
|
||||||
<button class="icon-btn" title="Open downloads folder" onclick={onOpenDownloadsFolder}>
|
<button class="icon-btn" title="Open downloads folder" onclick={onOpenDownloadsFolder}>
|
||||||
<FolderSimple size={15} weight="bold" />
|
<FolderSimple size={15} weight="bold" />
|
||||||
</button>
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="sort-panel-wrap">
|
<div class="sort-panel-wrap">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
CaretDown, ArrowsClockwise, List, SquaresFour, FolderSimplePlus,
|
CaretDown, ArrowsClockwise, List, SquaresFour, FolderSimplePlus,
|
||||||
Trash, DownloadSimple, X, MagnifyingGlass, Funnel, Check, FolderOpen,
|
Trash, DownloadSimple, X, MagnifyingGlass, Funnel, Check, FolderOpen,
|
||||||
} from 'phosphor-svelte'
|
} from 'phosphor-svelte'
|
||||||
|
import { canOpenFolder } from '$lib/core/filesystem'
|
||||||
import type { Chapter, Category } from '$lib/types'
|
import type { Chapter, Category } from '$lib/types'
|
||||||
import type { ChapterSortMode, ChapterSortDir } from './lib/chapterList'
|
import type { ChapterSortMode, ChapterSortDir } from './lib/chapterList'
|
||||||
|
|
||||||
@@ -275,7 +276,7 @@
|
|||||||
<ArrowsClockwise size={14} weight="light" class={refreshing ? 'anim-spin' : ''} />
|
<ArrowsClockwise size={14} weight="light" class={refreshing ? 'anim-spin' : ''} />
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{#if downloadedCount > 0}
|
{#if downloadedCount > 0 && canOpenFolder()}
|
||||||
<button class="icon-btn" onclick={onOpenFolder} title="Open manga folder">
|
<button class="icon-btn" onclick={onOpenFolder} title="Open manga folder">
|
||||||
<FolderOpen size={14} weight="light" />
|
<FolderOpen size={14} weight="light" />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -16,11 +16,28 @@ function join(root: string, ...parts: string[]): string {
|
|||||||
return [root.replace(/[/\\]$/, ''), ...parts].join(sep)
|
return [root.replace(/[/\\]$/, ''), ...parts].join(sep)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkSupported(): boolean {
|
function isLocalServer(): boolean {
|
||||||
|
try {
|
||||||
|
const host = new URL(settingsState.settings.serverUrl).hostname
|
||||||
|
return host === 'localhost' || host === '127.0.0.1' || host === '::1'
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canOpenFolder(): boolean {
|
||||||
|
return platformService.isSupported('filesystem') && isLocalServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkCanOpenFolder(): boolean {
|
||||||
if (!platformService.isSupported('filesystem')) {
|
if (!platformService.isSupported('filesystem')) {
|
||||||
addToast({ kind: 'info', title: 'Desktop only', body: 'Opening folders requires the desktop app.' })
|
addToast({ kind: 'info', title: 'Desktop only', body: 'Opening folders requires the desktop app.' })
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (!isLocalServer()) {
|
||||||
|
addToast({ kind: 'info', title: 'Remote server', body: 'Folder access is unavailable when connected to a remote server.' })
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +50,7 @@ function checkRoot(root: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openMangaFolder(manga: Manga): Promise<void> {
|
export async function openMangaFolder(manga: Manga): Promise<void> {
|
||||||
if (!checkSupported()) return
|
if (!checkCanOpenFolder()) return
|
||||||
const root = getDownloadsRoot()
|
const root = getDownloadsRoot()
|
||||||
if (!checkRoot(root)) return
|
if (!checkRoot(root)) return
|
||||||
const source = (manga as any).source?.displayName ?? (manga as any).source?.name ?? ''
|
const source = (manga as any).source?.displayName ?? (manga as any).source?.name ?? ''
|
||||||
@@ -44,14 +61,14 @@ export async function openMangaFolder(manga: Manga): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function openDownloadsFolder(): Promise<void> {
|
export async function openDownloadsFolder(): Promise<void> {
|
||||||
if (!checkSupported()) return
|
if (!checkCanOpenFolder()) return
|
||||||
const root = getDownloadsRoot()
|
const root = getDownloadsRoot()
|
||||||
if (!checkRoot(root)) return
|
if (!checkRoot(root)) return
|
||||||
await platformService.openPath(root).catch(console.error)
|
await platformService.openPath(root).catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function openCustomFolder(path: string): Promise<void> {
|
export async function openCustomFolder(path: string): Promise<void> {
|
||||||
if (!checkSupported()) return
|
if (!checkCanOpenFolder()) return
|
||||||
if (!path?.trim()) return
|
if (!path?.trim()) return
|
||||||
await platformService.openPath(path).catch(console.error)
|
await platformService.openPath(path).catch(console.error)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user