mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-20 12:40:15 +02:00
onboarding + eq fixes
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
type ScanProgress,
|
||||
type ScanResult,
|
||||
} from '@/library/scanner';
|
||||
import { endScanService, reportScanProgress } from '@/library/scanService';
|
||||
import { ALBUM_SORT_LABELS, type AlbumSort } from '@/lib/albumSort';
|
||||
import { ARTIST_SORT_LABELS, type ArtistSort } from '@/lib/artistSort';
|
||||
import { TRACK_SORT_LABELS, type TrackSort } from '@/lib/trackSort';
|
||||
@@ -114,7 +115,12 @@ interface LibraryStore {
|
||||
let initPromise: Promise<void> | null = null;
|
||||
|
||||
export const useLibraryStore = create<LibraryStore>((set, get) => {
|
||||
const onProgress = (progress: ScanProgress) => set({ scanProgress: progress });
|
||||
const onProgress = (progress: ScanProgress) => {
|
||||
set({ scanProgress: progress });
|
||||
// Mirror progress into the foreground-service notification (starts it on the
|
||||
// first tick) so a big scan keeps running + stays visible when backgrounded.
|
||||
void reportScanProgress(progress);
|
||||
};
|
||||
|
||||
/** Shared scan wrapper: progress/error state + refresh, scans never overlap. */
|
||||
const runScan = async (scan: () => Promise<ScanResult | null>) => {
|
||||
@@ -127,6 +133,7 @@ export const useLibraryStore = create<LibraryStore>((set, get) => {
|
||||
} finally {
|
||||
await get().refresh();
|
||||
set({ isScanning: false, scanProgress: { ...IDLE_PROGRESS } });
|
||||
endScanService();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { create } from 'zustand';
|
||||
import { openLibraryDb } from '@/db/database';
|
||||
import { getFolders, getSetting, setSetting } from '@/db/queries';
|
||||
|
||||
/**
|
||||
* First-run wizard gate. SQLite (settings table) is the source of truth, mirrored
|
||||
* in memory like the other pref stores. The wizard shows once on a fresh install
|
||||
* and never again once `onboardingComplete` is persisted.
|
||||
*/
|
||||
const ONBOARDING_COMPLETE_KEY = 'onboarding_complete';
|
||||
|
||||
interface OnboardingStore {
|
||||
onboardingComplete: boolean;
|
||||
loaded: boolean;
|
||||
load: () => Promise<void>;
|
||||
markComplete: () => Promise<void>;
|
||||
/** Dev affordance: re-arm the wizard (see Experimental settings). */
|
||||
reset: () => Promise<void>;
|
||||
}
|
||||
|
||||
export const useOnboardingStore = create<OnboardingStore>((set, get) => ({
|
||||
onboardingComplete: false,
|
||||
loaded: false,
|
||||
|
||||
load: async () => {
|
||||
if (get().loaded) return;
|
||||
const db = await openLibraryDb();
|
||||
const value = await getSetting(db, ONBOARDING_COMPLETE_KEY);
|
||||
if (value !== null) {
|
||||
set({ onboardingComplete: value === 'true', loaded: true });
|
||||
return;
|
||||
}
|
||||
// Flag never set: an install that already has library folders predates this
|
||||
// wizard — treat it as onboarded (and persist) so the wizard never ambushes
|
||||
// an upgrading user. A genuinely fresh install has no folders → show it.
|
||||
const folders = await getFolders(db);
|
||||
const complete = folders.length > 0;
|
||||
if (complete) await setSetting(db, ONBOARDING_COMPLETE_KEY, 'true');
|
||||
set({ onboardingComplete: complete, loaded: true });
|
||||
},
|
||||
|
||||
markComplete: async () => {
|
||||
set({ onboardingComplete: true });
|
||||
const db = await openLibraryDb();
|
||||
await setSetting(db, ONBOARDING_COMPLETE_KEY, 'true');
|
||||
},
|
||||
|
||||
reset: async () => {
|
||||
set({ onboardingComplete: false });
|
||||
const db = await openLibraryDb();
|
||||
await setSetting(db, ONBOARDING_COMPLETE_KEY, 'false');
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user