mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-05-25 18:48:14 +08:00
fix: outerSize making window large
This commit is contained in:
parent
940d1699f8
commit
f71946566c
@ -1,9 +1,8 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use scrcpy_mask::{command, resource::ResHelper, share};
|
||||
use scrcpy_mask::{command, resource::ResHelper};
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_store::StoreExt;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@ -15,85 +14,8 @@ async fn main() {
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_store::Builder::new().build())
|
||||
.setup(|app| {
|
||||
let store = app
|
||||
.store("store.bin")
|
||||
.map_err(|_| "failed to load store".to_string())?;
|
||||
|
||||
// set adb path
|
||||
match store.get("adbPath") {
|
||||
Some(value) => {
|
||||
*share::ADB_PATH.lock().unwrap() = value.as_str().unwrap().to_string()
|
||||
}
|
||||
None => store.set("adbPath", "adb".to_string()),
|
||||
}
|
||||
|
||||
// restore window position and size
|
||||
match store.get("maskArea") {
|
||||
Some(value) => {
|
||||
// TODO check position and size validity
|
||||
|
||||
let pos_x = value["posX"].as_f64();
|
||||
let pos_y = value["posY"].as_f64();
|
||||
let mut size_w = value["sizeW"].as_i64().unwrap_or(800) as f64;
|
||||
let mut size_h = value["sizeH"].as_i64().unwrap_or(600) as f64;
|
||||
|
||||
let main_window: tauri::WebviewWindow = app.get_webview_window("main").unwrap();
|
||||
|
||||
main_window.set_zoom(1.).unwrap_or(());
|
||||
|
||||
// check size validity
|
||||
if size_w < 100.0 {
|
||||
size_w = 100.0;
|
||||
}
|
||||
if size_h < 100.0 {
|
||||
size_h = 100.0;
|
||||
}
|
||||
|
||||
if let Some(monitor) = main_window.primary_monitor().ok().flatten() {
|
||||
let size = monitor.size().to_logical::<f64>(monitor.scale_factor());
|
||||
let (max_w, max_h) = (size.width - 70.0, size.height - 30.0);
|
||||
if size_w > max_w {
|
||||
size_w = max_w;
|
||||
}
|
||||
if size_h > max_h {
|
||||
size_h = max_h;
|
||||
}
|
||||
}
|
||||
|
||||
main_window
|
||||
.set_size(tauri::Size::Logical(tauri::LogicalSize {
|
||||
width: size_w + 70.0,
|
||||
height: size_h + 30.0,
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
// check position validity
|
||||
if pos_x.is_none() || pos_y.is_none() {
|
||||
main_window.center().unwrap_or(());
|
||||
} else {
|
||||
let pos_x = pos_x.unwrap();
|
||||
let pos_y = pos_y.unwrap();
|
||||
main_window
|
||||
.set_position(tauri::Position::Logical(tauri::LogicalPosition {
|
||||
x: pos_x - 70.0,
|
||||
y: pos_y - 30.0,
|
||||
}))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let main_window: tauri::WebviewWindow = app.get_webview_window("main").unwrap();
|
||||
|
||||
main_window.center().unwrap_or(());
|
||||
|
||||
main_window
|
||||
.set_size(tauri::Size::Logical(tauri::LogicalSize {
|
||||
width: (800 + 70) as f64,
|
||||
height: (600 + 30) as f64,
|
||||
}))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
let main_window: tauri::WebviewWindow = app.get_webview_window("main").unwrap();
|
||||
main_window.set_zoom(1.).unwrap_or(());
|
||||
|
||||
// check resource files
|
||||
ResHelper::res_init(
|
||||
|
@ -15,7 +15,7 @@ import ScreenStream from "./ScreenStream.vue";
|
||||
import { getVersion } from "@tauri-apps/api/app";
|
||||
import { fetch } from "@tauri-apps/plugin-http";
|
||||
import { open } from "@tauri-apps/plugin-shell";
|
||||
import { getCurrentWindow, PhysicalSize } from "@tauri-apps/api/window";
|
||||
import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { checkAdbAvailable } from "../invoke";
|
||||
|
||||
@ -67,10 +67,12 @@ onMounted(async () => {
|
||||
const maskElement = document.getElementById("maskElement") as HTMLElement;
|
||||
const appWindow = getCurrentWindow();
|
||||
appWindow.onResized(() => {
|
||||
// TODO use store.curMaskSize
|
||||
store.maskSizeH = maskElement.clientHeight;
|
||||
store.maskSizeW = maskElement.clientWidth;
|
||||
});
|
||||
}, 500);
|
||||
console.log("mask mounted");
|
||||
});
|
||||
|
||||
let checkAdbMessage: MessageReactive | null = null;
|
||||
@ -100,10 +102,10 @@ function genClientId() {
|
||||
}
|
||||
|
||||
async function cleanAfterimage() {
|
||||
// TODO fix oldSize making window large
|
||||
const appWindow = getCurrentWindow();
|
||||
const oldSize = await appWindow.outerSize();
|
||||
const newSize = new PhysicalSize(oldSize.width, oldSize.height + 1);
|
||||
const scale = await appWindow.scaleFactor();
|
||||
const oldSize = (await appWindow.innerSize()).toLogical(scale);
|
||||
const newSize = new LogicalSize(oldSize.width, oldSize.height + 1);
|
||||
await appWindow.setSize(newSize);
|
||||
await appWindow.setSize(oldSize);
|
||||
}
|
||||
|
@ -20,8 +20,6 @@ import {
|
||||
import {
|
||||
LogicalPosition,
|
||||
LogicalSize,
|
||||
PhysicalPosition,
|
||||
PhysicalSize,
|
||||
getCurrentWindow,
|
||||
} from "@tauri-apps/api/window";
|
||||
import { SettingsOutline } from "@vicons/ionicons5";
|
||||
@ -41,6 +39,7 @@ const message = useMessage();
|
||||
const formRef = ref<FormInst | null>(null);
|
||||
|
||||
// logical pos and size of the mask area
|
||||
// TODO use store.curMaskSize and store.curMaskPos
|
||||
const curMaskArea = ref({
|
||||
posX: 0,
|
||||
posY: 0,
|
||||
@ -75,22 +74,20 @@ const areaFormRules: FormRules = {
|
||||
},
|
||||
};
|
||||
|
||||
async function refreshCurMaskArea(size?: PhysicalSize, pos?: PhysicalPosition) {
|
||||
const lSize = size?.toLogical(factor);
|
||||
const lPos = pos?.toLogical(factor);
|
||||
|
||||
async function refreshCurMaskArea(size?: LogicalSize, pos?: LogicalPosition) {
|
||||
// header size and sidebar size
|
||||
const mt = 30;
|
||||
const ml = 70;
|
||||
|
||||
// use logical position and size
|
||||
if (lSize !== undefined) {
|
||||
curMaskArea.value.sizeW = Math.round(lSize.width) - ml;
|
||||
curMaskArea.value.sizeH = Math.round(lSize.height) - mt;
|
||||
if (size !== undefined) {
|
||||
curMaskArea.value.sizeW = Math.round(size.width) - ml;
|
||||
curMaskArea.value.sizeH = Math.round(size.height) - mt;
|
||||
console.log(curMaskArea.value);
|
||||
}
|
||||
if (lPos !== undefined) {
|
||||
curMaskArea.value.posX = Math.round(lPos.x) + ml;
|
||||
curMaskArea.value.posY = Math.round(lPos.y) + mt;
|
||||
if (pos !== undefined) {
|
||||
curMaskArea.value.posX = Math.round(pos.x) + ml;
|
||||
curMaskArea.value.posY = Math.round(pos.y) + mt;
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,14 +132,14 @@ onMounted(async () => {
|
||||
factor = await appWindow.scaleFactor();
|
||||
|
||||
unlistenResize = await appWindow.onResized(({ payload: size }) => {
|
||||
refreshCurMaskArea(size, undefined);
|
||||
refreshCurMaskArea(size.toLogical(factor), undefined);
|
||||
});
|
||||
unlistenMove = await appWindow.onMoved(({ payload: position }) => {
|
||||
refreshCurMaskArea(undefined, position);
|
||||
refreshCurMaskArea(undefined, position.toLogical(factor));
|
||||
});
|
||||
refreshCurMaskArea(
|
||||
await appWindow.outerSize(),
|
||||
await appWindow.outerPosition()
|
||||
(await appWindow.outerSize()).toLogical(factor),
|
||||
(await appWindow.outerPosition()).toLogical(factor)
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -46,6 +46,7 @@ const store = useGlobalStore();
|
||||
background-color: var(--content-bg-color);
|
||||
color: var(--light-color);
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
display: flex;
|
||||
|
||||
.n-tabs {
|
||||
|
@ -178,10 +178,6 @@
|
||||
"note": "Note",
|
||||
"notePlaceholder": "Please enter note"
|
||||
},
|
||||
"KeyInfo": {
|
||||
"title": "按键信息",
|
||||
"note": "按下任意键"
|
||||
},
|
||||
"Observation": {
|
||||
"observation": "Observation",
|
||||
"scale": "Sensitivity",
|
||||
@ -261,6 +257,10 @@
|
||||
"pos": "Points",
|
||||
"editPos": "Edit",
|
||||
"editTips": "Left-click on a blank area to add a new coordinate point. \nLeft-click and drag to move a specific point, and right-click to delete the point."
|
||||
},
|
||||
"KeyInfo": {
|
||||
"title": "Key Info",
|
||||
"note": "Press any key"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -178,10 +178,6 @@
|
||||
"note": "备注",
|
||||
"notePlaceholder": "请输入备注"
|
||||
},
|
||||
"KeyInfo": {
|
||||
"title": "Key Info",
|
||||
"note": "Press any key"
|
||||
},
|
||||
"Observation": {
|
||||
"observation": "观察视角",
|
||||
"scale": "灵敏度",
|
||||
@ -261,6 +257,10 @@
|
||||
"pos": "坐标点",
|
||||
"editPos": "编辑",
|
||||
"editTips": "左键点击空白区域添加新坐标点。左键拖拽移动特定坐标点,右键删除特定坐标点"
|
||||
},
|
||||
"KeyInfo": {
|
||||
"title": "按键信息",
|
||||
"note": "按下任意按键"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -5,6 +5,12 @@ import { setAdbPath } from "../invoke";
|
||||
import { allLanguage } from "../i18n";
|
||||
import { locale } from "@tauri-apps/plugin-os";
|
||||
import { NonReactiveStore } from "./noneReactiveStore";
|
||||
import {
|
||||
getCurrentWindow,
|
||||
LogicalPosition,
|
||||
LogicalSize,
|
||||
primaryMonitor,
|
||||
} from "@tauri-apps/api/window";
|
||||
|
||||
export class LocalStore {
|
||||
public static store: Store;
|
||||
@ -88,8 +94,45 @@ async function initMaskArea() {
|
||||
sizeH: number;
|
||||
}>("maskArea")) ?? { posX: 100, posY: 100, sizeW: 800, sizeH: 600 };
|
||||
|
||||
// TODO check mask area valid and remove related code in rust
|
||||
NonReactiveStore.setLocal("maskArea", maskArea);
|
||||
// mask area validation
|
||||
const appWindow = getCurrentWindow();
|
||||
let { posX, posY, sizeW, sizeH } = maskArea;
|
||||
const mt = 30;
|
||||
const ml = 70;
|
||||
|
||||
// min size
|
||||
if (sizeW < 120) sizeW = 120;
|
||||
if (sizeH < 150) sizeH = 120;
|
||||
// max size
|
||||
const monitor = await primaryMonitor();
|
||||
const monitorSize = monitor?.size.toLogical(monitor.scaleFactor);
|
||||
if (monitorSize !== undefined) {
|
||||
if (sizeW > monitorSize.width - ml) sizeW = monitorSize.width - ml;
|
||||
if (sizeH > monitorSize.height - mt) sizeH = monitorSize.height - mt;
|
||||
}
|
||||
[sizeW, sizeH] = [sizeW, sizeH].map((v) => Math.round(v));
|
||||
appWindow.setSize(new LogicalSize(sizeW + ml, sizeH + mt));
|
||||
|
||||
// min pos (right bottom corner)
|
||||
// move to left top corner
|
||||
if (posX + sizeW < 0) posX = ml;
|
||||
if (posY + sizeH < 0) posY = mt;
|
||||
if (monitorSize !== undefined) {
|
||||
// max pos (left top corner)
|
||||
// move to right bottom corner
|
||||
if (posX > monitorSize.width) posX = monitorSize.width - sizeW;
|
||||
if (posY > monitorSize.height) posY = monitorSize.height - sizeH;
|
||||
}
|
||||
|
||||
[posX, posY] = [posX, posY].map((v) => Math.round(v));
|
||||
appWindow.setPosition(new LogicalPosition(posX - 70, posY - 30));
|
||||
|
||||
NonReactiveStore.setLocal("maskArea", {
|
||||
posX,
|
||||
posY,
|
||||
sizeW,
|
||||
sizeH,
|
||||
});
|
||||
}
|
||||
|
||||
// init keyMappingConfigList from local store
|
||||
|
Loading…
Reference in New Issue
Block a user