chore: fix types & styles

This commit is contained in:
DarkSky 2023-12-18 21:32:45 +08:00
parent 68646d5eac
commit baca5ec985
2 changed files with 613 additions and 635 deletions

View File

@ -29,8 +29,8 @@ use windows::{
Storage::FileSystem::SearchPathW, Storage::FileSystem::SearchPathW,
System::{ System::{
Com::{ Com::{
CoCreateInstance, CoInitializeEx, CoUninitialize, IPersistFile, CoCreateInstance, CoInitializeEx, CoUninitialize, IPersistFile, CLSCTX_INPROC_SERVER,
CLSCTX_INPROC_SERVER, COINIT_APARTMENTTHREADED, STGM_READ, COINIT_APARTMENTTHREADED, STGM_READ,
}, },
Environment::GetEnvironmentVariableW, Environment::GetEnvironmentVariableW,
SystemInformation::GetSystemDirectoryW, SystemInformation::GetSystemDirectoryW,
@ -43,19 +43,17 @@ use windows::{
Shell::{ Shell::{
BHID_SFUIObject, IContextMenu, IShellItem, IShellItemImageFactory, IShellLinkW, BHID_SFUIObject, IContextMenu, IShellItem, IShellItemImageFactory, IShellLinkW,
SHCreateItemFromParsingName, SHEmptyRecycleBinW, SHQueryUserNotificationState, SHCreateItemFromParsingName, SHEmptyRecycleBinW, SHQueryUserNotificationState,
ShellExecuteW, ShellLink, CMF_NORMAL, CMINVOKECOMMANDINFO, ShellExecuteW, ShellLink, CMF_NORMAL, CMINVOKECOMMANDINFO, QUNS_ACCEPTS_NOTIFICATIONS,
QUNS_ACCEPTS_NOTIFICATIONS, QUNS_APP, QUNS_BUSY, QUNS_NOT_PRESENT, QUNS_APP, QUNS_BUSY, QUNS_NOT_PRESENT, QUNS_PRESENTATION_MODE, QUNS_QUIET_TIME,
QUNS_PRESENTATION_MODE, QUNS_QUIET_TIME, QUNS_RUNNING_D3D_FULL_SCREEN, QUNS_RUNNING_D3D_FULL_SCREEN, SHERB_NOSOUND, SIIGBF_ICONONLY, SLGP_UNCPRIORITY,
SHERB_NOSOUND, SIIGBF_ICONONLY, SLGP_UNCPRIORITY,
}, },
WindowsAndMessaging::{ WindowsAndMessaging::{
CallNextHookEx, CreatePopupMenu, DestroyMenu, FindWindowW, GetClassNameW, CallNextHookEx, CreatePopupMenu, DestroyMenu, FindWindowW, GetClassNameW, GetCursorPos,
GetCursorPos, GetForegroundWindow, GetSystemMetrics, GetWindowRect, SendMessageW, GetForegroundWindow, GetSystemMetrics, GetWindowRect, SendMessageW, SetForegroundWindow,
SetForegroundWindow, SetWindowsHookExW, TrackPopupMenu, WindowFromPoint, HHOOK, SetWindowsHookExW, TrackPopupMenu, WindowFromPoint, HHOOK, MSLLHOOKSTRUCT, SC_MONITORPOWER,
MSLLHOOKSTRUCT, SC_MONITORPOWER, SM_CXSCREEN, SM_CYSCREEN, SW_NORMAL, SM_CXSCREEN, SM_CYSCREEN, SW_NORMAL, SW_SHOWDEFAULT, TPM_NONOTIFY, TPM_RETURNCMD,
SW_SHOWDEFAULT, TPM_NONOTIFY, TPM_RETURNCMD, WH_MOUSE_LL, WM_LBUTTONDOWN, WH_MOUSE_LL, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEHWHEEL,
WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEHWHEEL, WM_MOUSEMOVE, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_SYSCOMMAND,
WM_MOUSEWHEEL, WM_RBUTTONDOWN, WM_RBUTTONUP, WM_SYSCOMMAND,
}, },
}, },
}, },
@ -75,9 +73,8 @@ pub fn get_file_icon(path: &str) -> Option<String> {
let _ = CoInitializeEx(None, COINIT_APARTMENTTHREADED); let _ = CoInitializeEx(None, COINIT_APARTMENTTHREADED);
} }
// IShellItemImageFactory // IShellItemImageFactory
let result = unsafe { let result =
SHCreateItemFromParsingName::<PCWSTR, Option<_>, IShellItemImageFactory>(path, None) unsafe { SHCreateItemFromParsingName::<PCWSTR, Option<_>, IShellItemImageFactory>(path, None) };
};
if let Ok(shell_item_image_factory) = result { if let Ok(shell_item_image_factory) = result {
if let Some(mut image_buffer) = get_file_icon_image_buffer(&shell_item_image_factory, 256) { if let Some(mut image_buffer) = get_file_icon_image_buffer(&shell_item_image_factory, 256) {
// 判断像素点,是否是小图标 // 判断像素点,是否是小图标
@ -97,12 +94,10 @@ pub fn get_file_icon(path: &str) -> Option<String> {
} }
} }
// 计算如果透明区域大于百分之70就代表是小图标 // 计算如果透明区域大于百分之70就代表是小图标
let proportion = let proportion = (transparency / (transparency + non_transparency) * 100_f64).round() as u32;
(transparency / (transparency + non_transparency) * 100_f64).round() as u32;
if proportion >= 70 { if proportion >= 70 {
// 获取小图标 // 获取小图标
if let Some(image_buffer_small) = if let Some(image_buffer_small) = get_file_icon_image_buffer(&shell_item_image_factory, 48)
get_file_icon_image_buffer(&shell_item_image_factory, 48)
{ {
image_buffer = image_buffer_small; image_buffer = image_buffer_small;
} }
@ -338,9 +333,7 @@ pub fn explorer_context_menu(window: i32, path: &str, x: i32, y: i32) {
// Menu // Menu
if let Ok(menu) = unsafe { CreatePopupMenu() } { if let Ok(menu) = unsafe { CreatePopupMenu() } {
// 写入菜单 // 写入菜单
if let Ok(()) = if let Ok(()) = unsafe { context_menu.QueryContextMenu(menu, 0, 1, 0x7FFF, CMF_NORMAL) } {
unsafe { context_menu.QueryContextMenu(menu, 0, 1, 0x7FFF, CMF_NORMAL) }
{
// HWND // HWND
let hwnd = HWND(window as isize); let hwnd = HWND(window as isize);
// 弹出菜单 // 弹出菜单
@ -459,31 +452,21 @@ fn is_fullscreen_window() -> bool {
*/ */
pub fn is_fullscreen() -> bool { pub fn is_fullscreen() -> bool {
if let Ok(state) = unsafe { SHQueryUserNotificationState() } { if let Ok(state) = unsafe { SHQueryUserNotificationState() } {
if state == QUNS_NOT_PRESENT { match state {
// 非全屏(机器锁定/屏幕保护程序/用户切换)
return false;
} else if state == QUNS_BUSY {
// 全屏F11 全屏,我试过的所有视频游戏都使用它) // 全屏F11 全屏,我试过的所有视频游戏都使用它)
return is_fullscreen_window(); QUNS_BUSY => is_fullscreen_window(),
} else if state == QUNS_RUNNING_D3D_FULL_SCREEN {
// 全屏Direct3D 应用程序以独占模式运行,即全屏) // 全屏Direct3D 应用程序以独占模式运行,即全屏)
return true; QUNS_RUNNING_D3D_FULL_SCREEN |
} else if state == QUNS_PRESENTATION_MODE {
// 全屏(一种用于显示全屏演示文稿的特殊模式) // 全屏(一种用于显示全屏演示文稿的特殊模式)
return true; QUNS_PRESENTATION_MODE => true,
} else if state == QUNS_ACCEPTS_NOTIFICATIONS { QUNS_NOT_PRESENT | // 非全屏(机器锁定/屏幕保护程序/用户切换)
// 不是全屏 QUNS_ACCEPTS_NOTIFICATIONS |QUNS_QUIET_TIME |QUNS_APP => false,
return false; _ =>false
} else if state == QUNS_QUIET_TIME {
// 不是全屏
return false;
} else if state == QUNS_APP {
// 不是全屏
return false;
}
} }
} else {
false false
} }
}
/** /**
* *
@ -544,8 +527,7 @@ 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()); 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()); 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 {
@ -565,7 +547,7 @@ unsafe extern "system" fn mouse_proc(code: i32, wparam: WPARAM, lparam: LPARAM)
button = 1; button = 1;
} }
} }
if event != "" { if event.is_empty() {
if let Some(func) = TSFN.as_ref() { if let Some(func) = TSFN.as_ref() {
let mouse_event = MouseEvent { let mouse_event = MouseEvent {
event, event,
@ -582,7 +564,7 @@ unsafe extern "system" fn mouse_proc(code: i32, wparam: WPARAM, lparam: LPARAM)
} }
} }
} }
return CallNextHookEx(MOUSE_HOOK.unwrap(), code, wparam, lparam); CallNextHookEx(MOUSE_HOOK.unwrap(), code, wparam, lparam)
} }
/** /**
@ -590,8 +572,7 @@ unsafe extern "system" fn mouse_proc(code: i32, wparam: WPARAM, lparam: LPARAM)
*/ */
pub fn create_mouse_hook(callback: JsFunction) { pub fn create_mouse_hook(callback: JsFunction) {
// 创建回调 // 创建回调
if let Ok(threadsafe_function) = if let Ok(threadsafe_function) = callback.create_threadsafe_function(0, |ctx| Ok(vec![ctx.value]))
callback.create_threadsafe_function(0, |ctx| Ok(vec![ctx.value]))
{ {
unsafe { TSFN = Some(threadsafe_function) }; unsafe { TSFN = Some(threadsafe_function) };
// 创建鼠标HOOK // 创建鼠标HOOK
@ -652,10 +633,7 @@ pub fn get_clipboard_file_list() -> Vec<String> {
* BITMAP * BITMAP
*/ */
pub fn clipboard_has_bitmap() -> bool { pub fn clipboard_has_bitmap() -> bool {
match get_clipboard(formats::Bitmap) { get_clipboard(formats::Bitmap).is_ok()
Ok(_) => true,
Err(_) => false,
}
} }
/** /**
@ -736,14 +714,13 @@ pub fn get_appx_list() -> Vec<HashMap<String, String>> {
if let Ok(app_list) = package.GetAppListEntriesAsync() { if let Ok(app_list) = package.GetAppListEntriesAsync() {
if let Ok(app_list) = app_list.get() { if let Ok(app_list) = app_list.get() {
for (index, app) in app_list.into_iter().enumerate() { for (index, app) in app_list.into_iter().enumerate() {
if app.DisplayInfo().is_err() if app.DisplayInfo().is_err() || app.DisplayInfo().unwrap().DisplayName().is_err() {
|| app.DisplayInfo().unwrap().DisplayName().is_err()
{
continue; continue;
} }
map.insert( map.insert(
format!("appName{}", index), format!("appName{}", index),
app.DisplayInfo() app
.DisplayInfo()
.unwrap() .unwrap()
.DisplayName() .DisplayName()
.unwrap() .unwrap()

View File

@ -1,75 +1,76 @@
import { BrowserWindow, Tray } from "electron"; import { BrowserWindow, Tray } from 'electron'
import { FSWatcher } from "node:fs"; import { FSWatcher } from 'node:fs'
import { Setting } from "../../types/setting"; import { Setting } from '../../types/setting'
import * as Addon from '@dawn-launcher/addon'
declare global { declare global {
// addon // addon
var addon: any; var addon: typeof Addon
// 语言 // 语言
var language: any; var language: any
// 主窗口 // 主窗口
var mainWindow: BrowserWindow | null; var mainWindow: BrowserWindow | null
// 快速搜索窗口 // 快速搜索窗口
var quickSearchWindow: BrowserWindow | null; var quickSearchWindow: BrowserWindow | null
// 快速搜索窗口是否初始化完成 // 快速搜索窗口是否初始化完成
var quickSearchWindowInit: Boolean | null; var quickSearchWindowInit: Boolean | null
// 设置窗口 // 设置窗口
var settingWindow: BrowserWindow | null; var settingWindow: BrowserWindow | null
// 分类添加/编辑窗口 // 分类添加/编辑窗口
var classificationAddEditWindow: BrowserWindow | null; var classificationAddEditWindow: BrowserWindow | null
// 分类图标窗口 // 分类图标窗口
var classificationSetIconWindow: BrowserWindow | null; var classificationSetIconWindow: BrowserWindow | null
// 关联分类窗口 // 关联分类窗口
var classificationAssociateFolderWindow: BrowserWindow | null; var classificationAssociateFolderWindow: BrowserWindow | null
// 聚合分类窗口 // 聚合分类窗口
var classificationAggregateWindow: BrowserWindow | null; var classificationAggregateWindow: BrowserWindow | null
// 项目添加/编辑窗口 // 项目添加/编辑窗口
var itemAddEditWindow: BrowserWindow | null; var itemAddEditWindow: BrowserWindow | null
// 项目网络图标窗口 // 项目网络图标窗口
var itemNetworkIconWindow: BrowserWindow | null; var itemNetworkIconWindow: BrowserWindow | null
// 项目SVG图标窗口 // 项目SVG图标窗口
var itemSVGIconWindow: BrowserWindow | null; var itemSVGIconWindow: BrowserWindow | null
// 关于窗口 // 关于窗口
var aboutWindow: BrowserWindow | null; var aboutWindow: BrowserWindow | null
// 备份/恢复数据窗口 // 备份/恢复数据窗口
var backupRestoreDataWindow: BrowserWindow | null; var backupRestoreDataWindow: BrowserWindow | null
// 存储关联分类监听 // 存储关联分类监听
var associateFolderWatcher: Map<number, AssociateFolderData>; var associateFolderWatcher: Map<number, AssociateFolderData>
// 设置 // 设置
var setting: Setting | null; var setting: Setting | null
// 托盘 // 托盘
var tray: Tray; var tray: Tray
// 主窗口方向 // 主窗口方向
var mainWindowDirection: String | null; var mainWindowDirection: String | null
// 停靠在桌面边缘时自动隐藏timer // 停靠在桌面边缘时自动隐藏timer
var autoHideTimer: NodeJS.Timeout; var autoHideTimer: NodeJS.Timeout
// 需要失去焦点时隐藏 // 需要失去焦点时隐藏
var blurHide: boolean | null; var blurHide: boolean | null
// 双击任务栏显示/隐藏timer // 双击任务栏显示/隐藏timer
var doubleClickTaskbarTimer: NodeJS.Timeout; var doubleClickTaskbarTimer: NodeJS.Timeout
// 双击任务栏显示/隐藏counter // 双击任务栏显示/隐藏counter
var doubleClickTaskbarCounter: number; var doubleClickTaskbarCounter: number
// 监测无效项目interval // 监测无效项目interval
var checkInvalidItemInterval: NodeJS.Timeout; var checkInvalidItemInterval: NodeJS.Timeout
// 存储子进程信息 // 存储子进程信息
var childProcessMap: Map<number, ChildProcessInfo>; var childProcessMap: Map<number, ChildProcessInfo>
// 分类右键菜单显示 // 分类右键菜单显示
var classificationRightMenu: boolean | null; var classificationRightMenu: boolean | null
// 项目右键菜单显示 // 项目右键菜单显示
var itemRightMenu: boolean | null; var itemRightMenu: boolean | null
} }
export interface ChildProcessInfo { export interface ChildProcessInfo {
utilityProcess: Electron.UtilityProcess; utilityProcess: Electron.UtilityProcess
port1: Electron.MessagePortMain; port1: Electron.MessagePortMain
port2: Electron.MessagePortMain; port2: Electron.MessagePortMain
} }
export interface AssociateFolderData { export interface AssociateFolderData {
classificationId: number; classificationId: number
dir: string; dir: string
hiddenItems: string | null; hiddenItems: string | null
watch: FSWatcher; watch: FSWatcher
} }
export {}; export {}