mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2024-11-12 20:11:21 +08:00
bug(macos): fix bug on macos
This commit is contained in:
parent
b9814a9aed
commit
32bf097f27
17
package.json
17
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"
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user