feat: Refactor settings management into a dedicated page with new configuration options, including live stream source and remote input settings

This commit is contained in:
zimplexing
2025-07-11 17:23:36 +08:00
parent fc8da352fb
commit 03d80c42cd
14 changed files with 607 additions and 215 deletions

View File

@@ -3,93 +3,62 @@ import { SettingsManager } from '@/services/storage';
import { api } from '@/services/api';
import useHomeStore from './homeStore';
export interface LiveStreamSource {
id: string;
name: string;
url: string;
enabled: boolean;
}
export interface PlaybackSourceConfig {
primarySource: string;
fallbackSources: string[];
enabledSources: string[];
}
interface SettingsState {
apiBaseUrl: string;
liveStreamSources: LiveStreamSource[];
m3uUrl: string;
remoteInputEnabled: boolean;
playbackSourceConfig: PlaybackSourceConfig;
videoSource: {
enabledAll: boolean;
sources: {
[key: string]: boolean;
};
};
isModalVisible: boolean;
loadSettings: () => Promise<void>;
setApiBaseUrl: (url: string) => void;
setLiveStreamSources: (sources: LiveStreamSource[]) => void;
addLiveStreamSource: (source: Omit<LiveStreamSource, 'id'>) => void;
removeLiveStreamSource: (id: string) => void;
updateLiveStreamSource: (id: string, updates: Partial<LiveStreamSource>) => void;
setM3uUrl: (url: string) => void;
setRemoteInputEnabled: (enabled: boolean) => void;
setPlaybackSourceConfig: (config: PlaybackSourceConfig) => void;
saveSettings: () => Promise<void>;
setVideoSource: (config: { enabledAll: boolean; sources: {[key: string]: boolean} }) => void;
showModal: () => void;
hideModal: () => void;
}
export const useSettingsStore = create<SettingsState>((set, get) => ({
apiBaseUrl: 'https://orion-tv.edu.deal',
apiBaseUrl: '',
m3uUrl: 'https://raw.githubusercontent.com/sjnhnp/adblock/refs/heads/main/filtered_http_only_valid.m3u',
liveStreamSources: [],
remoteInputEnabled: false,
playbackSourceConfig: {
primarySource: 'default',
fallbackSources: [],
enabledSources: ['default'],
},
isModalVisible: false,
videoSource: {
enabledAll: true,
sources: {},
},
loadSettings: async () => {
const settings = await SettingsManager.get();
set({
apiBaseUrl: settings.apiBaseUrl,
liveStreamSources: settings.liveStreamSources || [],
m3uUrl: settings.m3uUrl,
remoteInputEnabled: settings.remoteInputEnabled || false,
playbackSourceConfig: settings.playbackSourceConfig || {
primarySource: 'default',
fallbackSources: [],
enabledSources: ['default'],
videoSource: settings.videoSource || {
enabledAll: true,
sources: {},
},
});
api.setBaseUrl(settings.apiBaseUrl);
},
setApiBaseUrl: (url) => set({ apiBaseUrl: url }),
setLiveStreamSources: (sources) => set({ liveStreamSources: sources }),
addLiveStreamSource: (source) => {
const { liveStreamSources } = get();
const newSource = {
...source,
id: Date.now().toString(),
};
set({ liveStreamSources: [...liveStreamSources, newSource] });
},
removeLiveStreamSource: (id) => {
const { liveStreamSources } = get();
set({ liveStreamSources: liveStreamSources.filter(s => s.id !== id) });
},
updateLiveStreamSource: (id, updates) => {
const { liveStreamSources } = get();
set({
liveStreamSources: liveStreamSources.map(s =>
s.id === id ? { ...s, ...updates } : s
)
});
},
setM3uUrl: (url) => set({ m3uUrl: url }),
setRemoteInputEnabled: (enabled) => set({ remoteInputEnabled: enabled }),
setPlaybackSourceConfig: (config) => set({ playbackSourceConfig: config }),
setVideoSource: (config) => set({ videoSource: config }),
saveSettings: async () => {
const { apiBaseUrl, liveStreamSources, remoteInputEnabled, playbackSourceConfig } = get();
const { apiBaseUrl, m3uUrl, remoteInputEnabled, videoSource } = get();
await SettingsManager.save({
apiBaseUrl,
liveStreamSources,
m3uUrl,
remoteInputEnabled,
playbackSourceConfig,
videoSource,
});
api.setBaseUrl(apiBaseUrl);
set({ isModalVisible: false });