feishin/src/renderer/store/settings.store.ts

282 lines
7.2 KiB
TypeScript
Raw Normal View History

2022-12-19 15:59:14 -08:00
/* eslint-disable prefer-destructuring */
/* eslint-disable @typescript-eslint/no-unused-vars */
import merge from 'lodash/merge';
import create from 'zustand';
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
2023-03-28 23:59:51 -07:00
import shallow from 'zustand/shallow';
2022-12-19 15:59:14 -08:00
import { AppTheme } from '/@/renderer/themes/types';
import {
TableColumn,
CrossfadeStyle,
Play,
PlaybackStyle,
PlaybackType,
TableType,
2023-03-28 23:59:51 -07:00
Platform,
2022-12-19 15:59:14 -08:00
} from '/@/renderer/types';
export type PersistedTableColumn = {
column: TableColumn;
width: number;
};
export type DataTableProps = {
autoFit: boolean;
columns: PersistedTableColumn[];
followCurrentSong?: boolean;
rowHeight: number;
};
export type SideQueueType = 'sideQueue' | 'sideDrawerQueue';
export interface SettingsState {
general: {
followSystemTheme: boolean;
fontContent: string;
2023-03-30 06:44:33 -07:00
playButtonBehavior: Play;
2022-12-19 15:59:14 -08:00
showQueueDrawerButton: boolean;
sideQueueType: SideQueueType;
2023-03-30 06:44:33 -07:00
skipButtons: {
enabled: boolean;
skipBackwardSeconds: number;
skipForwardSeconds: number;
};
2022-12-19 15:59:14 -08:00
theme: AppTheme;
themeDark: AppTheme;
themeLight: AppTheme;
volumeWheelStep: number;
2022-12-19 15:59:14 -08:00
};
2023-03-30 06:44:33 -07:00
playback: {
2022-12-19 15:59:14 -08:00
audioDeviceId?: string | null;
crossfadeDuration: number;
crossfadeStyle: CrossfadeStyle;
globalMediaHotkeys: boolean;
muted: boolean;
scrobble: {
enabled: boolean;
scrobbleAtDuration: number;
2022-12-19 15:59:14 -08:00
scrobbleAtPercentage: number;
};
2023-03-30 06:44:33 -07:00
2022-12-19 15:59:14 -08:00
style: PlaybackStyle;
type: PlaybackType;
};
2023-03-30 06:44:33 -07:00
tab: 'general' | 'playback' | 'window' | string;
2022-12-19 15:59:14 -08:00
tables: {
fullScreen: DataTableProps;
2022-12-19 15:59:14 -08:00
nowPlaying: DataTableProps;
sideDrawerQueue: DataTableProps;
sideQueue: DataTableProps;
songs: DataTableProps;
};
2023-03-30 06:44:33 -07:00
window: {
2023-03-31 05:42:48 -07:00
disableAutoUpdate: boolean;
2023-03-30 08:09:20 -07:00
exitToTray: boolean;
minimizeToTray: boolean;
2023-03-30 06:44:33 -07:00
windowBarStyle: Platform;
};
2022-12-19 15:59:14 -08:00
}
export interface SettingsSlice extends SettingsState {
actions: {
setSettings: (data: Partial<SettingsState>) => void;
};
}
export const useSettingsStore = create<SettingsSlice>()(
persist(
devtools(
immer((set, get) => ({
actions: {
setSettings: (data) => {
set({ ...get(), ...data });
},
},
general: {
followSystemTheme: false,
2022-12-30 21:04:30 -08:00
fontContent: 'Poppins',
2023-03-30 06:44:33 -07:00
playButtonBehavior: Play.NOW,
2022-12-19 16:19:45 -08:00
showQueueDrawerButton: false,
sideQueueType: 'sideDrawerQueue',
2023-03-30 06:44:33 -07:00
skipButtons: {
enabled: false,
skipBackwardSeconds: 5,
skipForwardSeconds: 10,
},
2022-12-19 15:59:14 -08:00
theme: AppTheme.DEFAULT_DARK,
themeDark: AppTheme.DEFAULT_DARK,
themeLight: AppTheme.DEFAULT_LIGHT,
volumeWheelStep: 5,
2022-12-19 15:59:14 -08:00
},
2023-03-30 06:44:33 -07:00
playback: {
2022-12-19 15:59:14 -08:00
audioDeviceId: undefined,
crossfadeDuration: 5,
crossfadeStyle: CrossfadeStyle.EQUALPOWER,
2022-12-19 16:19:45 -08:00
globalMediaHotkeys: false,
2022-12-19 15:59:14 -08:00
muted: false,
scrobble: {
enabled: true,
scrobbleAtDuration: 240,
2022-12-19 15:59:14 -08:00
scrobbleAtPercentage: 75,
},
2023-03-30 06:44:33 -07:00
2022-12-19 15:59:14 -08:00
style: PlaybackStyle.GAPLESS,
type: PlaybackType.LOCAL,
},
tab: 'general',
tables: {
fullScreen: {
autoFit: true,
columns: [
{
column: TableColumn.TITLE_COMBINED,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
{
column: TableColumn.USER_FAVORITE,
width: 100,
},
],
followCurrentSong: true,
rowHeight: 60,
},
2022-12-19 15:59:14 -08:00
nowPlaying: {
autoFit: true,
columns: [
{
column: TableColumn.ROW_INDEX,
width: 50,
},
{
column: TableColumn.TITLE,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
{
column: TableColumn.ALBUM,
width: 100,
},
{
column: TableColumn.ALBUM_ARTIST,
width: 100,
},
{
column: TableColumn.GENRE,
width: 100,
},
{
column: TableColumn.YEAR,
width: 100,
},
],
followCurrentSong: true,
rowHeight: 30,
},
sideDrawerQueue: {
autoFit: true,
columns: [
{
column: TableColumn.TITLE_COMBINED,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
],
followCurrentSong: true,
rowHeight: 60,
},
sideQueue: {
autoFit: true,
columns: [
{
column: TableColumn.ROW_INDEX,
width: 50,
},
{
column: TableColumn.TITLE_COMBINED,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
],
followCurrentSong: true,
rowHeight: 60,
},
songs: {
autoFit: true,
columns: [
{
column: TableColumn.ROW_INDEX,
width: 50,
},
{
column: TableColumn.TITLE_COMBINED,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
{
column: TableColumn.ALBUM,
width: 300,
},
{
column: TableColumn.ARTIST,
width: 100,
},
{
column: TableColumn.YEAR,
width: 100,
},
],
rowHeight: 60,
},
},
2023-03-30 06:44:33 -07:00
window: {
2023-03-31 05:42:48 -07:00
disableAutoUpdate: true,
2023-03-30 08:09:20 -07:00
exitToTray: false,
minimizeToTray: false,
2023-03-30 06:44:33 -07:00
windowBarStyle: Platform.WEB,
},
2022-12-19 15:59:14 -08:00
})),
{ name: 'store_settings' },
),
{
merge: (persistedState, currentState) => {
return merge(currentState, persistedState);
},
name: 'store_settings',
2023-03-30 06:44:33 -07:00
version: 5,
2022-12-19 15:59:14 -08:00
},
),
);
export const useSettingsStoreActions = () => useSettingsStore((state) => state.actions);
2023-03-30 06:44:33 -07:00
export const usePlaybackSettings = () => useSettingsStore((state) => state.playback, shallow);
2022-12-19 15:59:14 -08:00
export const useTableSettings = (type: TableType) =>
useSettingsStore((state) => state.tables[type]);
2023-03-28 23:59:51 -07:00
export const useGeneralSettings = () => useSettingsStore((state) => state.general, shallow);
2022-12-25 01:55:00 -08:00
2023-03-30 06:44:33 -07:00
export const usePlayerType = () => useSettingsStore((state) => state.playback.type, shallow);
export const usePlayButtonBehavior = () =>
2023-03-30 06:44:33 -07:00
useSettingsStore((state) => state.general.playButtonBehavior, shallow);
export const useWindowSettings = () => useSettingsStore((state) => state.window, shallow);