mirror of
https://github.com/atdunbg/Nekosonic-Music.git
synced 2026-06-22 00:58:51 +08:00
## 后端 - 替换 rodio 为 symphonia + ringbuf,重构 audio.rs 播放引擎 - 重构 api.rs,使用 api_call! 宏统一 API 调用模式 - 新增 media_controls.rs,使用 souvlaki 实现跨平台系统媒体控制 (Linux MPRIS / Windows SMTC / macOS Now Playing) - 版本号升至 v0.5.0 ## 前端 - 新增 - 新增 SongListItem 通用组件 - 新增 useOnlineStatus composable,检测网络状态 - 新增 usePageCache composable,页面数据缓存与失效 - 新增 getCoverUrl()、formatDate() 工具函数 - 新增 emitPlaybackState() 同步播放状态到系统媒体控制 - 新增 mpris-command 事件监听,响应系统媒体控制命令 - 新增 Toast 离线/恢复在线提示 - 各页面新增断网恢复后自动重试加载 - 新增路由守卫:已登录用户访问 /login 重定向至首页 - 新增音量持久化(settings store + localStorage) - 新增禁用右键菜单与用户选择限制(输入框除外) ## 前端 - 变更 - Song 接口从 player.ts 迁移至 song.ts 并导出 - AlbumDetail/ArtistDetail/PlaylistDetail/RecentPlays/LocalMusic 迁移至 SongListItem - PlayerBar 队列列表迁移至 SongListItem,封面使用 getCoverUrl() - downloadSong 参数类型从内联对象改为 Song,使用 getCoverUrl() - 默认主题从 green 改为 blue,ThemeName 及相关列表中 blue 移至首位 - 全局快捷键从 Alt+Control 改为 Control+Alt 顺序 - formatShortcut 新增 KeyP → P 显示 - keep-alive 从 max=3 固定 include 改为 max=5 动态列表,窗口隐藏时释放 - App.vue 封面使用 getCoverUrl() 替代手动 al/album 回退 - formatPlayCount 提取常量 - Login.vue text-warning 改为 text-yellow-400 ## 前端 - 删除 - 删除 Search.vue(与 Discover.vue 重复) - 删除 SongItemMenu.vue(被 SongListItem 替代) ## 修复 - 更新器跳过版本逻辑:仅静默检查时跳过已忽略版本,手动检查不再跳过 - 重复播放同一首歌时无法恢复播放 - settings.ts 重复的 ThemeName 定义 - PlayerBar.vue modeTexts 缺少类型注解 - Home.vue map 回调参数缺少类型 - Settings.vue v-for key 类型不匹配
179 lines
5.1 KiB
TypeScript
179 lines
5.1 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { ref, watch } from 'vue';
|
|
|
|
export type AudioQuality = 'standard' | 'higher' | 'exhigh' | 'lossless' | 'hires';
|
|
export type ThemeName = 'blue' | 'green' | 'rose' | 'violet' | 'orange' | 'cyan' | 'pink';
|
|
export type CloseAction = 'ask' | 'minimize' | 'exit';
|
|
|
|
export const themeLabels: Record<ThemeName, string> = {
|
|
blue: '天蓝',
|
|
green: '翠绿',
|
|
rose: '玫红',
|
|
violet: '紫罗兰',
|
|
orange: '橙色',
|
|
cyan: '青色',
|
|
pink: '粉色',
|
|
};
|
|
|
|
export const themeColors: Record<ThemeName, string> = {
|
|
blue: '#3b82f6',
|
|
green: '#22c55e',
|
|
rose: '#f43f5e',
|
|
violet: '#8b5cf6',
|
|
orange: '#f97316',
|
|
cyan: '#06b6d4',
|
|
pink: '#ec4899',
|
|
};
|
|
|
|
export const qualityLabels: Record<AudioQuality, string> = {
|
|
standard: '标准',
|
|
higher: '较高',
|
|
exhigh: '极高 (HQ)',
|
|
lossless: '无损 (SQ)',
|
|
hires: 'Hi-Res',
|
|
};
|
|
|
|
export const closeActionLabels: Record<CloseAction, string> = {
|
|
ask: '每次询问',
|
|
minimize: '最小化到托盘',
|
|
exit: '直接退出',
|
|
};
|
|
|
|
export interface ShortcutBinding {
|
|
key: string;
|
|
label: string;
|
|
}
|
|
|
|
export const defaultShortcuts: Record<string, ShortcutBinding> = {
|
|
playPause: { key: 'Control+KeyP', label: '播放/暂停' },
|
|
prev: { key: 'Control+ArrowLeft', label: '上一首' },
|
|
next: { key: 'Control+ArrowRight', label: '下一首' },
|
|
volUp: { key: 'Control+ArrowUp', label: '音量增加' },
|
|
volDown: { key: 'Control+ArrowDown', label: '音量减小' },
|
|
globalPlayPause: { key: 'Control+Alt+KeyP', label: '播放/暂停(全局)' },
|
|
globalPrev: { key: 'Control+Alt+ArrowLeft', label: '上一首(全局)' },
|
|
globalNext: { key: 'Control+Alt+ArrowRight', label: '下一首(全局)' },
|
|
globalVolUp: { key: 'Control+Alt+ArrowUp', label: '音量增加(全局)' },
|
|
globalVolDown: { key: 'Control+Alt+ArrowDown', label: '音量减小(全局)' },
|
|
};
|
|
|
|
interface SettingsData {
|
|
audioQuality: AudioQuality;
|
|
downloadPath: string;
|
|
theme: ThemeName;
|
|
closeAction: CloseAction;
|
|
shortcuts: Record<string, ShortcutBinding>;
|
|
outputDevice: string | null;
|
|
volume: number;
|
|
}
|
|
|
|
function loadSettings(): SettingsData {
|
|
try {
|
|
const raw = localStorage.getItem('app_settings');
|
|
if (raw) {
|
|
const parsed = JSON.parse(raw);
|
|
const theme = parsed.theme || parsed.accentColor || 'blue';
|
|
const validThemes: ThemeName[] = ['blue', 'green', 'rose', 'violet', 'orange', 'cyan', 'pink'];
|
|
return {
|
|
audioQuality: parsed.audioQuality || 'standard',
|
|
downloadPath: parsed.downloadPath || '',
|
|
theme: validThemes.includes(theme) ? theme : 'blue',
|
|
closeAction: parsed.closeAction || 'ask',
|
|
shortcuts: { ...defaultShortcuts, ...(parsed.shortcuts || {}) },
|
|
outputDevice: parsed.outputDevice || null,
|
|
volume: typeof parsed.volume === 'number' ? parsed.volume : 100,
|
|
};
|
|
}
|
|
} catch {}
|
|
return {
|
|
audioQuality: 'standard',
|
|
downloadPath: '',
|
|
theme: 'blue',
|
|
closeAction: 'ask',
|
|
shortcuts: { ...defaultShortcuts },
|
|
outputDevice: null,
|
|
volume: 100,
|
|
};
|
|
}
|
|
|
|
export const useSettingsStore = defineStore('settings', () => {
|
|
const saved = loadSettings();
|
|
|
|
const audioQuality = ref<AudioQuality>(saved.audioQuality);
|
|
const downloadPath = ref<string>(saved.downloadPath);
|
|
const theme = ref<ThemeName>(saved.theme);
|
|
const closeAction = ref<CloseAction>(saved.closeAction || 'ask');
|
|
const shortcuts = ref<Record<string, ShortcutBinding>>(saved.shortcuts);
|
|
const outputDevice = ref<string | null>(saved.outputDevice);
|
|
const volume = ref<number>(saved.volume);
|
|
|
|
function setAudioQuality(q: AudioQuality) {
|
|
audioQuality.value = q;
|
|
}
|
|
|
|
function setDownloadPath(p: string) {
|
|
downloadPath.value = p;
|
|
}
|
|
|
|
function setTheme(t: ThemeName) {
|
|
theme.value = t;
|
|
}
|
|
|
|
function setCloseAction(a: CloseAction) {
|
|
closeAction.value = a;
|
|
}
|
|
|
|
function setShortcut(id: string, key: string) {
|
|
shortcuts.value = { ...shortcuts.value, [id]: { ...shortcuts.value[id], key } };
|
|
}
|
|
|
|
function resetShortcuts() {
|
|
shortcuts.value = { ...defaultShortcuts };
|
|
}
|
|
|
|
function setOutputDevice(device: string | null) {
|
|
outputDevice.value = device;
|
|
}
|
|
|
|
function resetAll() {
|
|
audioQuality.value = 'standard';
|
|
downloadPath.value = '';
|
|
theme.value = 'blue';
|
|
closeAction.value = 'ask';
|
|
shortcuts.value = { ...defaultShortcuts };
|
|
outputDevice.value = null;
|
|
volume.value = 100;
|
|
}
|
|
|
|
watch([audioQuality, downloadPath, theme, closeAction, shortcuts, outputDevice, volume], () => {
|
|
const data: SettingsData = {
|
|
audioQuality: audioQuality.value,
|
|
downloadPath: downloadPath.value,
|
|
theme: theme.value,
|
|
closeAction: closeAction.value,
|
|
shortcuts: shortcuts.value,
|
|
outputDevice: outputDevice.value,
|
|
volume: volume.value,
|
|
};
|
|
localStorage.setItem('app_settings', JSON.stringify(data));
|
|
}, { deep: true });
|
|
|
|
return {
|
|
audioQuality,
|
|
downloadPath,
|
|
theme,
|
|
closeAction,
|
|
shortcuts,
|
|
outputDevice,
|
|
volume,
|
|
setAudioQuality,
|
|
setDownloadPath,
|
|
setTheme,
|
|
setCloseAction,
|
|
setOutputDevice,
|
|
setShortcut,
|
|
resetShortcuts,
|
|
resetAll,
|
|
};
|
|
});
|