mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-03 14:20:50 +08:00
Compare commits
3 Commits
167f081ee6
...
v4.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2cdd1d8d7 | ||
|
|
c90cfbf3cd | ||
|
|
2c5bfac439 |
@@ -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>
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user