mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-05-11 01:38:31 +08:00
feat(Device): add get screen size
This commit is contained in:
parent
6284648663
commit
14ac09a7ed
@ -58,6 +58,27 @@ impl Device {
|
|||||||
.spawn()
|
.spawn()
|
||||||
.context("Failed to execute 'adb shell'")?)
|
.context("Failed to execute 'adb shell'")?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// execute "adb shell wm size" to get screen size
|
||||||
|
pub fn cmd_screen_size(res_dir: &PathBuf, id: &str) -> Result<(u32, u32)> {
|
||||||
|
let mut adb_command = Adb::cmd_base(res_dir);
|
||||||
|
let output = adb_command
|
||||||
|
.args(&["-s", id, "shell", "wm", "size"])
|
||||||
|
.output()
|
||||||
|
.context("Failed to execute 'adb shell wm size'")?;
|
||||||
|
|
||||||
|
for line in output.stdout.lines() {
|
||||||
|
if let std::result::Result::Ok(line) = line {
|
||||||
|
if line.starts_with("Physical size: ") {
|
||||||
|
let size_str = line.trim_start_matches("Physical size: ").split('x');
|
||||||
|
let width = size_str.clone().next().unwrap().parse::<u32>().unwrap();
|
||||||
|
let height = size_str.clone().last().unwrap().parse::<u32>().unwrap();
|
||||||
|
return Ok((width, height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Err(anyhow::anyhow!("Failed to get screen size"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Adb;
|
pub struct Adb;
|
||||||
|
@ -40,6 +40,11 @@ impl ScrcpyClient {
|
|||||||
Adb::cmd_forward_remove(res_dir)
|
Adb::cmd_forward_remove(res_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the screen size of the device
|
||||||
|
pub fn get_device_screen_size(res_dir: &PathBuf, id: &str) -> Result<(u32, u32)> {
|
||||||
|
Device::cmd_screen_size(res_dir, id)
|
||||||
|
}
|
||||||
|
|
||||||
/// push server file to current device
|
/// push server file to current device
|
||||||
pub fn push_server_file(res_dir: &PathBuf, id: &str) -> Result<()> {
|
pub fn push_server_file(res_dir: &PathBuf, id: &str) -> Result<()> {
|
||||||
let info = Device::cmd_push(
|
let info = Device::cmd_push(
|
||||||
|
@ -108,6 +108,15 @@ fn start_scrcpy_server(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_device_screen_size(id: String, app: tauri::AppHandle) -> Result<(u32, u32), String> {
|
||||||
|
let dir = app.path().resource_dir().unwrap().join("resource");
|
||||||
|
match ScrcpyClient::get_device_screen_size(&dir, &id) {
|
||||||
|
Ok(size) => Ok(size),
|
||||||
|
Err(e) => Err(e.to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn load_default_keyconfig(app: tauri::AppHandle) -> Result<String, String> {
|
fn load_default_keyconfig(app: tauri::AppHandle) -> Result<String, String> {
|
||||||
let dir = app.path().resource_dir().unwrap().join("resource");
|
let dir = app.path().resource_dir().unwrap().join("resource");
|
||||||
@ -194,6 +203,7 @@ async fn main() {
|
|||||||
forward_server_port,
|
forward_server_port,
|
||||||
push_server_file,
|
push_server_file,
|
||||||
start_scrcpy_server,
|
start_scrcpy_server,
|
||||||
|
get_device_screen_size,
|
||||||
load_default_keyconfig
|
load_default_keyconfig
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
pushServerFile,
|
pushServerFile,
|
||||||
forwardServerPort,
|
forwardServerPort,
|
||||||
startScrcpyServer,
|
startScrcpyServer,
|
||||||
|
getDeviceScreenSize,
|
||||||
} from "../invoke";
|
} from "../invoke";
|
||||||
import {
|
import {
|
||||||
NH4,
|
NH4,
|
||||||
@ -160,17 +161,17 @@ const menuOptions: DropdownOption[] = [
|
|||||||
label: () => h("span", "控制此设备"),
|
label: () => h("span", "控制此设备"),
|
||||||
key: "control",
|
key: "control",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: () => h("span", "获取屏幕尺寸"),
|
||||||
|
key: "screen",
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
function onMenuClickoutside() {
|
function onMenuClickoutside() {
|
||||||
showMenu.value = false;
|
showMenu.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onMenuSelect(key: string) {
|
async function deviceControl() {
|
||||||
showMenu.value = false;
|
|
||||||
store.showLoading();
|
|
||||||
switch (key) {
|
|
||||||
case "control":
|
|
||||||
if (!port.value) {
|
if (!port.value) {
|
||||||
port.value = 27183;
|
port.value = 27183;
|
||||||
}
|
}
|
||||||
@ -195,7 +196,7 @@ async function onMenuSelect(key: string) {
|
|||||||
});
|
});
|
||||||
message.info("屏幕尺寸已保存,正在启动控制服务,请保持设备亮屏");
|
message.info("屏幕尺寸已保存,正在启动控制服务,请保持设备亮屏");
|
||||||
|
|
||||||
let device = devices.value[rowIndex];
|
const device = devices.value[rowIndex];
|
||||||
|
|
||||||
let scid = (
|
let scid = (
|
||||||
"00000000" + Math.floor(Math.random() * 100000).toString(16)
|
"00000000" + Math.floor(Math.random() * 100000).toString(16)
|
||||||
@ -228,6 +229,24 @@ async function onMenuSelect(key: string) {
|
|||||||
store.hideLoading();
|
store.hideLoading();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deviceGetScreenSize() {
|
||||||
|
let id = devices.value[rowIndex].id;
|
||||||
|
const size = await getDeviceScreenSize(id);
|
||||||
|
store.hideLoading();
|
||||||
|
message.success(`设备屏幕尺寸为: ${size[0]} x ${size[1]}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onMenuSelect(key: string) {
|
||||||
|
showMenu.value = false;
|
||||||
|
store.showLoading();
|
||||||
|
switch (key) {
|
||||||
|
case "control":
|
||||||
|
await deviceControl();
|
||||||
|
break;
|
||||||
|
case "screen":
|
||||||
|
await deviceGetScreenSize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,7 +316,7 @@ async function refreshDevices() {
|
|||||||
</NButton>
|
</NButton>
|
||||||
</template>
|
</template>
|
||||||
scid: {{ store.controledDevice.scid }} <br />status:
|
scid: {{ store.controledDevice.scid }} <br />status:
|
||||||
{{ store.controledDevice.device.status }} <br />screen:
|
{{ store.controledDevice.device.status }}
|
||||||
</NTooltip>
|
</NTooltip>
|
||||||
<NButton quaternary circle type="error" @click="shutdownSC()">
|
<NButton quaternary circle type="error" @click="shutdownSC()">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
interface Device {
|
interface Device {
|
||||||
id: string;
|
id: string;
|
||||||
@ -29,6 +29,12 @@ export async function startScrcpyServer(
|
|||||||
return await invoke("start_scrcpy_server", { id, scid, address });
|
return await invoke("start_scrcpy_server", { id, scid, address });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getDeviceScreenSize(
|
||||||
|
id: string
|
||||||
|
): Promise<[number, number]> {
|
||||||
|
return await invoke("get_device_screen_size", { id });
|
||||||
|
}
|
||||||
|
|
||||||
export async function loadDefaultKeyconfig(): Promise<string> {
|
export async function loadDefaultKeyconfig(): Promise<string> {
|
||||||
return await invoke("load_default_keyconfig");
|
return await invoke("load_default_keyconfig");
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import KeyBoard from "./components/keyboard/KeyBoard.vue";
|
|||||||
import Device from "./components/Device.vue";
|
import Device from "./components/Device.vue";
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{ path: "/mask", name: "mask", component: Mask },
|
{ path: "/", name: "mask", component: Mask },
|
||||||
{ path: "/device", name: "device", component: Device },
|
{ path: "/device", name: "device", component: Device },
|
||||||
{ path: "/setting", name: "setting", component: Setting },
|
{ path: "/setting", name: "setting", component: Setting },
|
||||||
{ path: "/keyboard", name: "keyboard", component: KeyBoard },
|
{ path: "/keyboard", name: "keyboard", component: KeyBoard },
|
||||||
|
Loading…
Reference in New Issue
Block a user