mirror of
https://github.com/fanchenio/DawnLauncher.git
synced 2025-07-14 05:12:11 +08:00
Optimize the overall operation logic of double-clicking the taskbar to reduce accidental touches.
This commit is contained in:
parent
87ab4e3060
commit
da4a19f81a
@ -11,6 +11,7 @@ import { createSettingWindow } from "../setting";
|
|||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import cacheData from "../commons/cacheData";
|
import cacheData from "../commons/cacheData";
|
||||||
import { getMainBackgorunColor, sendToWebContent } from "../commons";
|
import { getMainBackgorunColor, sendToWebContent } from "../commons";
|
||||||
|
import { release } from "node:os";
|
||||||
|
|
||||||
// 窗口
|
// 窗口
|
||||||
let mainWindow: BrowserWindow | null = null;
|
let mainWindow: BrowserWindow | null = null;
|
||||||
@ -160,6 +161,10 @@ function createMainWindow() {
|
|||||||
let event: string = res.event;
|
let event: string = res.event;
|
||||||
let x: number = res.x;
|
let x: number = res.x;
|
||||||
let y: number = res.y;
|
let y: number = res.y;
|
||||||
|
let className: string =
|
||||||
|
!res.class_name || res.class_name.trim() === ""
|
||||||
|
? null
|
||||||
|
: res.class_name.trim();
|
||||||
// 1左键 2右键 3滚轮
|
// 1左键 2右键 3滚轮
|
||||||
let button: number = res.button;
|
let button: number = res.button;
|
||||||
if (event === "mousemove") {
|
if (event === "mousemove") {
|
||||||
@ -178,7 +183,7 @@ function createMainWindow() {
|
|||||||
showHideMouseWheelClick();
|
showHideMouseWheelClick();
|
||||||
}
|
}
|
||||||
// 双击任务栏
|
// 双击任务栏
|
||||||
doubleClickTaskbar(button);
|
doubleClickTaskbar(button, className);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 禁用标题栏右键
|
// 禁用标题栏右键
|
||||||
@ -574,76 +579,25 @@ function autoHide(x: number, y: number, size: number, timer: boolean) {
|
|||||||
/**
|
/**
|
||||||
* 双击任务栏显示/隐藏
|
* 双击任务栏显示/隐藏
|
||||||
*/
|
*/
|
||||||
function doubleClickTaskbar(button: number) {
|
function doubleClickTaskbar(button: number, className: string | null) {
|
||||||
// 必须开启设置
|
// 必须开启设置
|
||||||
if (!global.setting.general.showHideDoubleClickTaskbar) {
|
if (!global.setting.general.showHideDoubleClickTaskbar) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 不是左键的话
|
|
||||||
if (button !== 1) {
|
|
||||||
// 清除timeout
|
|
||||||
clearTimeout(global.doubleClickTaskbarTimer);
|
|
||||||
// 清空计数
|
|
||||||
global.doubleClickTaskbarCounter = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 获取屏幕
|
// 获取屏幕
|
||||||
let displays = getWindowInScreen();
|
let displays = getWindowInScreen();
|
||||||
if (displays.length > 1 || displays.length === 0) {
|
if (
|
||||||
|
button !== 1 ||
|
||||||
|
displays.length > 1 ||
|
||||||
|
displays.length === 0 ||
|
||||||
|
className !== "Shell_TrayWnd"
|
||||||
|
) {
|
||||||
// 清除timeout
|
// 清除timeout
|
||||||
clearTimeout(global.doubleClickTaskbarTimer);
|
clearTimeout(global.doubleClickTaskbarTimer);
|
||||||
// 清空计数
|
// 清空计数
|
||||||
global.doubleClickTaskbarCounter = 0;
|
global.doubleClickTaskbarCounter = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 获取鼠标位置
|
|
||||||
let point = screen.getCursorScreenPoint();
|
|
||||||
// 判断鼠标是否在当前屏幕内
|
|
||||||
if (
|
|
||||||
point.x >= displays[0].bounds.x &&
|
|
||||||
point.x <= displays[0].bounds.x + displays[0].bounds.width &&
|
|
||||||
point.y >= displays[0].bounds.y &&
|
|
||||||
point.y <= displays[0].bounds.y + displays[0].bounds.height
|
|
||||||
) {
|
|
||||||
// 判断是否双击在任务栏上
|
|
||||||
let flag = false;
|
|
||||||
// 判断任务栏在哪一侧
|
|
||||||
if (displays[0].bounds.height > displays[0].workArea.height) {
|
|
||||||
if (displays[0].bounds.y === displays[0].workArea.y) {
|
|
||||||
// 底部
|
|
||||||
let top = displays[0].workArea.y + displays[0].workArea.height;
|
|
||||||
let bottom = displays[0].bounds.y + displays[0].bounds.height;
|
|
||||||
if (point.y >= top && point.y <= bottom) {
|
|
||||||
flag = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 顶部
|
|
||||||
if (
|
|
||||||
point.y >= displays[0].bounds.y &&
|
|
||||||
point.y <= displays[0].workArea.y
|
|
||||||
) {
|
|
||||||
flag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (displays[0].bounds.width > displays[0].workArea.width) {
|
|
||||||
if (displays[0].bounds.x === displays[0].workArea.x) {
|
|
||||||
// 右侧
|
|
||||||
let left = displays[0].workArea.x + displays[0].workArea.width;
|
|
||||||
let right = displays[0].bounds.x + displays[0].bounds.width;
|
|
||||||
if (point.x >= left && point.x <= right) {
|
|
||||||
flag = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 左侧
|
|
||||||
if (
|
|
||||||
point.x >= displays[0].bounds.x &&
|
|
||||||
point.x <= displays[0].workArea.x
|
|
||||||
) {
|
|
||||||
flag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (flag) {
|
|
||||||
// 监听双击
|
// 监听双击
|
||||||
if (!global.doubleClickTaskbarCounter) {
|
if (!global.doubleClickTaskbarCounter) {
|
||||||
global.doubleClickTaskbarCounter = 0;
|
global.doubleClickTaskbarCounter = 0;
|
||||||
@ -659,9 +613,11 @@ function doubleClickTaskbar(button: number) {
|
|||||||
clearTimeout(global.doubleClickTaskbarTimer);
|
clearTimeout(global.doubleClickTaskbarTimer);
|
||||||
// 清空计数
|
// 清空计数
|
||||||
global.doubleClickTaskbarCounter = 0;
|
global.doubleClickTaskbarCounter = 0;
|
||||||
// 判断点击的窗口ClassName
|
if (
|
||||||
let className = global.addon.getCursorPosWindowClassName();
|
(release().startsWith("10.0.1") &&
|
||||||
if (className.indexOf("MSTask") >= 0 || className === "Shell_TrayWnd") {
|
global.addon.getCursorPosWindowClassName().indexOf("MSTask") >= 0) ||
|
||||||
|
release().startsWith("10.0.2")
|
||||||
|
) {
|
||||||
if (mainWindow.isVisible()) {
|
if (mainWindow.isVisible()) {
|
||||||
hideMainWindow();
|
hideMainWindow();
|
||||||
} else {
|
} else {
|
||||||
@ -674,18 +630,6 @@ function doubleClickTaskbar(button: number) {
|
|||||||
global.doubleClickTaskbarCounter = 0;
|
global.doubleClickTaskbarCounter = 0;
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 清除timeout
|
|
||||||
clearTimeout(global.doubleClickTaskbarTimer);
|
|
||||||
// 清空计数
|
|
||||||
global.doubleClickTaskbarCounter = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 清除timeout
|
|
||||||
clearTimeout(global.doubleClickTaskbarTimer);
|
|
||||||
// 清空计数
|
|
||||||
global.doubleClickTaskbarCounter = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -514,6 +514,7 @@ struct MouseEvent {
|
|||||||
y: i32,
|
y: i32,
|
||||||
button: i32,
|
button: i32,
|
||||||
mouse_data: u32,
|
mouse_data: u32,
|
||||||
|
class_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -526,6 +527,8 @@ unsafe extern "system" fn mouse_proc(code: i32, wparam: WPARAM, lparam: LPARAM)
|
|||||||
let x = (*msll_struct).pt.x;
|
let x = (*msll_struct).pt.x;
|
||||||
let y = (*msll_struct).pt.y;
|
let y = (*msll_struct).pt.y;
|
||||||
let mouse_data = (*msll_struct).mouseData;
|
let mouse_data = (*msll_struct).mouseData;
|
||||||
|
// 类名
|
||||||
|
let mut class_name = String::new();
|
||||||
// 参数
|
// 参数
|
||||||
let param = wparam.0 as u32;
|
let param = wparam.0 as u32;
|
||||||
// 事件
|
// 事件
|
||||||
@ -540,11 +543,14 @@ unsafe extern "system" fn mouse_proc(code: i32, wparam: WPARAM, lparam: LPARAM)
|
|||||||
// 鼠标操作
|
// 鼠标操作
|
||||||
if param == WM_LBUTTONUP || param == WM_RBUTTONUP || param == WM_MBUTTONUP {
|
if param == WM_LBUTTONUP || param == WM_RBUTTONUP || param == WM_MBUTTONUP {
|
||||||
event.push_str("mouseup");
|
event.push_str("mouseup");
|
||||||
|
class_name.push_str(&get_foreground_window_class_name());
|
||||||
} else if param == WM_LBUTTONDOWN || param == WM_RBUTTONDOWN || param == WM_MBUTTONDOWN
|
} else if param == WM_LBUTTONDOWN || param == WM_RBUTTONDOWN || param == WM_MBUTTONDOWN
|
||||||
{
|
{
|
||||||
event.push_str("mousedown");
|
event.push_str("mousedown");
|
||||||
|
class_name.push_str(&get_foreground_window_class_name());
|
||||||
} else if param == WM_MOUSEWHEEL || param == WM_MOUSEHWHEEL {
|
} else if param == WM_MOUSEWHEEL || param == WM_MOUSEHWHEEL {
|
||||||
event.push_str("mousewheel");
|
event.push_str("mousewheel");
|
||||||
|
class_name.push_str(&get_foreground_window_class_name());
|
||||||
}
|
}
|
||||||
// 按键类型
|
// 按键类型
|
||||||
if param == WM_LBUTTONUP || param == WM_LBUTTONDOWN {
|
if param == WM_LBUTTONUP || param == WM_LBUTTONDOWN {
|
||||||
@ -567,6 +573,7 @@ unsafe extern "system" fn mouse_proc(code: i32, wparam: WPARAM, lparam: LPARAM)
|
|||||||
y,
|
y,
|
||||||
mouse_data,
|
mouse_data,
|
||||||
button,
|
button,
|
||||||
|
class_name,
|
||||||
};
|
};
|
||||||
func.call(
|
func.call(
|
||||||
Ok(serde_json::to_string(&mouse_event).unwrap()),
|
Ok(serde_json::to_string(&mouse_event).unwrap()),
|
||||||
@ -749,3 +756,17 @@ pub fn get_appx_list() -> Vec<HashMap<String, String>> {
|
|||||||
}
|
}
|
||||||
result_list
|
result_list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前活跃窗口的类名
|
||||||
|
*/
|
||||||
|
fn get_foreground_window_class_name() -> String {
|
||||||
|
let hwnd = unsafe { GetForegroundWindow() };
|
||||||
|
// 获取窗口的ClassName
|
||||||
|
let mut buffer = [0u16; MAX_PATH as usize];
|
||||||
|
unsafe {
|
||||||
|
GetClassNameW(hwnd, &mut buffer);
|
||||||
|
};
|
||||||
|
// 返回
|
||||||
|
u16_to_string(&buffer)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user