From 4d72d2d0dfd90e7eb4abb76325ad1aac1e7101a5 Mon Sep 17 00:00:00 2001 From: Sline Date: Tue, 10 Feb 2026 14:06:27 +0800 Subject: [PATCH] refactor: replace `winapi` w/ `windows` (#6291) --- Cargo.lock | 2 +- src-tauri/Cargo.toml | 16 +--------------- src-tauri/src/utils/schtasks.rs | 29 +++++------------------------ 3 files changed, 7 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7517ca18b..482ae9cd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1176,7 +1176,7 @@ dependencies = [ "tokio", "tokio-stream", "warp", - "winapi", + "windows 0.62.2", "winreg 0.55.0", "zip 7.4.0", ] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1af69080b..0c36be0ab 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -110,21 +110,7 @@ dark-light = { git = "https://github.com/rust-dark-light/dark-light" } deelevate = { workspace = true } runas = "=1.2.0" winreg = "0.55.0" -winapi = { version = "0.3.9", features = [ - "winbase", - "fileapi", - "winnt", - "handleapi", - "errhandlingapi", - "minwindef", - "winerror", - "stringapiset", - "tlhelp32", - "processthreadsapi", - "winhttp", - "winreg", - "winnls", -] } +windows = { version = "0.62.2", features = ["Win32_Globalization"] } [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] tauri-plugin-autostart = "2.5.1" diff --git a/src-tauri/src/utils/schtasks.rs b/src-tauri/src/utils/schtasks.rs index a566826ac..87edbaa70 100644 --- a/src-tauri/src/utils/schtasks.rs +++ b/src-tauri/src/utils/schtasks.rs @@ -5,8 +5,7 @@ use std::fs; use std::os::windows::process::CommandExt as _; use std::path::{Path, PathBuf}; use std::process::{Command, Output}; -use winapi::um::stringapiset::MultiByteToWideChar; -use winapi::um::winnls::{GetACP, GetOEMCP}; +use windows::Win32::Globalization::{GetACP, GetOEMCP, MULTI_BYTE_TO_WIDE_CHAR_FLAGS, MultiByteToWideChar}; const CREATE_NO_WINDOW: u32 = 0x08000000; const TASK_NAME_USER: &str = "Clash Verge"; @@ -207,34 +206,16 @@ fn decode_with_code_page(bytes: &[u8], code_page: u32) -> Option { return None; } - let required = unsafe { - MultiByteToWideChar( - code_page, - 0, - bytes.as_ptr() as *const i8, - len as i32, - std::ptr::null_mut(), - 0, - ) - }; + let required = unsafe { MultiByteToWideChar(code_page, MULTI_BYTE_TO_WIDE_CHAR_FLAGS(0), bytes, None) }; - if required == 0 { + if required <= 0 { return None; } let mut wide = vec![0u16; required as usize]; - let written = unsafe { - MultiByteToWideChar( - code_page, - 0, - bytes.as_ptr() as *const i8, - len as i32, - wide.as_mut_ptr(), - required, - ) - }; + let written = unsafe { MultiByteToWideChar(code_page, MULTI_BYTE_TO_WIDE_CHAR_FLAGS(0), bytes, Some(&mut wide)) }; - if written == 0 { + if written <= 0 { return None; }