mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-30 03:47:22 +08:00
Merge pull request #645 from geewon1i/Lyric-lock-icon
fix(歌词悬窗): 通过主进程周期检测鼠标位置纠正悬停状态,修复鼠标快速移出时锁图标残留问题 Closes #606
This commit is contained in:
@@ -10,6 +10,54 @@ let isDragging = false;
|
|||||||
|
|
||||||
// 添加窗口大小变化防护
|
// 添加窗口大小变化防护
|
||||||
let originalSize = { width: 0, height: 0 };
|
let originalSize = { width: 0, height: 0 };
|
||||||
|
let mousePresenceTimer: ReturnType<typeof setInterval> | null = null;
|
||||||
|
let lastMouseInside: boolean | null = null;
|
||||||
|
|
||||||
|
const isPointInsideWindow = (
|
||||||
|
point: { x: number; y: number },
|
||||||
|
bounds: { x: number; y: number; width: number; height: number }
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
point.x >= bounds.x &&
|
||||||
|
point.x < bounds.x + bounds.width &&
|
||||||
|
point.y >= bounds.y &&
|
||||||
|
point.y < bounds.y + bounds.height
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const stopMousePresenceTracking = () => {
|
||||||
|
if (mousePresenceTimer) {
|
||||||
|
clearInterval(mousePresenceTimer);
|
||||||
|
mousePresenceTimer = null;
|
||||||
|
}
|
||||||
|
lastMouseInside = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const emitMousePresence = () => {
|
||||||
|
if (!lyricWindow || lyricWindow.isDestroyed()) return;
|
||||||
|
|
||||||
|
const mousePoint = screen.getCursorScreenPoint();
|
||||||
|
const bounds = lyricWindow.getBounds();
|
||||||
|
const isInside = isPointInsideWindow(mousePoint, bounds);
|
||||||
|
|
||||||
|
if (isInside === lastMouseInside) return;
|
||||||
|
|
||||||
|
lastMouseInside = isInside;
|
||||||
|
lyricWindow.webContents.send('lyric-mouse-presence', isInside);
|
||||||
|
};
|
||||||
|
|
||||||
|
const startMousePresenceTracking = () => {
|
||||||
|
if (mousePresenceTimer) return;
|
||||||
|
|
||||||
|
emitMousePresence();
|
||||||
|
mousePresenceTimer = setInterval(() => {
|
||||||
|
if (!lyricWindow || lyricWindow.isDestroyed()) {
|
||||||
|
stopMousePresenceTracking();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emitMousePresence();
|
||||||
|
}, 50);
|
||||||
|
};
|
||||||
|
|
||||||
const createWin = () => {
|
const createWin = () => {
|
||||||
console.log('Creating lyric window');
|
console.log('Creating lyric window');
|
||||||
@@ -102,6 +150,7 @@ const createWin = () => {
|
|||||||
|
|
||||||
// 监听窗口关闭事件
|
// 监听窗口关闭事件
|
||||||
lyricWindow.on('closed', () => {
|
lyricWindow.on('closed', () => {
|
||||||
|
stopMousePresenceTracking();
|
||||||
if (lyricWindow) {
|
if (lyricWindow) {
|
||||||
lyricWindow.destroy();
|
lyricWindow.destroy();
|
||||||
lyricWindow = null;
|
lyricWindow = null;
|
||||||
@@ -135,6 +184,7 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void
|
|||||||
}
|
}
|
||||||
lyricWindow.focus();
|
lyricWindow.focus();
|
||||||
lyricWindow.show();
|
lyricWindow.show();
|
||||||
|
startMousePresenceTracking();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -169,6 +219,7 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void
|
|||||||
win.once('ready-to-show', () => {
|
win.once('ready-to-show', () => {
|
||||||
console.log('Lyric window ready to show');
|
console.log('Lyric window ready to show');
|
||||||
win.show();
|
win.show();
|
||||||
|
startMousePresenceTracking();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -197,6 +248,7 @@ export const loadLyricWindow = (ipcMain: IpcMain, mainWin: BrowserWindow): void
|
|||||||
|
|
||||||
ipcMain.on('close-lyric', () => {
|
ipcMain.on('close-lyric', () => {
|
||||||
if (lyricWindow && !lyricWindow.isDestroyed()) {
|
if (lyricWindow && !lyricWindow.isDestroyed()) {
|
||||||
|
stopMousePresenceTracking();
|
||||||
lyricWindow.webContents.send('lyric-window-close');
|
lyricWindow.webContents.send('lyric-window-close');
|
||||||
mainWin.webContents.send('lyric-control-back', 'close');
|
mainWin.webContents.send('lyric-control-back', 'close');
|
||||||
mainWin.webContents.send('lyric-window-closed');
|
mainWin.webContents.send('lyric-window-closed');
|
||||||
|
|||||||
@@ -341,6 +341,7 @@ const displayMode = computed(() => lyricSetting.value.displayMode);
|
|||||||
const showTranslation = computed(() => lyricSetting.value.showTranslation);
|
const showTranslation = computed(() => lyricSetting.value.showTranslation);
|
||||||
|
|
||||||
let hideControlsTimer: number | null = null;
|
let hideControlsTimer: number | null = null;
|
||||||
|
let removeMousePresenceListener: (() => void) | null = null;
|
||||||
|
|
||||||
const isHovering = ref(false);
|
const isHovering = ref(false);
|
||||||
|
|
||||||
@@ -782,10 +783,25 @@ onMounted(() => {
|
|||||||
|
|
||||||
// 通知主窗口歌词窗口已就绪,请求发送完整歌词数据
|
// 通知主窗口歌词窗口已就绪,请求发送完整歌词数据
|
||||||
windowData.electron.ipcRenderer.send('lyric-ready');
|
windowData.electron.ipcRenderer.send('lyric-ready');
|
||||||
|
|
||||||
|
removeMousePresenceListener = window.ipcRenderer.on(
|
||||||
|
'lyric-mouse-presence',
|
||||||
|
(isInside: boolean) => {
|
||||||
|
isHovering.value = isInside;
|
||||||
|
|
||||||
|
if (lyricSetting.value.isLock) {
|
||||||
|
windowData.electron.ipcRenderer.send('set-ignore-mouse', !isInside);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener('resize', updateContainerHeight);
|
window.removeEventListener('resize', updateContainerHeight);
|
||||||
|
if (removeMousePresenceListener) {
|
||||||
|
removeMousePresenceListener();
|
||||||
|
removeMousePresenceListener = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkTheme = () => {
|
const checkTheme = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user