mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-30 21:07:24 +08:00
✨ feat: 添加“收藏”功能至托盘菜单
This commit is contained in:
@@ -47,7 +47,8 @@ export default {
|
|||||||
prev: 'Previous',
|
prev: 'Previous',
|
||||||
next: 'Next',
|
next: 'Next',
|
||||||
pause: 'Pause',
|
pause: 'Pause',
|
||||||
play: 'Play'
|
play: 'Play',
|
||||||
|
favorite: 'Favorite'
|
||||||
},
|
},
|
||||||
language: 'Language'
|
language: 'Language'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export default {
|
|||||||
prev: '上一首',
|
prev: '上一首',
|
||||||
next: '下一首',
|
next: '下一首',
|
||||||
pause: '暂停',
|
pause: '暂停',
|
||||||
play: '播放'
|
play: '播放',
|
||||||
|
favorite: '收藏'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -174,6 +174,18 @@ export function updateTrayMenu(mainWindow: BrowserWindow) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 收藏
|
||||||
|
menu.append(
|
||||||
|
new MenuItem({
|
||||||
|
label: i18n.global.t('common.tray.favorite'),
|
||||||
|
type: 'normal',
|
||||||
|
click: () => {
|
||||||
|
console.log('[Tray] 发送收藏命令 - macOS菜单');
|
||||||
|
mainWindow.webContents.send('global-shortcut', 'toggleFavorite');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
menu.append(
|
menu.append(
|
||||||
new MenuItem({
|
new MenuItem({
|
||||||
label: i18n.global.t('common.tray.next'),
|
label: i18n.global.t('common.tray.next'),
|
||||||
@@ -253,6 +265,14 @@ export function updateTrayMenu(mainWindow: BrowserWindow) {
|
|||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: i18n.global.t('common.tray.favorite'),
|
||||||
|
type: 'normal',
|
||||||
|
click: () => {
|
||||||
|
console.log('[Tray] 发送收藏命令 - Windows/Linux菜单');
|
||||||
|
mainWindow.webContents.send('global-shortcut', 'toggleFavorite');
|
||||||
|
}
|
||||||
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
label: i18n.global.t('common.tray.prev'),
|
label: i18n.global.t('common.tray.prev'),
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ import { showShortcutToast } from './shortcutToast';
|
|||||||
let actionTimeout: NodeJS.Timeout | null = null;
|
let actionTimeout: NodeJS.Timeout | null = null;
|
||||||
const ACTION_DELAY = 300; // 毫秒
|
const ACTION_DELAY = 300; // 毫秒
|
||||||
|
|
||||||
|
// 添加一个操作锁,记录最后一次操作的时间和动作
|
||||||
|
let lastActionInfo = {
|
||||||
|
action: '',
|
||||||
|
timestamp: 0
|
||||||
|
};
|
||||||
|
|
||||||
interface ShortcutConfig {
|
interface ShortcutConfig {
|
||||||
key: string;
|
key: string;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
@@ -31,17 +37,33 @@ let appShortcuts: ShortcutsConfig = {};
|
|||||||
* @param action 快捷键动作
|
* @param action 快捷键动作
|
||||||
*/
|
*/
|
||||||
export async function handleShortcutAction(action: string) {
|
export async function handleShortcutAction(action: string) {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
// 如果存在未完成的动作,则忽略当前请求
|
// 如果存在未完成的动作,则忽略当前请求
|
||||||
if (actionTimeout) {
|
if (actionTimeout) {
|
||||||
console.log('忽略快速连续的动作请求:', action);
|
console.log('[AppShortcuts] 忽略快速连续的动作请求:', action);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否是同一个动作的重复触发(300ms内)
|
||||||
|
if (lastActionInfo.action === action && now - lastActionInfo.timestamp < ACTION_DELAY) {
|
||||||
|
console.log(`[AppShortcuts] 忽略重复的 ${action} 动作,距上次仅 ${now - lastActionInfo.timestamp}ms`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新最后一次操作信息
|
||||||
|
lastActionInfo = {
|
||||||
|
action,
|
||||||
|
timestamp: now
|
||||||
|
};
|
||||||
|
|
||||||
// 设置防抖锁
|
// 设置防抖锁
|
||||||
actionTimeout = setTimeout(() => {
|
actionTimeout = setTimeout(() => {
|
||||||
actionTimeout = null;
|
actionTimeout = null;
|
||||||
}, ACTION_DELAY);
|
}, ACTION_DELAY);
|
||||||
|
|
||||||
|
console.log(`[AppShortcuts] 执行动作: ${action}, 时间戳: ${now}`);
|
||||||
|
|
||||||
const playerStore = usePlayerStore();
|
const playerStore = usePlayerStore();
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
@@ -93,16 +115,19 @@ export async function handleShortcutAction(action: string) {
|
|||||||
case 'toggleFavorite': {
|
case 'toggleFavorite': {
|
||||||
const isFavorite = playerStore.favoriteList.includes(Number(playerStore.playMusic.id));
|
const isFavorite = playerStore.favoriteList.includes(Number(playerStore.playMusic.id));
|
||||||
const numericId = Number(playerStore.playMusic.id);
|
const numericId = Number(playerStore.playMusic.id);
|
||||||
|
console.log(`[AppShortcuts] toggleFavorite 当前状态: ${isFavorite}, ID: ${numericId}`);
|
||||||
if (isFavorite) {
|
if (isFavorite) {
|
||||||
playerStore.removeFromFavorite(numericId);
|
playerStore.removeFromFavorite(numericId);
|
||||||
|
console.log(`[AppShortcuts] 已从收藏中移除: ${numericId}`);
|
||||||
} else {
|
} else {
|
||||||
playerStore.addToFavorite(numericId);
|
playerStore.addToFavorite(numericId);
|
||||||
|
console.log(`[AppShortcuts] 已添加到收藏: ${numericId}`);
|
||||||
}
|
}
|
||||||
showToast(
|
showToast(
|
||||||
isFavorite
|
isFavorite
|
||||||
? t('player.playBar.favorite', { name: playerStore.playMusic.name })
|
? t('player.playBar.unFavorite', { name: playerStore.playMusic.name })
|
||||||
: t('player.playBar.unFavorite', { name: playerStore.playMusic.name }),
|
: t('player.playBar.favorite', { name: playerStore.playMusic.name }),
|
||||||
isFavorite ? 'ri-heart-fill' : 'ri-heart-line'
|
isFavorite ? 'ri-heart-line' : 'ri-heart-fill'
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -114,10 +139,9 @@ export async function handleShortcutAction(action: string) {
|
|||||||
console.error(`执行快捷键动作 ${action} 时出错:`, error);
|
console.error(`执行快捷键动作 ${action} 时出错:`, error);
|
||||||
} finally {
|
} finally {
|
||||||
// 确保在出错时也能清除超时
|
// 确保在出错时也能清除超时
|
||||||
if (actionTimeout) {
|
clearTimeout(actionTimeout);
|
||||||
clearTimeout(actionTimeout);
|
actionTimeout = null;
|
||||||
actionTimeout = null;
|
console.log(`[AppShortcuts] 动作完成: ${action}, 时间戳: ${Date.now()}, 耗时: ${Date.now() - now}ms`);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user