feat(store): store mask area data

This commit is contained in:
AkiChase 2024-04-16 21:50:00 +08:00
parent 96821e1c9e
commit 3855814dce
9 changed files with 89 additions and 44 deletions

View File

@ -11,6 +11,7 @@
},
"dependencies": {
"@tauri-apps/api": ">=2.0.0-beta.8",
"@tauri-apps/plugin-store": "2.0.0-beta.2",
"pinia": "^2.1.7",
"vue": "^3.3.4",
"vue-router": "4"

View File

@ -12,6 +12,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies]
tauri = { version = "2.0.0-beta.15", features = ["macos-private-api"] }
tauri-plugin-store = "2.0.0-beta.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
anyhow = "1.0"

View File

@ -2,7 +2,9 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"windows": [
"main"
],
"permissions": [
"event:default",
"window:default",
@ -13,6 +15,11 @@
"window:allow-close",
"window:allow-is-maximizable",
"window:allow-start-dragging",
"window:allow-unmaximize"
"window:allow-unmaximize",
"store:default",
"store:allow-get",
"store:allow-set",
"store:allow-save",
"store:allow-load"
]
}
}

View File

@ -66,12 +66,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 {
#[cfg(target_os = "windows")]{
#[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"))]{
#[cfg(not(target_os = "windows"))]
{
Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb))
}
}

View File

@ -1,7 +1,7 @@
pub mod adb;
pub mod resource;
pub mod client;
pub mod socket;
pub mod binary;
pub mod client;
pub mod control_msg;
pub mod scrcpy_mask_cmd;
pub mod resource;
pub mod scrcpy_mask_cmd;
pub mod socket;

View File

@ -111,14 +111,41 @@ fn start_scrcpy_server(
#[tokio::main]
async fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::new().build())
.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();
let stores = app
.app_handle()
.state::<tauri_plugin_store::StoreCollection<tauri::Wry>>();
let path = std::path::PathBuf::from("store.bin");
tauri_plugin_store::with_store(app.app_handle().clone(), stores, path, |store| {
// restore window position and size
match store.get("maskArea") {
Some(value) => {
let pos_x = value["posX"].as_i64().unwrap();
let pos_y = value["posY"].as_i64().unwrap();
let size_w = value["sizeW"].as_i64().unwrap();
let size_h = value["sizeH"].as_i64().unwrap();
let main_window: tauri::WebviewWindow =
app.get_webview_window("main").unwrap();
main_window
.set_position(tauri::Position::Logical(tauri::LogicalPosition {
x: (pos_x - 70) as f64,
y: (pos_y - 30) as f64,
}))
.unwrap();
main_window
.set_size(tauri::Size::Logical(tauri::LogicalSize {
width: (size_w + 70) as f64,
height: (size_h + 30) as f64,
}))
.unwrap();
}
None => {}
}
Ok(())
})
.unwrap();
// check resource files
ResHelper::res_init(

View File

@ -22,7 +22,6 @@ pub async fn connect_socket(
listen_handler: u32,
app: Arc<tauri::AppHandle>,
) -> anyhow::Result<()> {
let client = TcpStream::connect(address)
.await
.context("Socket connect failed")?;
@ -193,8 +192,7 @@ async fn recv_front_msg(
.await
}
}
}
else{
} else {
eprintln!("fc-command非法");
eprintln!("{:?}", payload);
}

View File

@ -20,40 +20,25 @@ import {
PhysicalSize,
getCurrent,
} from "@tauri-apps/api/window";
import { Store } from "@tauri-apps/plugin-store";
import { SettingsOutline } from "@vicons/ionicons5";
import { UnlistenFn } from "@tauri-apps/api/event";
let unlistenResize: UnlistenFn = () => {};
let unlistenMove: UnlistenFn = () => {};
let factor = 1;
// 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) {
const lSize = size?.toLogical(factor);
const lPos = pos?.toLogical(factor);
// header size and sidebar size
const mt = 30;
const ml = 70;
// use logical position and size
if (lSize !== undefined) {
areaModel.value.sizeW = lSize.width - ml;
areaModel.value.sizeH = lSize.height - mt;
}
if (lPos !== undefined) {
areaModel.value.posX = lPos.x + ml;
areaModel.value.posY = lPos.y + mt;
}
}
const localStore = new Store("store.bin");
const message = useMessage();
const formRef = ref<FormInst | null>(null);
// logical pos and size of the mask area
interface MaskArea {
posX: number;
posY: number;
sizeW: number;
sizeH: number;
}
const areaModel = ref({
posX: 0,
posY: 0,
@ -88,12 +73,32 @@ const areaFormRules: FormRules = {
},
};
async function refreshAreaModel(size?: PhysicalSize, pos?: PhysicalPosition) {
const lSize = size?.toLogical(factor);
const lPos = pos?.toLogical(factor);
// header size and sidebar size
const mt = 30;
const ml = 70;
// use logical position and size
if (lSize !== undefined) {
areaModel.value.sizeW = lSize.width - ml;
areaModel.value.sizeH = lSize.height - mt;
}
if (lPos !== undefined) {
areaModel.value.posX = lPos.x + ml;
areaModel.value.posY = lPos.y + mt;
}
}
function handleAdjustClick(e: MouseEvent) {
e.preventDefault();
formRef.value?.validate((errors) => {
if (!errors) {
adjustMaskArea().then(() => {
message.success("调整完成");
localStore.set("maskArea", areaModel.value);
message.success("蒙版区域已保存");
});
} else {
message.error("请正确输入蒙版的坐标和尺寸");
@ -127,6 +132,11 @@ onMounted(async () => {
const appWindow = getCurrent();
factor = await appWindow.scaleFactor();
let maskArea: null | MaskArea = await localStore.get("maskArea");
if (maskArea !== null) {
areaModel.value = maskArea;
}
unlistenResize = await appWindow.onResized(({ payload: size }) => {
refreshAreaModel(size, undefined);
});

View File

@ -85,7 +85,6 @@ function calculateMacroPosList(
});
}
// TODO 偶尔不定时抽风切换一下程序就能恢复表现为setinterval中的回调函数未执行
// TODO 技能界面实际上是有投影变换的,需要一定的算法,不能仅仅相对坐标 640,400
// add shortcuts for observation