optimize the problem of accidental double-clicking on the taskbar.

This commit is contained in:
unknown 2024-01-13 10:23:15 +08:00
parent af25b93004
commit ac9c8c834f

View File

@ -156,6 +156,7 @@ function createMainWindow() {
} }
}); });
// 创建鼠标hook // 创建鼠标hook
let mousedownClassName = null;
addon.createMouseHook((...args: any[]) => { addon.createMouseHook((...args: any[]) => {
let res = JSON.parse(args[1]); let res = JSON.parse(args[1]);
let event: string = res.event; let event: string = res.event;
@ -175,15 +176,19 @@ function createMainWindow() {
} }
} else if (event === "mousedown") { } else if (event === "mousedown") {
// 鼠标按下 // 鼠标按下
if (button === 1) {
mousedownClassName = className;
}
} else if (event === "mouseup") { } else if (event === "mouseup") {
// 鼠标抬起 // 鼠标抬起
if (button === 3) { if (button === 1) {
// 双击任务栏
doubleClickTaskbar(mousedownClassName, className);
} else if (button === 3) {
// 中间单击 // 中间单击
// 显示隐藏窗口 // 显示隐藏窗口
showHideMouseWheelClick(); showHideMouseWheelClick();
} }
// 双击任务栏
doubleClickTaskbar(button, className);
} }
}); });
// 禁用标题栏右键 // 禁用标题栏右键
@ -579,7 +584,10 @@ function autoHide(x: number, y: number, size: number, timer: boolean) {
/** /**
* / * /
*/ */
function doubleClickTaskbar(button: number, className: string | null) { function doubleClickTaskbar(
mousedownClassName: string | null,
className: string | null
) {
// 必须开启设置 // 必须开启设置
if (!global.setting.general.showHideDoubleClickTaskbar) { if (!global.setting.general.showHideDoubleClickTaskbar) {
return; return;
@ -587,7 +595,6 @@ function doubleClickTaskbar(button: number, className: string | null) {
// 获取屏幕 // 获取屏幕
let displays = getWindowInScreen(); let displays = getWindowInScreen();
if ( if (
button !== 1 ||
displays.length > 1 || displays.length > 1 ||
displays.length === 0 || displays.length === 0 ||
className !== "Shell_TrayWnd" className !== "Shell_TrayWnd"
@ -598,38 +605,46 @@ function doubleClickTaskbar(button: number, className: string | null) {
global.doubleClickTaskbarCounter = 0; global.doubleClickTaskbarCounter = 0;
return; return;
} }
// 必须是指定Class
if (
(release().startsWith("10.0.1") &&
global.addon.getCursorPosWindowClassName().indexOf("MSTask") >= 0) ||
(release().startsWith("10.0.2") &&
global.addon.getCursorPosWindowClassName() !== "TrayNotifyWnd")
) {
// 监听双击 // 监听双击
if (!global.doubleClickTaskbarCounter) { if (!global.doubleClickTaskbarCounter) {
global.doubleClickTaskbarCounter = 0; global.doubleClickTaskbarCounter = 0;
} }
// +1 // +1
global.doubleClickTaskbarCounter++; global.doubleClickTaskbarCounter++;
// 等于2就是双击
if ( if (
global.doubleClickTaskbarCounter && global.doubleClickTaskbarCounter &&
global.doubleClickTaskbarCounter === 2 global.doubleClickTaskbarCounter === 2 &&
mousedownClassName === "Shell_TrayWnd"
) { ) {
// 清除timeout // 清除timeout
clearTimeout(global.doubleClickTaskbarTimer); clearTimeout(global.doubleClickTaskbarTimer);
// 清空计数 // 清空计数
global.doubleClickTaskbarCounter = 0; global.doubleClickTaskbarCounter = 0;
if ( // 显示或隐藏
(release().startsWith("10.0.1") &&
global.addon.getCursorPosWindowClassName().indexOf("MSTask") >= 0) ||
release().startsWith("10.0.2")
) {
if (mainWindow.isVisible()) { if (mainWindow.isVisible()) {
hideMainWindow(); hideMainWindow();
} else { } else {
showMainWindowBefore(false); showMainWindowBefore(false);
} }
}
} else { } else {
// 间隔为500毫秒如果超过500毫秒就代表不是双击 // 间隔为500毫秒如果超过500毫秒就代表不是双击
global.doubleClickTaskbarTimer = setTimeout(function () { global.doubleClickTaskbarTimer = setTimeout(function () {
global.doubleClickTaskbarCounter = 0; global.doubleClickTaskbarCounter = 0;
}, 500); }, 500);
} }
} else {
// 清除timeout
clearTimeout(global.doubleClickTaskbarTimer);
// 清空计数
global.doubleClickTaskbarCounter = 0;
}
} }
export { export {