mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-04 11:44:44 +08:00
- Added login/logout buttons to the HomeScreen and SettingsScreen. - Integrated authentication state management using Zustand and cookies. - Updated API to support username and password for login. - Enhanced PlayScreen to handle video playback based on user authentication. - Created a new detailStore to manage video details and sources. - Refactored playerStore to utilize detailStore for episode management. - Added sourceStore to manage video source toggling. - Updated settingsStore to fetch server configuration. - Improved error handling and user feedback with Toast notifications. - Cleaned up unused code and optimized imports across components.
81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import { create } from 'zustand';
|
|
import { SettingsManager } from '@/services/storage';
|
|
import { api, ServerConfig } from '@/services/api';
|
|
import useHomeStore from './homeStore';
|
|
|
|
|
|
interface SettingsState {
|
|
apiBaseUrl: string;
|
|
m3uUrl: string;
|
|
remoteInputEnabled: boolean;
|
|
videoSource: {
|
|
enabledAll: boolean;
|
|
sources: {
|
|
[key: string]: boolean;
|
|
};
|
|
};
|
|
isModalVisible: boolean;
|
|
serverConfig: ServerConfig | null;
|
|
loadSettings: () => Promise<void>;
|
|
fetchServerConfig: () => Promise<void>;
|
|
setApiBaseUrl: (url: string) => void;
|
|
setM3uUrl: (url: string) => void;
|
|
setRemoteInputEnabled: (enabled: boolean) => 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: '',
|
|
m3uUrl: 'https://raw.githubusercontent.com/sjnhnp/adblock/refs/heads/main/filtered_http_only_valid.m3u',
|
|
liveStreamSources: [],
|
|
remoteInputEnabled: false,
|
|
isModalVisible: false,
|
|
serverConfig: null,
|
|
videoSource: {
|
|
enabledAll: true,
|
|
sources: {},
|
|
},
|
|
loadSettings: async () => {
|
|
const settings = await SettingsManager.get();
|
|
set({
|
|
apiBaseUrl: settings.apiBaseUrl,
|
|
m3uUrl: settings.m3uUrl,
|
|
remoteInputEnabled: settings.remoteInputEnabled || false,
|
|
videoSource: settings.videoSource || {
|
|
enabledAll: true,
|
|
sources: {},
|
|
},
|
|
});
|
|
api.setBaseUrl(settings.apiBaseUrl);
|
|
await get().fetchServerConfig();
|
|
},
|
|
fetchServerConfig: async () => {
|
|
try {
|
|
const config = await api.getServerConfig();
|
|
set({ serverConfig: config });
|
|
} catch (error) {
|
|
console.error("Failed to fetch server config:", error);
|
|
}
|
|
},
|
|
setApiBaseUrl: (url) => set({ apiBaseUrl: url }),
|
|
setM3uUrl: (url) => set({ m3uUrl: url }),
|
|
setRemoteInputEnabled: (enabled) => set({ remoteInputEnabled: enabled }),
|
|
setVideoSource: (config) => set({ videoSource: config }),
|
|
saveSettings: async () => {
|
|
const { apiBaseUrl, m3uUrl, remoteInputEnabled, videoSource } = get();
|
|
await SettingsManager.save({
|
|
apiBaseUrl,
|
|
m3uUrl,
|
|
remoteInputEnabled,
|
|
videoSource,
|
|
});
|
|
api.setBaseUrl(apiBaseUrl);
|
|
set({ isModalVisible: false });
|
|
useHomeStore.getState().fetchInitialData();
|
|
},
|
|
showModal: () => set({ isModalVisible: true }),
|
|
hideModal: () => set({ isModalVisible: false }),
|
|
})); |