mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-02-23 07:22:17 +08:00
bug(setting): fix size and pos error
This commit is contained in:
parent
2578449304
commit
96821e1c9e
@ -10,9 +10,7 @@
|
|||||||
"tauri": "tauri"
|
"tauri": "tauri"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tauri-apps/api": ">=2.0.0-beta.0",
|
"@tauri-apps/api": ">=2.0.0-beta.8",
|
||||||
"@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"
|
||||||
|
@ -11,8 +11,7 @@ edition = "2021"
|
|||||||
tauri-build = { version = "2.0.0-beta", features = [] }
|
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.15", features = ["macos-private-api"] }
|
||||||
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,8 +13,6 @@
|
|||||||
"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"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,14 @@ fn start_scrcpy_server(
|
|||||||
async fn main() {
|
async fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
|
// let main_window = app.get_webview_window("main").unwrap();
|
||||||
|
// main_window
|
||||||
|
// .set_size(tauri::Size::Logical(tauri::LogicalSize {
|
||||||
|
// width: 1350.,
|
||||||
|
// height: 750.,
|
||||||
|
// }))
|
||||||
|
// .unwrap();
|
||||||
|
|
||||||
// check resource files
|
// check resource files
|
||||||
ResHelper::res_init(
|
ResHelper::res_init(
|
||||||
&app.path()
|
&app.path()
|
||||||
@ -120,44 +128,8 @@ async fn main() {
|
|||||||
.join("resource"),
|
.join("resource"),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let main_window = app.get_webview_window("main").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();
|
|
||||||
|
|
||||||
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(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.plugin(tauri_plugin_os::init())
|
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
adb_devices,
|
adb_devices,
|
||||||
forward_server_port,
|
forward_server_port,
|
||||||
|
@ -29,7 +29,6 @@ import {
|
|||||||
.container {
|
.container {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: auto;
|
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 70px 1fr;
|
grid-template-columns: 70px 1fr;
|
||||||
grid-template-rows: 30px 1fr;
|
grid-template-rows: 30px 1fr;
|
||||||
|
@ -28,6 +28,7 @@ import {
|
|||||||
NFormItem,
|
NFormItem,
|
||||||
NIcon,
|
NIcon,
|
||||||
NSpin,
|
NSpin,
|
||||||
|
NScrollbar,
|
||||||
DataTableColumns,
|
DataTableColumns,
|
||||||
DropdownOption,
|
DropdownOption,
|
||||||
useDialog,
|
useDialog,
|
||||||
@ -213,6 +214,7 @@ async function refreshDevices() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<NScrollbar>
|
||||||
<div class="device">
|
<div class="device">
|
||||||
<NSpin :show="store.showLoadingRef">
|
<NSpin :show="store.showLoadingRef">
|
||||||
<NH4 prefix="bar">本地端口</NH4>
|
<NH4 prefix="bar">本地端口</NH4>
|
||||||
@ -223,7 +225,7 @@ async function refreshDevices() {
|
|||||||
:max="49151"
|
:max="49151"
|
||||||
style="max-width: 300px"
|
style="max-width: 300px"
|
||||||
/>
|
/>
|
||||||
<NH4 prefix="bar">屏幕尺寸</NH4>
|
<NH4 prefix="bar">设备尺寸</NH4>
|
||||||
<NFlex justify="left" align="center">
|
<NFlex justify="left" align="center">
|
||||||
<NFormItem label="宽度">
|
<NFormItem label="宽度">
|
||||||
<NInputNumber
|
<NInputNumber
|
||||||
@ -312,17 +314,14 @@ async function refreshDevices() {
|
|||||||
/>
|
/>
|
||||||
</NSpin>
|
</NSpin>
|
||||||
</div>
|
</div>
|
||||||
|
</NScrollbar>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.device {
|
.device {
|
||||||
color: var(--light-color);
|
color: var(--light-color);
|
||||||
background-color: var(--bg-color);
|
background-color: var(--bg-color);
|
||||||
padding: 0 25px;
|
padding: 0 20px;
|
||||||
}
|
|
||||||
|
|
||||||
.n-h4 {
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.controled-device-list {
|
.controled-device-list {
|
||||||
|
@ -12,14 +12,14 @@ import {
|
|||||||
NIcon,
|
NIcon,
|
||||||
FormInst,
|
FormInst,
|
||||||
useMessage,
|
useMessage,
|
||||||
NP,
|
|
||||||
} from "naive-ui";
|
} from "naive-ui";
|
||||||
import {
|
import {
|
||||||
|
LogicalPosition,
|
||||||
|
LogicalSize,
|
||||||
PhysicalPosition,
|
PhysicalPosition,
|
||||||
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";
|
||||||
|
|
||||||
@ -27,34 +27,25 @@ let unlistenResize: UnlistenFn = () => {};
|
|||||||
let unlistenMove: UnlistenFn = () => {};
|
let unlistenMove: UnlistenFn = () => {};
|
||||||
|
|
||||||
let factor = 1;
|
let factor = 1;
|
||||||
let platformName = "";
|
|
||||||
|
|
||||||
// macos: use logical position and size to refresh the area model
|
// macos: use logical position and size to refresh the area model
|
||||||
// others: use pyhsical 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) {
|
||||||
|
const lSize = size?.toLogical(factor);
|
||||||
|
const lPos = pos?.toLogical(factor);
|
||||||
|
|
||||||
// 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
|
// use logical position and size
|
||||||
if (size !== undefined) {
|
if (lSize !== undefined) {
|
||||||
areaModel.value.sizeW = Math.floor((size.width - ml) / factor);
|
areaModel.value.sizeW = lSize.width - ml;
|
||||||
areaModel.value.sizeH = Math.floor((size.height - mt) / factor);
|
areaModel.value.sizeH = lSize.height - mt;
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
if (lPos !== undefined) {
|
||||||
|
areaModel.value.posX = lPos.x + ml;
|
||||||
|
areaModel.value.posY = lPos.y + mt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +101,6 @@ function handleAdjustClick(e: MouseEvent) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 等待官方合并修复分支后检查表现是否正常
|
|
||||||
// move and resize window to the selected window (control) area
|
// move and resize window to the selected window (control) area
|
||||||
async function adjustMaskArea() {
|
async function adjustMaskArea() {
|
||||||
// header size and sidebar size
|
// header size and sidebar size
|
||||||
@ -119,30 +109,23 @@ async function adjustMaskArea() {
|
|||||||
|
|
||||||
const appWindow = getCurrent();
|
const appWindow = getCurrent();
|
||||||
|
|
||||||
const pos = new PhysicalPosition(
|
const pos = new LogicalPosition(
|
||||||
areaModel.value.posX - ml,
|
areaModel.value.posX - ml,
|
||||||
areaModel.value.posY - mt
|
areaModel.value.posY - mt
|
||||||
);
|
);
|
||||||
|
|
||||||
const size = new PhysicalSize(
|
const size = new LogicalSize(
|
||||||
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();
|
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);
|
||||||
@ -165,7 +148,7 @@ onUnmounted(() => {
|
|||||||
<template>
|
<template>
|
||||||
<div class="setting-page">
|
<div class="setting-page">
|
||||||
<NFlex justify="space-between" align="center">
|
<NFlex justify="space-between" align="center">
|
||||||
<NH4 prefix="bar">手动调整</NH4>
|
<NH4 prefix="bar">蒙版调整</NH4>
|
||||||
<NButton
|
<NButton
|
||||||
tertiary
|
tertiary
|
||||||
circle
|
circle
|
||||||
@ -213,7 +196,6 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
</NFormItemGi>
|
</NFormItemGi>
|
||||||
</NGrid>
|
</NGrid>
|
||||||
<NP>提示:使用物理坐标、尺寸</NP>
|
|
||||||
</NForm>
|
</NForm>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -31,7 +31,8 @@ import { NTabs, NTabPane, NScrollbar } from "naive-ui";
|
|||||||
.setting {
|
.setting {
|
||||||
background-color: var(--content-bg-color);
|
background-color: var(--content-bg-color);
|
||||||
color: var(--light-color);
|
color: var(--light-color);
|
||||||
overflow: hidden;
|
height: 100%;
|
||||||
|
overflow-y: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
.NTabPane {
|
.NTabPane {
|
||||||
|
Loading…
Reference in New Issue
Block a user