diff --git a/package.json b/package.json index 39014eb..4563ac7 100644 --- a/package.json +++ b/package.json @@ -10,21 +10,22 @@ "tauri": "tauri" }, "dependencies": { + "@tauri-apps/api": ">=2.0.0-beta.0", + "@tauri-apps/plugin-os": "2.0.0-beta.2", + "@tauri-apps/plugin-shell": ">=2.0.0-beta.0", "pinia": "^2.1.7", "vue": "^3.3.4", - "vue-router": "4", - "@tauri-apps/api": ">=2.0.0-beta.0", - "@tauri-apps/plugin-shell": ">=2.0.0-beta.0" + "vue-router": "4" }, "devDependencies": { - "@vitejs/plugin-vue": "^5.0.4", - "typescript": "^5.0.2", - "vite": "^5.0.0", - "vue-tsc": "^1.8.5", "@tauri-apps/cli": ">=2.0.0-beta.0", "@vicons/fluent": "^0.12.0", "@vicons/ionicons5": "^0.12.0", + "@vitejs/plugin-vue": "^5.0.4", "naive-ui": "^2.38.1", - "sass": "^1.71.1" + "sass": "^1.71.1", + "typescript": "^5.0.2", + "vite": "^5.0.0", + "vue-tsc": "^1.8.5" } } diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 0f81b51..0ce2459 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -12,7 +12,7 @@ tauri-build = { version = "2.0.0-beta", features = [] } [dependencies] tauri = { version = "2.0.0-beta", features = ["macos-private-api"] } -tauri-plugin-shell = "2.0.0-beta" +tauri-plugin-os = "2.0.0-beta" serde = { version = "1", features = ["derive"] } serde_json = "1" anyhow = "1.0" diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 774080e..dab3777 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -13,6 +13,8 @@ "window:allow-close", "window:allow-is-maximizable", "window:allow-start-dragging", - "window:allow-unmaximize" + "window:allow-unmaximize", + "os:default", + "os:allow-platform" ] } diff --git a/src-tauri/src/adb.rs b/src-tauri/src/adb.rs index 08c5b11..8e9edc0 100644 --- a/src-tauri/src/adb.rs +++ b/src-tauri/src/adb.rs @@ -1,8 +1,13 @@ use crate::resource::{ResHelper, ResourceName}; use std::{ - io::BufRead, os::windows::process::CommandExt, path::PathBuf, process::{Child, Command, Stdio} + io::BufRead, + path::PathBuf, + process::{Child, Command, Stdio}, }; +#[cfg(target_os = "windows")] +use std::os::windows::process::CommandExt; + use anyhow::{Context, Ok, Result}; #[derive(Clone, Debug, serde::Serialize)] @@ -87,12 +92,14 @@ pub struct Adb; /// But some output of command won't be output, like adb service startup information. impl Adb { fn cmd_base(res_dir: &PathBuf) -> Command { - let mut cmd = Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb)); - - #[cfg(target_os = "windows")] - cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW - - cmd + #[cfg(target_os = "windows")]{ + let mut cmd = Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb)); + cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW + cmd + } + #[cfg(not(target_os = "windows"))]{ + Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb)) + } } /// execute "adb devices" and return devices list diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e9b5aca..c3fb2a3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -132,33 +132,42 @@ async fn main() { .unwrap(); let main_window = app.get_webview_window("main").unwrap(); - let scale_factor = main_window.scale_factor().unwrap(); - main_window - .set_size(tauri::Size::Physical(tauri::PhysicalSize { - width: 1350, - height: 750, - })) - .unwrap(); - let zoomfactor = 1.0 / scale_factor; - main_window - .with_webview(move |webview| { - #[cfg(target_os = "windows")] - unsafe { - // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html - webview.controller().SetZoomFactor(zoomfactor).unwrap(); - } + #[cfg(windows)] + { + let scale_factor = main_window.scale_factor().unwrap(); + main_window + .set_size(tauri::Size::Physical(tauri::PhysicalSize { + width: 1350, + height: 750, + })) + .unwrap(); - // #[cfg(target_os = "macos")] - // unsafe { - // let () = msg_send![webview.inner(), setPageZoom: 4.]; - // } - }) - .unwrap(); + main_window + .with_webview(move |webview| { + unsafe { + // see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html + webview + .controller() + .SetZoomFactor(1.0 / scale_factor) + .unwrap(); + } + }) + .unwrap(); + } + #[cfg(target_os = "macos")] + { + main_window + .set_size(tauri::Size::Logical(tauri::LogicalSize { + width: 1350., + height: 750., + })) + .unwrap(); + } Ok(()) }) - .plugin(tauri_plugin_shell::init()) + .plugin(tauri_plugin_os::init()) .invoke_handler(tauri::generate_handler![ adb_devices, get_screen_size, diff --git a/src/components/setting/Mask.vue b/src/components/setting/Mask.vue index 1e285bf..bb6ac38 100644 --- a/src/components/setting/Mask.vue +++ b/src/components/setting/Mask.vue @@ -19,24 +19,42 @@ import { PhysicalSize, getCurrent, } from "@tauri-apps/api/window"; +import { platform } from "@tauri-apps/plugin-os"; import { SettingsOutline } from "@vicons/ionicons5"; import { UnlistenFn } from "@tauri-apps/api/event"; let unlistenResize: UnlistenFn = () => {}; let unlistenMove: UnlistenFn = () => {}; +let factor = 1; +let platformName = ""; + +// macos: use logical position and size to refresh the area model +// others: use pyhsical position and size to refresh the area model async function refreshAreaModel(size?: PhysicalSize, pos?: PhysicalPosition) { // header size and sidebar size const mt = 30; const ml = 70; - if (size !== undefined) { - areaModel.value.sizeW = Math.floor(size.width - ml); - areaModel.value.sizeH = Math.floor(size.height - mt); - } - if (pos !== undefined) { - areaModel.value.posX = Math.floor(pos.x + ml); - areaModel.value.posY = Math.floor(pos.y + mt); + if (platformName === "macos") { + // use logical position and size + if (size !== undefined) { + areaModel.value.sizeW = Math.floor((size.width - ml) / factor); + areaModel.value.sizeH = Math.floor((size.height - mt) / factor); + } + if (pos !== undefined) { + areaModel.value.posX = Math.floor((pos.x + ml) / factor); + areaModel.value.posY = Math.floor((pos.y + mt) / factor); + } + } else { + if (size !== undefined) { + areaModel.value.sizeW = Math.floor(size.width - ml); + areaModel.value.sizeH = Math.floor(size.height - mt); + } + if (pos !== undefined) { + areaModel.value.posX = Math.floor(pos.x + ml); + areaModel.value.posY = Math.floor(pos.y + mt); + } } } @@ -110,12 +128,22 @@ async function adjustMaskArea() { areaModel.value.sizeW + ml, areaModel.value.sizeH + mt ); - await appWindow.setPosition(pos); - await appWindow.setSize(size); + + if (platformName === "macos") { + // use logical position and size + await appWindow.setPosition(pos.toLogical(factor)); + await appWindow.setSize(size.toLogical(factor)); + } else { + await appWindow.setPosition(pos); + await appWindow.setSize(size); + } } onMounted(async () => { const appWindow = getCurrent(); + factor = await appWindow.scaleFactor(); + platformName = await platform(); + unlistenResize = await appWindow.onResized(({ payload: size }) => { refreshAreaModel(size, undefined); });