mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-20 12:40:15 +02:00
improve desktop remote
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
import { openLibraryDb } from '@/db/database';
|
||||
import { clearPlaylistSyncBaselines } from '@/db/desktopSyncQueries';
|
||||
import { useDesktopSyncStore } from '@/stores/desktopSyncStore';
|
||||
import { usePlaybackTargetStore } from '@/stores/playbackTargetStore';
|
||||
import type {
|
||||
DesktopRemoteConnection,
|
||||
DesktopRemoteControlCommand,
|
||||
@@ -279,6 +280,7 @@ export const useDesktopRemoteStore = create<DesktopRemoteStore>((set, get) => {
|
||||
message: 'Paired. Connecting...',
|
||||
errorMessage: '',
|
||||
});
|
||||
void usePlaybackTargetStore.getState().setTarget('desktop');
|
||||
void get().connect();
|
||||
return;
|
||||
}
|
||||
@@ -423,6 +425,7 @@ export const useDesktopRemoteStore = create<DesktopRemoteStore>((set, get) => {
|
||||
message: 'Paired. Connecting...',
|
||||
errorMessage: '',
|
||||
});
|
||||
void usePlaybackTargetStore.getState().setTarget('desktop');
|
||||
void get().connect();
|
||||
} catch (error) {
|
||||
if (error instanceof DesktopRemoteHttpError && error.status === 401) {
|
||||
@@ -628,6 +631,7 @@ export const useDesktopRemoteStore = create<DesktopRemoteStore>((set, get) => {
|
||||
pinPairing: null,
|
||||
message: '',
|
||||
});
|
||||
void usePlaybackTargetStore.getState().setTarget('phone');
|
||||
},
|
||||
|
||||
sendControl: async (command, time) => {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { create } from 'zustand';
|
||||
import { openLibraryDb } from '@/db/database';
|
||||
import { getSetting, setSetting } from '@/db/queries';
|
||||
|
||||
const PLAYBACK_TARGET_KEY = 'playback_target';
|
||||
|
||||
export type PlaybackTarget = 'phone' | 'desktop';
|
||||
|
||||
function parsePlaybackTarget(value: string | null): PlaybackTarget {
|
||||
return value === 'desktop' ? 'desktop' : 'phone';
|
||||
}
|
||||
|
||||
interface PlaybackTargetStore {
|
||||
target: PlaybackTarget;
|
||||
loaded: boolean;
|
||||
load: () => Promise<void>;
|
||||
setTarget: (target: PlaybackTarget) => Promise<void>;
|
||||
}
|
||||
|
||||
export const usePlaybackTargetStore = create<PlaybackTargetStore>((set, get) => ({
|
||||
target: 'phone',
|
||||
loaded: false,
|
||||
|
||||
load: async () => {
|
||||
if (get().loaded) return;
|
||||
const db = await openLibraryDb();
|
||||
const stored = await getSetting(db, PLAYBACK_TARGET_KEY);
|
||||
set({ target: parsePlaybackTarget(stored), loaded: true });
|
||||
},
|
||||
|
||||
setTarget: async (target) => {
|
||||
if (get().target === target && get().loaded) return;
|
||||
set({ target, loaded: true });
|
||||
const db = await openLibraryDb();
|
||||
await setSetting(db, PLAYBACK_TARGET_KEY, target);
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user