mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-02-22 14:42:15 +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"
|
"tauri": "tauri"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"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",
|
"pinia": "^2.1.7",
|
||||||
"vue": "^3.3.4",
|
"vue": "^3.3.4",
|
||||||
"vue-router": "4",
|
"vue-router": "4"
|
||||||
"@tauri-apps/api": ">=2.0.0-beta.0",
|
|
||||||
"@tauri-apps/plugin-shell": ">=2.0.0-beta.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"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",
|
"@tauri-apps/cli": ">=2.0.0-beta.0",
|
||||||
"@vicons/fluent": "^0.12.0",
|
"@vicons/fluent": "^0.12.0",
|
||||||
"@vicons/ionicons5": "^0.12.0",
|
"@vicons/ionicons5": "^0.12.0",
|
||||||
|
"@vitejs/plugin-vue": "^5.0.4",
|
||||||
"naive-ui": "^2.38.1",
|
"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]
|
[dependencies]
|
||||||
tauri = { version = "2.0.0-beta", features = ["macos-private-api"] }
|
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 = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
"window:allow-close",
|
"window:allow-close",
|
||||||
"window:allow-is-maximizable",
|
"window:allow-is-maximizable",
|
||||||
"window:allow-start-dragging",
|
"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 crate::resource::{ResHelper, ResourceName};
|
||||||
use std::{
|
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};
|
use anyhow::{Context, Ok, Result};
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Serialize)]
|
#[derive(Clone, Debug, serde::Serialize)]
|
||||||
@ -87,13 +92,15 @@ pub struct Adb;
|
|||||||
/// But some output of command won't be output, like adb service startup information.
|
/// But some output of command won't be output, like adb service startup information.
|
||||||
impl Adb {
|
impl Adb {
|
||||||
fn cmd_base(res_dir: &PathBuf) -> Command {
|
fn cmd_base(res_dir: &PathBuf) -> Command {
|
||||||
|
#[cfg(target_os = "windows")]{
|
||||||
let mut cmd = Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb));
|
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.creation_flags(0x08000000); // CREATE_NO_WINDOW
|
||||||
|
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
#[cfg(not(target_os = "windows"))]{
|
||||||
|
Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// execute "adb devices" and return devices list
|
/// execute "adb devices" and return devices list
|
||||||
pub fn cmd_devices(res_dir: &PathBuf) -> Result<Vec<Device>> {
|
pub fn cmd_devices(res_dir: &PathBuf) -> Result<Vec<Device>> {
|
||||||
|
@ -132,6 +132,9 @@ async fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let main_window = app.get_webview_window("main").unwrap();
|
let main_window = app.get_webview_window("main").unwrap();
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
let scale_factor = main_window.scale_factor().unwrap();
|
let scale_factor = main_window.scale_factor().unwrap();
|
||||||
main_window
|
main_window
|
||||||
.set_size(tauri::Size::Physical(tauri::PhysicalSize {
|
.set_size(tauri::Size::Physical(tauri::PhysicalSize {
|
||||||
@ -140,25 +143,31 @@ async fn main() {
|
|||||||
}))
|
}))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let zoomfactor = 1.0 / scale_factor;
|
|
||||||
main_window
|
main_window
|
||||||
.with_webview(move |webview| {
|
.with_webview(move |webview| {
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html
|
// see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html
|
||||||
webview.controller().SetZoomFactor(zoomfactor).unwrap();
|
webview
|
||||||
|
.controller()
|
||||||
|
.SetZoomFactor(1.0 / scale_factor)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(target_os = "macos")]
|
|
||||||
// unsafe {
|
|
||||||
// let () = msg_send![webview.inner(), setPageZoom: 4.];
|
|
||||||
// }
|
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
}
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
main_window
|
||||||
|
.set_size(tauri::Size::Logical(tauri::LogicalSize {
|
||||||
|
width: 1350.,
|
||||||
|
height: 750.,
|
||||||
|
}))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_os::init())
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
adb_devices,
|
adb_devices,
|
||||||
get_screen_size,
|
get_screen_size,
|
||||||
|
@ -19,17 +19,34 @@ import {
|
|||||||
PhysicalSize,
|
PhysicalSize,
|
||||||
getCurrent,
|
getCurrent,
|
||||||
} from "@tauri-apps/api/window";
|
} from "@tauri-apps/api/window";
|
||||||
|
import { platform } from "@tauri-apps/plugin-os";
|
||||||
import { SettingsOutline } from "@vicons/ionicons5";
|
import { SettingsOutline } from "@vicons/ionicons5";
|
||||||
import { UnlistenFn } from "@tauri-apps/api/event";
|
import { UnlistenFn } from "@tauri-apps/api/event";
|
||||||
|
|
||||||
let unlistenResize: UnlistenFn = () => {};
|
let unlistenResize: UnlistenFn = () => {};
|
||||||
let unlistenMove: 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) {
|
async function refreshAreaModel(size?: PhysicalSize, pos?: PhysicalPosition) {
|
||||||
// header size and sidebar size
|
// header size and sidebar size
|
||||||
const mt = 30;
|
const mt = 30;
|
||||||
const ml = 70;
|
const ml = 70;
|
||||||
|
|
||||||
|
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) {
|
if (size !== undefined) {
|
||||||
areaModel.value.sizeW = Math.floor(size.width - ml);
|
areaModel.value.sizeW = Math.floor(size.width - ml);
|
||||||
areaModel.value.sizeH = Math.floor(size.height - mt);
|
areaModel.value.sizeH = Math.floor(size.height - mt);
|
||||||
@ -39,6 +56,7 @@ async function refreshAreaModel(size?: PhysicalSize, pos?: PhysicalPosition) {
|
|||||||
areaModel.value.posY = Math.floor(pos.y + mt);
|
areaModel.value.posY = Math.floor(pos.y + mt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const message = useMessage();
|
const message = useMessage();
|
||||||
|
|
||||||
@ -110,12 +128,22 @@ async function adjustMaskArea() {
|
|||||||
areaModel.value.sizeW + ml,
|
areaModel.value.sizeW + ml,
|
||||||
areaModel.value.sizeH + mt
|
areaModel.value.sizeH + mt
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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.setPosition(pos);
|
||||||
await appWindow.setSize(size);
|
await appWindow.setSize(size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const appWindow = getCurrent();
|
const appWindow = getCurrent();
|
||||||
|
factor = await appWindow.scaleFactor();
|
||||||
|
platformName = await platform();
|
||||||
|
|
||||||
unlistenResize = await appWindow.onResized(({ payload: size }) => {
|
unlistenResize = await appWindow.onResized(({ payload: size }) => {
|
||||||
refreshAreaModel(size, undefined);
|
refreshAreaModel(size, undefined);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user