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

802 lines
25 KiB
TypeScript
Raw Normal View History

import type { ContextMenuItemType } from '/@/renderer/features/context-menu';
2023-05-20 18:41:24 -07:00
import { ColDef } from '@ag-grid-community/core';
2023-03-31 05:56:32 -07:00
import isElectron from 'is-electron';
2023-06-03 05:36:38 -07:00
import { generatePath } from 'react-router';
2023-05-20 20:00:09 -07:00
import { create } from 'zustand';
2022-12-19 15:59:14 -08:00
import { devtools, persist } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';
2023-05-10 18:45:22 -07:00
import { shallow } from 'zustand/shallow';
import i18n from '/@/i18n/i18n';
2023-06-03 00:39:33 -07:00
import { AppRoute } from '/@/renderer/router/routes';
import { usePlayerStore } from '/@/renderer/store/player.store';
import { mergeOverridingColumns } from '/@/renderer/store/utils';
2025-05-20 19:23:36 -07:00
import { randomString } from '/@/renderer/utils';
import { AppTheme } from '/@/shared/types/domain-types';
import { LibraryItem, LyricSource } from '/@/shared/types/domain-types';
2022-12-19 15:59:14 -08:00
import {
2023-07-01 19:10:05 -07:00
CrossfadeStyle,
FontType,
Platform,
2023-07-01 19:10:05 -07:00
Play,
PlaybackStyle,
PlaybackType,
TableColumn,
2023-07-01 19:10:05 -07:00
TableType,
2025-05-20 19:23:36 -07:00
} from '/@/shared/types/types';
2022-12-19 15:59:14 -08:00
const utils = isElectron() ? window.api.utils : null;
2023-06-03 00:39:33 -07:00
export type SidebarItemType = {
2023-07-01 19:10:05 -07:00
disabled: boolean;
id: string;
label: string;
route: AppRoute | string;
2023-06-03 00:39:33 -07:00
};
2025-04-23 23:27:06 -07:00
export const sidebarItems: SidebarItemType[] = [
{
disabled: true,
id: 'Now Playing',
label: i18n.t('page.sidebar.nowPlaying'),
route: AppRoute.NOW_PLAYING,
},
2023-07-01 19:10:05 -07:00
{
disabled: true,
id: 'Search',
label: i18n.t('page.sidebar.search'),
2023-07-01 19:10:05 -07:00
route: generatePath(AppRoute.SEARCH, { itemType: LibraryItem.SONG }),
},
{ disabled: false, id: 'Home', label: i18n.t('page.sidebar.home'), route: AppRoute.HOME },
{
disabled: false,
id: 'Albums',
label: i18n.t('page.sidebar.albums'),
route: AppRoute.LIBRARY_ALBUMS,
},
{
disabled: false,
id: 'Tracks',
label: i18n.t('page.sidebar.tracks'),
route: AppRoute.LIBRARY_SONGS,
},
2023-07-01 19:10:05 -07:00
{
disabled: false,
id: 'Artists',
2025-04-23 23:27:06 -07:00
label: i18n.t('page.sidebar.albumArtists'),
2023-07-01 19:10:05 -07:00
route: AppRoute.LIBRARY_ALBUM_ARTISTS,
},
2025-04-23 23:27:06 -07:00
{
disabled: false,
id: 'Artists-all',
label: i18n.t('page.sidebar.artists'),
route: AppRoute.LIBRARY_ARTISTS,
},
{
disabled: false,
id: 'Genres',
label: i18n.t('page.sidebar.genres'),
route: AppRoute.LIBRARY_GENRES,
},
{
disabled: true,
id: 'Playlists',
label: i18n.t('page.sidebar.playlists'),
route: AppRoute.PLAYLISTS,
},
{
disabled: true,
id: 'Settings',
label: i18n.t('page.sidebar.settings'),
route: AppRoute.SETTINGS,
},
2023-06-03 00:39:33 -07:00
];
export enum HomeItem {
MOST_PLAYED = 'mostPlayed',
RANDOM = 'random',
RECENTLY_ADDED = 'recentlyAdded',
RECENTLY_PLAYED = 'recentlyPlayed',
}
export type SortableItem<T> = {
disabled: boolean;
id: T;
};
2024-09-01 16:48:43 -07:00
const homeItems = Object.values(HomeItem).map((item) => ({
disabled: false,
id: item,
}));
export enum ArtistItem {
BIOGRAPHY = 'biography',
COMPILATIONS = 'compilations',
RECENT_ALBUMS = 'recentAlbums',
2024-09-01 16:48:43 -07:00
SIMILAR_ARTISTS = 'similarArtists',
TOP_SONGS = 'topSongs',
2024-09-01 16:48:43 -07:00
}
const artistItems = Object.values(ArtistItem).map((item) => ({
disabled: false,
id: item,
}));
export enum BindingActions {
BROWSER_BACK = 'browserBack',
BROWSER_FORWARD = 'browserForward',
FAVORITE_CURRENT_ADD = 'favoriteCurrentAdd',
FAVORITE_CURRENT_REMOVE = 'favoriteCurrentRemove',
FAVORITE_CURRENT_TOGGLE = 'favoriteCurrentToggle',
FAVORITE_PREVIOUS_ADD = 'favoritePreviousAdd',
FAVORITE_PREVIOUS_REMOVE = 'favoritePreviousRemove',
FAVORITE_PREVIOUS_TOGGLE = 'favoritePreviousToggle',
2023-07-01 19:10:05 -07:00
GLOBAL_SEARCH = 'globalSearch',
LOCAL_SEARCH = 'localSearch',
MUTE = 'volumeMute',
NEXT = 'next',
PAUSE = 'pause',
PLAY = 'play',
PLAY_PAUSE = 'playPause',
PREVIOUS = 'previous',
2023-09-23 03:20:04 -07:00
RATE_0 = 'rate0',
RATE_1 = 'rate1',
RATE_2 = 'rate2',
RATE_3 = 'rate3',
RATE_4 = 'rate4',
RATE_5 = 'rate5',
2023-07-01 19:10:05 -07:00
SHUFFLE = 'toggleShuffle',
SKIP_BACKWARD = 'skipBackward',
SKIP_FORWARD = 'skipForward',
STOP = 'stop',
TOGGLE_FULLSCREEN_PLAYER = 'toggleFullscreenPlayer',
TOGGLE_QUEUE = 'toggleQueue',
TOGGLE_REPEAT = 'toggleRepeat',
VOLUME_DOWN = 'volumeDown',
VOLUME_UP = 'volumeUp',
ZOOM_IN = 'zoomIn',
ZOOM_OUT = 'zoomOut',
}
export enum GenreTarget {
ALBUM = 'album',
TRACK = 'track',
}
export type DataTableProps = {
autoFit: boolean;
columns: PersistedTableColumn[];
followCurrentSong?: boolean;
rowHeight: number;
};
export type PersistedTableColumn = {
column: TableColumn;
extraProps?: Partial<ColDef>;
width: number;
2024-09-01 08:26:30 -07:00
};
export interface SettingsSlice extends SettingsState {
actions: {
reset: () => void;
resetSampleRate: () => void;
setArtistItems: (item: SortableItem<ArtistItem>[]) => void;
setGenreBehavior: (target: GenreTarget) => void;
setHomeItems: (item: SortableItem<HomeItem>[]) => void;
setSettings: (data: Partial<SettingsState>) => void;
setSidebarItems: (items: SidebarItemType[]) => void;
setTable: (type: TableType, data: DataTableProps) => void;
setTranscodingConfig: (config: TranscodingConfig) => void;
toggleContextMenuItem: (item: ContextMenuItemType) => void;
toggleSidebarCollapseShare: () => void;
};
}
2022-12-19 15:59:14 -08:00
export interface SettingsState {
2024-08-27 08:26:34 -07:00
css: {
content: string;
enabled: boolean;
};
2023-10-23 06:58:39 -07:00
discord: {
clientId: string;
enabled: boolean;
enableIdle: boolean;
showAsListening: boolean;
2023-10-23 06:58:39 -07:00
showServerImage: boolean;
updateInterval: number;
};
font: {
builtIn: string;
custom: null | string;
system: null | string;
type: FontType;
};
2023-07-01 19:10:05 -07:00
general: {
accent: string;
albumArtRes?: null | number;
albumBackground: boolean;
albumBackgroundBlur: number;
2024-09-01 16:48:43 -07:00
artistItems: SortableItem<ArtistItem>[];
buttonSize: number;
2024-08-26 21:35:12 -07:00
disabledContextMenu: { [k in ContextMenuItemType]?: boolean };
doubleClickQueueAll: boolean;
2024-01-15 22:10:50 -08:00
externalLinks: boolean;
2023-07-01 19:10:05 -07:00
followSystemTheme: boolean;
genreTarget: GenreTarget;
homeFeature: boolean;
homeItems: SortableItem<HomeItem>[];
language: string;
lastFM: boolean;
lastfmApiKey: string;
musicBrainz: boolean;
nativeAspectRatio: boolean;
passwordStore?: string;
2023-07-01 19:10:05 -07:00
playButtonBehavior: Play;
playerbarOpenDrawer: boolean;
2023-07-01 19:10:05 -07:00
resume: boolean;
showQueueDrawerButton: boolean;
sidebarCollapsedNavigation: boolean;
sidebarCollapseShared: boolean;
2023-07-01 19:10:05 -07:00
sidebarItems: SidebarItemType[];
sidebarPlaylistList: boolean;
sideQueueType: SideQueueType;
2023-07-01 19:10:05 -07:00
skipButtons: {
enabled: boolean;
skipBackwardSeconds: number;
skipForwardSeconds: number;
};
theme: AppTheme;
themeDark: AppTheme;
themeLight: AppTheme;
volumeWheelStep: number;
volumeWidth: number;
2023-07-01 19:10:05 -07:00
zoomFactor: number;
};
hotkeys: {
bindings: Record<
BindingActions,
{ allowGlobal: boolean; hotkey: string; isGlobal: boolean }
>;
globalMediaHotkeys: boolean;
2023-03-30 06:44:33 -07:00
};
2023-07-01 19:10:05 -07:00
lyrics: {
alignment: 'center' | 'left' | 'right';
2023-07-01 19:10:05 -07:00
delayMs: number;
enableNeteaseTranslation: boolean;
2023-07-01 19:10:05 -07:00
fetch: boolean;
follow: boolean;
fontSize: number;
fontSizeUnsync: number;
gap: number;
gapUnsync: number;
showMatch: boolean;
showProvider: boolean;
2023-07-01 19:10:05 -07:00
sources: LyricSource[];
translationApiKey: string;
translationApiProvider: null | string;
translationTargetLanguage: null | string;
2023-07-01 19:10:05 -07:00
};
playback: {
audioDeviceId?: null | string;
2023-07-01 19:10:05 -07:00
crossfadeDuration: number;
crossfadeStyle: CrossfadeStyle;
mpvExtraParameters: string[];
mpvProperties: MpvSettings;
muted: boolean;
scrobble: {
enabled: boolean;
scrobbleAtDuration: number;
scrobbleAtPercentage: number;
};
style: PlaybackStyle;
2024-09-01 08:26:30 -07:00
transcode: TranscodingConfig;
2023-07-01 19:10:05 -07:00
type: PlaybackType;
2024-08-29 19:44:24 -07:00
webAudio: boolean;
2023-07-01 19:10:05 -07:00
};
remote: {
enabled: boolean;
password: string;
port: number;
username: string;
};
tab: 'general' | 'hotkeys' | 'playback' | 'window' | string;
2023-07-01 19:10:05 -07:00
tables: {
2023-08-08 08:28:40 -07:00
albumDetail: DataTableProps;
2023-07-01 19:10:05 -07:00
fullScreen: DataTableProps;
nowPlaying: DataTableProps;
sideDrawerQueue: DataTableProps;
sideQueue: DataTableProps;
songs: DataTableProps;
};
window: {
disableAutoUpdate: boolean;
exitToTray: boolean;
minimizeToTray: boolean;
startMinimized: boolean;
2024-09-08 20:55:07 -07:00
tray: boolean;
2023-07-01 19:10:05 -07:00
windowBarStyle: Platform;
2022-12-19 15:59:14 -08:00
};
}
export type SideQueueType = 'sideDrawerQueue' | 'sideQueue';
export type TranscodingConfig = {
bitrate?: number;
enabled: boolean;
format?: string;
};
type MpvSettings = {
audioExclusiveMode: 'no' | 'yes';
audioFormat?: 'float' | 's16' | 's32';
audioSampleRateHz?: number;
gaplessAudio: 'no' | 'weak' | 'yes';
replayGainClip: boolean;
replayGainFallbackDB?: number;
replayGainMode: 'album' | 'no' | 'track';
replayGainPreampDB?: number;
};
2022-12-19 15:59:14 -08:00
// Determines the default/initial windowBarStyle value based on the current platform.
const getPlatformDefaultWindowBarStyle = (): Platform => {
return utils ? (utils.isMacOS() ? Platform.MACOS : Platform.WINDOWS) : Platform.WEB;
};
const platformDefaultWindowBarStyle: Platform = getPlatformDefaultWindowBarStyle();
2023-03-31 05:56:32 -07:00
const initialState: SettingsState = {
2024-08-27 08:26:34 -07:00
css: {
content: '',
enabled: false,
},
2023-10-23 06:58:39 -07:00
discord: {
clientId: '1165957668758900787',
enabled: false,
enableIdle: false,
showAsListening: false,
2023-10-23 06:58:39 -07:00
showServerImage: false,
updateInterval: 15,
},
font: {
builtIn: 'Inter',
custom: null,
system: null,
type: FontType.BUILT_IN,
},
2023-07-01 19:10:05 -07:00
general: {
accent: 'rgb(53, 116, 252)',
albumArtRes: undefined,
albumBackground: false,
albumBackgroundBlur: 6,
2024-09-01 16:48:43 -07:00
artistItems,
buttonSize: 20,
2024-08-26 21:35:12 -07:00
disabledContextMenu: {},
doubleClickQueueAll: true,
2024-02-01 04:14:02 -08:00
externalLinks: true,
2023-07-01 19:10:05 -07:00
followSystemTheme: false,
genreTarget: GenreTarget.TRACK,
homeFeature: true,
homeItems,
language: 'en',
lastFM: true,
lastfmApiKey: '',
musicBrainz: true,
nativeAspectRatio: false,
passwordStore: undefined,
2023-07-01 19:10:05 -07:00
playButtonBehavior: Play.NOW,
playerbarOpenDrawer: false,
2023-07-01 19:10:05 -07:00
resume: false,
showQueueDrawerButton: false,
sidebarCollapsedNavigation: true,
sidebarCollapseShared: false,
2023-07-01 19:10:05 -07:00
sidebarItems,
sidebarPlaylistList: true,
sideQueueType: 'sideQueue',
2023-07-01 19:10:05 -07:00
skipButtons: {
enabled: false,
skipBackwardSeconds: 5,
skipForwardSeconds: 10,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
theme: AppTheme.DEFAULT_DARK,
themeDark: AppTheme.DEFAULT_DARK,
themeLight: AppTheme.DEFAULT_LIGHT,
volumeWheelStep: 5,
volumeWidth: 60,
2023-07-01 19:10:05 -07:00
zoomFactor: 100,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
hotkeys: {
bindings: {
browserBack: { allowGlobal: false, hotkey: '', isGlobal: false },
browserForward: { allowGlobal: false, hotkey: '', isGlobal: false },
favoriteCurrentAdd: { allowGlobal: true, hotkey: '', isGlobal: false },
favoriteCurrentRemove: { allowGlobal: true, hotkey: '', isGlobal: false },
favoriteCurrentToggle: { allowGlobal: true, hotkey: '', isGlobal: false },
favoritePreviousAdd: { allowGlobal: true, hotkey: '', isGlobal: false },
favoritePreviousRemove: { allowGlobal: true, hotkey: '', isGlobal: false },
favoritePreviousToggle: { allowGlobal: true, hotkey: '', isGlobal: false },
2023-07-01 19:10:05 -07:00
globalSearch: { allowGlobal: false, hotkey: 'mod+k', isGlobal: false },
localSearch: { allowGlobal: false, hotkey: 'mod+f', isGlobal: false },
next: { allowGlobal: true, hotkey: '', isGlobal: false },
pause: { allowGlobal: true, hotkey: '', isGlobal: false },
play: { allowGlobal: true, hotkey: '', isGlobal: false },
playPause: { allowGlobal: true, hotkey: 'space', isGlobal: false },
2023-07-01 19:10:05 -07:00
previous: { allowGlobal: true, hotkey: '', isGlobal: false },
2023-09-23 03:20:04 -07:00
rate0: { allowGlobal: true, hotkey: '', isGlobal: false },
rate1: { allowGlobal: true, hotkey: '', isGlobal: false },
rate2: { allowGlobal: true, hotkey: '', isGlobal: false },
rate3: { allowGlobal: true, hotkey: '', isGlobal: false },
rate4: { allowGlobal: true, hotkey: '', isGlobal: false },
rate5: { allowGlobal: true, hotkey: '', isGlobal: false },
2023-07-01 19:10:05 -07:00
skipBackward: { allowGlobal: true, hotkey: '', isGlobal: false },
skipForward: { allowGlobal: true, hotkey: '', isGlobal: false },
stop: { allowGlobal: true, hotkey: '', isGlobal: false },
toggleFullscreenPlayer: { allowGlobal: false, hotkey: '', isGlobal: false },
toggleQueue: { allowGlobal: false, hotkey: '', isGlobal: false },
toggleRepeat: { allowGlobal: true, hotkey: '', isGlobal: false },
toggleShuffle: { allowGlobal: true, hotkey: '', isGlobal: false },
volumeDown: { allowGlobal: true, hotkey: '', isGlobal: false },
volumeMute: { allowGlobal: true, hotkey: '', isGlobal: false },
volumeUp: { allowGlobal: true, hotkey: '', isGlobal: false },
zoomIn: { allowGlobal: true, hotkey: '', isGlobal: false },
zoomOut: { allowGlobal: true, hotkey: '', isGlobal: false },
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
globalMediaHotkeys: true,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
lyrics: {
alignment: 'center',
2023-07-01 19:10:05 -07:00
delayMs: 0,
enableNeteaseTranslation: false,
2023-07-01 19:10:05 -07:00
fetch: false,
follow: true,
fontSize: 46,
fontSizeUnsync: 20,
gap: 5,
gapUnsync: 0,
showMatch: true,
showProvider: true,
2023-07-01 19:10:05 -07:00
sources: [],
translationApiKey: '',
translationApiProvider: '',
translationTargetLanguage: 'en',
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
playback: {
audioDeviceId: undefined,
crossfadeDuration: 5,
crossfadeStyle: CrossfadeStyle.EQUALPOWER,
mpvExtraParameters: [],
mpvProperties: {
audioExclusiveMode: 'no',
audioFormat: undefined,
audioSampleRateHz: 0,
gaplessAudio: 'weak',
replayGainClip: true,
replayGainFallbackDB: undefined,
replayGainMode: 'no',
replayGainPreampDB: 0,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
muted: false,
scrobble: {
enabled: true,
scrobbleAtDuration: 240,
scrobbleAtPercentage: 75,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
style: PlaybackStyle.GAPLESS,
2024-09-01 08:26:30 -07:00
transcode: {
enabled: false,
},
2024-02-13 05:50:38 -08:00
type: PlaybackType.WEB,
2024-08-29 19:44:24 -07:00
webAudio: true,
2023-03-31 05:56:32 -07:00
},
remote: {
enabled: false,
password: randomString(8),
port: 4333,
username: 'feishin',
},
2023-07-01 19:10:05 -07:00
tab: 'general',
tables: {
2023-08-08 08:28:40 -07:00
albumDetail: {
autoFit: true,
columns: [
{
column: TableColumn.TRACK_NUMBER,
width: 50,
},
{
column: TableColumn.TITLE_COMBINED,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
{
column: TableColumn.BIT_RATE,
width: 300,
},
{
column: TableColumn.PLAY_COUNT,
width: 100,
},
{
column: TableColumn.LAST_PLAYED,
width: 100,
},
{
column: TableColumn.USER_FAVORITE,
width: 100,
},
],
rowHeight: 60,
},
2023-07-01 19:10:05 -07:00
fullScreen: {
autoFit: true,
columns: [
{
column: TableColumn.ROW_INDEX,
width: 80,
},
2023-07-01 19:10:05 -07:00
{
column: TableColumn.TITLE_COMBINED,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
{
column: TableColumn.USER_FAVORITE,
width: 100,
},
],
followCurrentSong: true,
rowHeight: 60,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
nowPlaying: {
autoFit: true,
columns: [
{
column: TableColumn.ROW_INDEX,
width: 80,
2023-07-01 19:10:05 -07:00
},
{
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,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
sideDrawerQueue: {
autoFit: true,
columns: [
{
column: TableColumn.TITLE_COMBINED,
width: 500,
},
{
column: TableColumn.DURATION,
width: 100,
},
],
followCurrentSong: true,
rowHeight: 60,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
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,
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
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-31 05:56:32 -07:00
},
},
2023-07-01 19:10:05 -07:00
window: {
disableAutoUpdate: false,
exitToTray: false,
minimizeToTray: false,
startMinimized: false,
2024-09-08 20:55:07 -07:00
tray: true,
2023-07-01 19:10:05 -07:00
windowBarStyle: platformDefaultWindowBarStyle,
},
2023-03-31 05:56:32 -07:00
};
2022-12-19 15:59:14 -08:00
export const useSettingsStore = create<SettingsSlice>()(
2023-07-01 19:10:05 -07:00
persist(
devtools(
immer((set, get) => ({
actions: {
reset: () => {
if (!isElectron()) {
set({
...initialState,
playback: {
...initialState.playback,
type: PlaybackType.WEB,
},
});
} else {
set(initialState);
}
},
resetSampleRate: () => {
set((state) => {
state.playback.mpvProperties.audioSampleRateHz = 0;
});
},
2024-09-01 16:48:43 -07:00
setArtistItems: (items) => {
set((state) => {
state.general.artistItems = items;
});
},
setGenreBehavior: (target: GenreTarget) => {
set((state) => {
state.general.genreTarget = target;
});
},
setHomeItems: (items: SortableItem<HomeItem>[]) => {
set((state) => {
state.general.homeItems = items;
});
},
2023-07-01 19:10:05 -07:00
setSettings: (data) => {
set({ ...get(), ...data });
},
setSidebarItems: (items: SidebarItemType[]) => {
set((state) => {
state.general.sidebarItems = items;
});
},
2023-10-07 18:11:02 -07:00
setTable: (type: TableType, data: DataTableProps) => {
set((state) => {
state.tables[type] = data;
});
},
2024-09-01 08:26:30 -07:00
setTranscodingConfig: (config) => {
set((state) => {
state.playback.transcode = config;
});
},
2024-08-26 21:35:12 -07:00
toggleContextMenuItem: (item: ContextMenuItemType) => {
set((state) => {
state.general.disabledContextMenu[item] =
!state.general.disabledContextMenu[item];
});
},
2024-08-24 21:09:44 -07:00
toggleSidebarCollapseShare: () => {
set((state) => {
state.general.sidebarCollapseShared =
!state.general.sidebarCollapseShared;
});
},
2023-03-31 05:56:32 -07:00
},
2023-07-01 19:10:05 -07:00
...initialState,
})),
{ name: 'store_settings' },
),
{
merge: mergeOverridingColumns,
2025-05-13 01:24:42 +00:00
migrate(persistedState, version) {
if (version === 8) {
const state = persistedState as SettingsSlice;
state.general.sidebarItems = state.general.sidebarItems.filter(
(item) => item.id !== 'Folders',
);
state.general.sidebarItems.push({
disabled: false,
id: 'Artists-all',
label: i18n.t('page.sidebar.artists'),
route: AppRoute.LIBRARY_ARTISTS,
});
}
return persistedState;
},
2023-07-01 19:10:05 -07:00
name: 'store_settings',
2025-04-23 23:27:06 -07:00
version: 9,
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) =>
2023-07-01 19:10:05 -07:00
useSettingsStore((state) => state.tables[type]);
2022-12-19 15:59:14 -08:00
2023-03-28 23:59:51 -07:00
export const useGeneralSettings = () => useSettingsStore((state) => state.general, shallow);
2022-12-25 01:55:00 -08:00
export const usePlaybackType = () =>
useSettingsStore((state) => {
const isFallback = usePlayerStore.getState().fallback;
if (isFallback) {
return PlaybackType.WEB;
}
return state.playback.type;
});
export const usePlayButtonBehavior = () =>
2023-07-01 19:10:05 -07:00
useSettingsStore((state) => state.general.playButtonBehavior, shallow);
2023-03-30 06:44:33 -07:00
export const useWindowSettings = () => useSettingsStore((state) => state.window, shallow);
2023-03-31 07:26:10 -07:00
export const useHotkeySettings = () => useSettingsStore((state) => state.hotkeys, shallow);
export const useMpvSettings = () =>
2023-07-01 19:10:05 -07:00
useSettingsStore((state) => state.playback.mpvProperties, shallow);
export const useLyricsSettings = () => useSettingsStore((state) => state.lyrics, shallow);
export const useRemoteSettings = () => useSettingsStore((state) => state.remote, shallow);
export const useFontSettings = () => useSettingsStore((state) => state.font, shallow);
2023-10-23 06:58:39 -07:00
export const useDiscordSetttings = () => useSettingsStore((state) => state.discord, shallow);
2024-08-27 08:26:34 -07:00
export const useCssSettings = () => useSettingsStore((state) => state.css, shallow);