Compare commits

...

3 Commits

Author SHA1 Message Date
algerkong
e2cdd1d8d7 feat: 优化音源选择逻辑以去重 2025-04-23 10:46:29 +08:00
algerkong
c90cfbf3cd feat: 优化设置模块,合并默认设置与存储设置,初始化时读取设置 2025-04-23 09:52:07 +08:00
algerkong
2c5bfac439 🔧 chore: 移除不再使用的快捷键初始化功能 2025-04-23 09:05:24 +08:00
4 changed files with 25 additions and 27 deletions

View File

@@ -26,7 +26,6 @@ import { isElectron, isLyricWindow } from '@/utils';
import { initAudioListeners } from './hooks/MusicHook';
import { isMobile } from './utils';
import { useAppShortcuts } from './utils/appShortcuts';
import { initShortcut } from './utils/shortcut';
const { locale } = useI18n();
const settingsStore = useSettingsStore();
@@ -120,8 +119,6 @@ onMounted(async () => {
window.api.sendSong(cloneDeep(playerStore.playMusic));
}
}
// 初始化快捷键
initShortcut();
});
</script>

View File

@@ -1,4 +1,4 @@
import { cloneDeep } from 'lodash';
import { cloneDeep, merge } from 'lodash';
import { defineStore } from 'pinia';
import { ref } from 'vue';
@@ -7,17 +7,6 @@ import { isElectron } from '@/utils';
import { applyTheme, getCurrentTheme, ThemeType } from '@/utils/theme';
export const useSettingsStore = defineStore('settings', () => {
// 初始化时先从存储中读取设置
const getInitialSettings = () => {
if (isElectron) {
const savedSettings = window.electron.ipcRenderer.sendSync('get-store-value', 'set');
return savedSettings || setDataDefault;
}
const savedSettings = localStorage.getItem('appSettings');
return savedSettings ? JSON.parse(savedSettings) : setDataDefault;
};
const setData = ref(getInitialSettings());
const theme = ref<ThemeType>(getCurrentTheme());
const isMobile = ref(false);
const isMiniMode = ref(false);
@@ -28,7 +17,11 @@ export const useSettingsStore = defineStore('settings', () => {
{ label: '系统默认', value: 'system-ui' }
]);
const showDownloadDrawer = ref(false);
// 先声明 setData ref 但不初始化
const setData = ref<any>({});
// 先定义 setSetData 函数
const setSetData = (data: any) => {
// 合并现有设置和新设置
const mergedData = {
@@ -44,6 +37,24 @@ export const useSettingsStore = defineStore('settings', () => {
setData.value = cloneDeep(mergedData);
};
// 初始化时先从存储中读取设置
const getInitialSettings = () => {
// 从存储中获取保存的设置
const savedSettings = isElectron
? window.electron.ipcRenderer.sendSync('get-store-value', 'set')
: JSON.parse(localStorage.getItem('appSettings') || '{}');
// 合并默认设置和保存的设置
const mergedSettings = merge({}, setDataDefault, savedSettings);
// 更新设置并返回
setSetData(mergedSettings);
return mergedSettings;
};
// 初始化 setData
setData.value = getInitialSettings();
const toggleTheme = () => {
theme.value = theme.value === 'dark' ? 'light' : 'dark';
applyTheme(theme.value);

View File

@@ -1,10 +0,0 @@
import { isElectron } from '.';
import { handleShortcutAction } from './appShortcuts';
export function initShortcut() {
if (isElectron) {
window.electron.ipcRenderer.on('global-shortcut', async (_, action: string) => {
handleShortcutAction(action);
});
}
}

View File

@@ -575,7 +575,7 @@ import config from '../../../../package.json';
// 手动定义Platform类型避免从主进程导入的问题
type Platform = 'qq' | 'migu' | 'kugou' | 'pyncmd' | 'joox' | 'kuwo' | 'bilibili' | 'youtube' | 'gdmusic';
// 所有平台
const ALL_PLATFORMS: Platform[] = ['migu', 'kugou', 'pyncmd', 'kuwo', 'bilibili', 'youtube', 'gdmusic'];
const ALL_PLATFORMS: Platform[] = ['migu', 'kugou', 'pyncmd', 'bilibili', 'youtube'];
const settingsStore = useSettingsStore();
const userStore = useUserStore();
@@ -1082,7 +1082,7 @@ const musicSources = computed({
},
set: (newValue: Platform[]) => {
// 确保至少选择一个音源
const valuesToSet = newValue.length > 0 ? newValue : ALL_PLATFORMS;
const valuesToSet = newValue.length > 0 ? [...new Set(newValue)] : ALL_PLATFORMS;
setData.value = {
...setData.value,
enabledMusicSources: valuesToSet