mirror of
https://github.com/AkiChase/scrcpy-mask
synced 2025-02-23 23:42:16 +08:00
feat(device): add screen size input
This commit is contained in:
parent
a9cc446671
commit
2578449304
@ -58,32 +58,6 @@ impl Device {
|
|||||||
.spawn()
|
.spawn()
|
||||||
.context("Failed to execute 'adb shell'")?)
|
.context("Failed to execute 'adb shell'")?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cmd_screen_size(res_dir: &PathBuf, id: &str) -> Result<(u16, u16)> {
|
|
||||||
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'")?;
|
|
||||||
let lines = output.stdout.lines();
|
|
||||||
let mut size = (0, 0);
|
|
||||||
for line in lines {
|
|
||||||
if let std::result::Result::Ok(s) = line {
|
|
||||||
println!("{}", s);
|
|
||||||
if s.starts_with("Physical size:") {
|
|
||||||
let mut iter = s.split_whitespace();
|
|
||||||
iter.next();
|
|
||||||
iter.next();
|
|
||||||
let mut size_str = iter.next().unwrap().split('x');
|
|
||||||
let width = size_str.next().unwrap().parse::<u16>().unwrap();
|
|
||||||
let height = size_str.next().unwrap().parse::<u16>().unwrap();
|
|
||||||
size = (width, height);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Adb;
|
pub struct Adb;
|
||||||
|
@ -40,11 +40,6 @@ impl ScrcpyClient {
|
|||||||
Adb::cmd_forward_remove(res_dir)
|
Adb::cmd_forward_remove(res_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get the screen size of the device
|
|
||||||
pub fn get_screen_size(res_dir: &PathBuf, id: &str) -> Result<(u16, u16)> {
|
|
||||||
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(
|
||||||
|
@ -20,16 +20,6 @@ fn adb_devices(app: tauri::AppHandle) -> Result<Vec<Device>, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
/// get screen size of the device
|
|
||||||
fn get_screen_size(id: String, app: tauri::AppHandle) -> Result<(u16, u16), String> {
|
|
||||||
let dir = app.path().resource_dir().unwrap().join("resource");
|
|
||||||
match ScrcpyClient::get_screen_size(&dir, &id) {
|
|
||||||
Ok(size) => Ok(size),
|
|
||||||
Err(e) => Err(e.to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
/// forward local port to the device port
|
/// forward local port to the device port
|
||||||
fn forward_server_port(
|
fn forward_server_port(
|
||||||
@ -170,7 +160,6 @@ async fn main() {
|
|||||||
.plugin(tauri_plugin_os::init())
|
.plugin(tauri_plugin_os::init())
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
adb_devices,
|
adb_devices,
|
||||||
get_screen_size,
|
|
||||||
forward_server_port,
|
forward_server_port,
|
||||||
push_server_file,
|
push_server_file,
|
||||||
start_scrcpy_server
|
start_scrcpy_server
|
||||||
|
@ -15,7 +15,6 @@ import {
|
|||||||
pushServerFile,
|
pushServerFile,
|
||||||
forwardServerPort,
|
forwardServerPort,
|
||||||
startScrcpyServer,
|
startScrcpyServer,
|
||||||
getScreenSize,
|
|
||||||
} from "../invoke";
|
} from "../invoke";
|
||||||
import {
|
import {
|
||||||
NH4,
|
NH4,
|
||||||
@ -26,11 +25,13 @@ import {
|
|||||||
NEmpty,
|
NEmpty,
|
||||||
NTooltip,
|
NTooltip,
|
||||||
NFlex,
|
NFlex,
|
||||||
|
NFormItem,
|
||||||
NIcon,
|
NIcon,
|
||||||
NSpin,
|
NSpin,
|
||||||
DataTableColumns,
|
DataTableColumns,
|
||||||
DropdownOption,
|
DropdownOption,
|
||||||
useDialog,
|
useDialog,
|
||||||
|
useMessage,
|
||||||
} from "naive-ui";
|
} from "naive-ui";
|
||||||
import { CloseCircle, InformationCircle } from "@vicons/ionicons5";
|
import { CloseCircle, InformationCircle } from "@vicons/ionicons5";
|
||||||
import { Refresh } from "@vicons/ionicons5";
|
import { Refresh } from "@vicons/ionicons5";
|
||||||
@ -40,6 +41,7 @@ import { useGlobalStore } from "../store/global";
|
|||||||
|
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
const store = useGlobalStore();
|
const store = useGlobalStore();
|
||||||
|
const message = useMessage();
|
||||||
|
|
||||||
const port = ref(27183);
|
const port = ref(27183);
|
||||||
|
|
||||||
@ -168,14 +170,21 @@ async function onMenuSelect(key: string) {
|
|||||||
if (!port.value) {
|
if (!port.value) {
|
||||||
port.value = 27183;
|
port.value = 27183;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(store.screenSizeW > 0) || !(store.screenSizeH > 0)) {
|
||||||
|
message.error("请正确输入当前控制设备的屏幕尺寸");
|
||||||
|
store.screenSizeW = 0;
|
||||||
|
store.screenSizeH = 0;
|
||||||
|
store.hideLoading();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let device = devices.value[rowIndex];
|
let device = devices.value[rowIndex];
|
||||||
|
|
||||||
let scid = (
|
let scid = (
|
||||||
"00000000" + Math.floor(Math.random() * 100000).toString(16)
|
"00000000" + Math.floor(Math.random() * 100000).toString(16)
|
||||||
).slice(-8);
|
).slice(-8);
|
||||||
|
|
||||||
let screenSize = await getScreenSize(device.id);
|
|
||||||
|
|
||||||
await pushServerFile(device.id);
|
await pushServerFile(device.id);
|
||||||
await forwardServerPort(device.id, scid, port.value);
|
await forwardServerPort(device.id, scid, port.value);
|
||||||
await startScrcpyServer(device.id, scid, `127.0.0.1:${port.value}`);
|
await startScrcpyServer(device.id, scid, `127.0.0.1:${port.value}`);
|
||||||
@ -186,7 +195,6 @@ async function onMenuSelect(key: string) {
|
|||||||
scid,
|
scid,
|
||||||
deviceName,
|
deviceName,
|
||||||
device,
|
device,
|
||||||
screenSize,
|
|
||||||
};
|
};
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
store.hideLoading();
|
store.hideLoading();
|
||||||
@ -202,13 +210,6 @@ async function refreshDevices() {
|
|||||||
devices.value = await adbDevices();
|
devices.value = await adbDevices();
|
||||||
store.hideLoading();
|
store.hideLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
const screenSizeInfo = computed(() => {
|
|
||||||
if (store.controledDevice) {
|
|
||||||
return `${store.controledDevice.screenSize[0]} x ${store.controledDevice.screenSize[1]}`;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -222,6 +223,28 @@ const screenSizeInfo = computed(() => {
|
|||||||
:max="49151"
|
:max="49151"
|
||||||
style="max-width: 300px"
|
style="max-width: 300px"
|
||||||
/>
|
/>
|
||||||
|
<NH4 prefix="bar">屏幕尺寸</NH4>
|
||||||
|
<NFlex justify="left" align="center">
|
||||||
|
<NFormItem label="宽度">
|
||||||
|
<NInputNumber
|
||||||
|
v-model:value="store.screenSizeW"
|
||||||
|
placeholder="屏幕宽度"
|
||||||
|
:min="0"
|
||||||
|
:disabled="store.controledDevice !== null"
|
||||||
|
/>
|
||||||
|
</NFormItem>
|
||||||
|
<NFormItem label="高度">
|
||||||
|
<NInputNumber
|
||||||
|
v-model:value="store.screenSizeH"
|
||||||
|
placeholder="屏幕高度"
|
||||||
|
:min="0"
|
||||||
|
:disabled="store.controledDevice !== null"
|
||||||
|
/>
|
||||||
|
</NFormItem>
|
||||||
|
</NFlex>
|
||||||
|
<NP
|
||||||
|
>提示:请正确输入当前控制设备的屏幕尺寸,这是成功发送触摸事件的必要参数</NP
|
||||||
|
>
|
||||||
<NH4 prefix="bar">受控设备</NH4>
|
<NH4 prefix="bar">受控设备</NH4>
|
||||||
<div class="controled-device-list">
|
<div class="controled-device-list">
|
||||||
<NEmpty
|
<NEmpty
|
||||||
@ -246,7 +269,6 @@ const screenSizeInfo = computed(() => {
|
|||||||
</template>
|
</template>
|
||||||
scid: {{ store.controledDevice.scid }} <br />status:
|
scid: {{ store.controledDevice.scid }} <br />status:
|
||||||
{{ store.controledDevice.device.status }} <br />screen:
|
{{ store.controledDevice.device.status }} <br />screen:
|
||||||
{{ screenSizeInfo }}
|
|
||||||
</NTooltip>
|
</NTooltip>
|
||||||
<NButton quaternary circle type="error" @click="shutdownSC()">
|
<NButton quaternary circle type="error" @click="shutdownSC()">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
|
@ -3,11 +3,7 @@ import { onActivated, ref } from "vue";
|
|||||||
import { NDialog } from "naive-ui";
|
import { NDialog } from "naive-ui";
|
||||||
import { useGlobalStore } from "../store/global";
|
import { useGlobalStore } from "../store/global";
|
||||||
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
import { onBeforeRouteLeave, useRouter } from "vue-router";
|
||||||
import {
|
import { initShortcuts, listenToKeyEvent, unlistenToKeyEvent } from "../hotkey";
|
||||||
initShortcuts,
|
|
||||||
listenToKeyEvent,
|
|
||||||
unlistenToKeyEvent,
|
|
||||||
} from "../hotkey";
|
|
||||||
|
|
||||||
const maskRef = ref<HTMLElement | null>(null);
|
const maskRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
@ -33,7 +29,7 @@ onActivated(async () => {
|
|||||||
}
|
}
|
||||||
if (store.controledDevice) {
|
if (store.controledDevice) {
|
||||||
if (maskRef.value) {
|
if (maskRef.value) {
|
||||||
initShortcuts(store.controledDevice.screenSize, maskRef.value);
|
initShortcuts([store.screenSizeW, store.screenSizeH], maskRef.value);
|
||||||
listenToKeyEvent();
|
listenToKeyEvent();
|
||||||
isShortcutInited = true;
|
isShortcutInited = true;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import {
|
|||||||
touch,
|
touch,
|
||||||
} from "./frontcommand/scrcpyMaskCmd";
|
} from "./frontcommand/scrcpyMaskCmd";
|
||||||
|
|
||||||
|
|
||||||
|
// TODO 根据当前蒙版的尺寸换算屏幕尺寸
|
||||||
function clientxToPosx(clientx: number) {
|
function clientxToPosx(clientx: number) {
|
||||||
return clientx < 70 ? 0 : Math.floor(clientx - 70);
|
return clientx < 70 ? 0 : Math.floor(clientx - 70);
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,6 @@ export async function adbDevices(): Promise<Device[]> {
|
|||||||
return await invoke("adb_devices");
|
return await invoke("adb_devices");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getScreenSize(id: string): Promise<[number, number]> {
|
|
||||||
return await invoke("get_screen_size", { id });
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function forwardServerPort(
|
export async function forwardServerPort(
|
||||||
id: string,
|
id: string,
|
||||||
scid: string,
|
scid: string,
|
||||||
|
@ -15,15 +15,19 @@ export const useGlobalStore = defineStore("counter", () => {
|
|||||||
scid: string;
|
scid: string;
|
||||||
deviceName: string;
|
deviceName: string;
|
||||||
device: Device;
|
device: Device;
|
||||||
screenSize: [number, number];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const controledDevice: Ref<ControledDevice|null> = ref(null);
|
const screenSizeW: Ref<number> = ref(1280);
|
||||||
|
const screenSizeH: Ref<number> = ref(720);
|
||||||
|
|
||||||
|
const controledDevice: Ref<ControledDevice | null> = ref(null);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showLoading,
|
showLoading,
|
||||||
hideLoading,
|
hideLoading,
|
||||||
showLoadingRef,
|
showLoadingRef,
|
||||||
controledDevice,
|
controledDevice,
|
||||||
|
screenSizeW,
|
||||||
|
screenSizeH,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user