bug(windows): hide cmd window and adjust size type

This commit is contained in:
AkiChase 2024-04-15 11:28:49 +08:00
parent 2c3a04bad3
commit a1719ae8bf
4 changed files with 44 additions and 25 deletions

View File

@ -1,8 +1,6 @@
use crate::resource::{ResHelper, ResourceName}; use crate::resource::{ResHelper, ResourceName};
use std::{ use std::{
io::BufRead, io::BufRead, os::windows::process::CommandExt, path::PathBuf, process::{Child, Command, Stdio}
path::PathBuf,
process::{Child, Command, Stdio},
}; };
use anyhow::{Context, Ok, Result}; use anyhow::{Context, Ok, Result};
@ -89,7 +87,12 @@ pub struct Adb;
/// But some output of command won't be output, like adb service startup information. /// But some output of command won't be output, like adb service startup information.
impl Adb { impl Adb {
fn cmd_base(res_dir: &PathBuf) -> Command { fn cmd_base(res_dir: &PathBuf) -> Command {
Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb)) let mut cmd = Command::new(ResHelper::get_file_path(res_dir, ResourceName::Adb));
#[cfg(target_os = "windows")]
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
cmd
} }
/// execute "adb devices" and return devices list /// execute "adb devices" and return devices list

View File

@ -130,6 +130,32 @@ async fn main() {
.join("resource"), .join("resource"),
) )
.unwrap(); .unwrap();
let main_window = app.get_webview_window("main").unwrap();
let scale_factor = main_window.scale_factor().unwrap();
main_window
.set_size(tauri::Size::Physical(tauri::PhysicalSize {
width: 1350,
height: 750,
}))
.unwrap();
let zoomfactor = 1.0 / scale_factor;
main_window
.with_webview(move |webview| {
#[cfg(target_os = "windows")]
unsafe {
// see https://docs.rs/webview2-com/0.19.1/webview2_com/Microsoft/Web/WebView2/Win32/struct.ICoreWebView2Controller.html
webview.controller().SetZoomFactor(zoomfactor).unwrap();
}
// #[cfg(target_os = "macos")]
// unsafe {
// let () = msg_send![webview.inner(), setPageZoom: 4.];
// }
})
.unwrap();
Ok(()) Ok(())
}) })
.plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_shell::init())

View File

@ -31,8 +31,6 @@
"icons/icon.icns", "icons/icon.icns",
"icons/icon.ico" "icons/icon.ico"
], ],
"resources":[ "resources": ["resource/*"]
"resource/*"
]
} }
} }

View File

@ -12,10 +12,9 @@ import {
NIcon, NIcon,
FormInst, FormInst,
useMessage, useMessage,
NP,
} from "naive-ui"; } from "naive-ui";
import { import {
LogicalPosition,
LogicalSize,
PhysicalPosition, PhysicalPosition,
PhysicalSize, PhysicalSize,
getCurrent, getCurrent,
@ -27,21 +26,17 @@ let unlistenResize: UnlistenFn = () => {};
let unlistenMove: UnlistenFn = () => {}; let unlistenMove: UnlistenFn = () => {};
async function refreshAreaModel(size?: PhysicalSize, pos?: PhysicalPosition) { async function refreshAreaModel(size?: PhysicalSize, pos?: PhysicalPosition) {
const factor = await getCurrent().scaleFactor();
const logicalSize = size?.toLogical(factor);
const logicalPos = 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 (logicalPos !== undefined) { if (size !== undefined) {
areaModel.value.posX = Math.floor(logicalPos.x + ml); areaModel.value.sizeW = Math.floor(size.width - ml);
areaModel.value.posY = Math.floor(logicalPos.y + mt); areaModel.value.sizeH = Math.floor(size.height - mt);
} }
if (logicalSize !== undefined) { if (pos !== undefined) {
areaModel.value.sizeW = Math.floor(logicalSize.width - ml); areaModel.value.posX = Math.floor(pos.x + ml);
areaModel.value.sizeH = Math.floor(logicalSize.height - mt); areaModel.value.posY = Math.floor(pos.y + mt);
} }
} }
@ -106,16 +101,12 @@ async function adjustMaskArea() {
const appWindow = getCurrent(); const appWindow = getCurrent();
const pos = new LogicalPosition( const pos = new PhysicalPosition(
areaModel.value.posX - ml, areaModel.value.posX - ml,
areaModel.value.posY - mt areaModel.value.posY - mt
); );
if (pos.x <= 0 || pos.y <= 0) { const size = new PhysicalSize(
message.warning("蒙版区域坐标过小,可能导致其他部分不可见");
}
const size = new LogicalSize(
areaModel.value.sizeW + ml, areaModel.value.sizeW + ml,
areaModel.value.sizeH + mt areaModel.value.sizeH + mt
); );
@ -194,6 +185,7 @@ onUnmounted(() => {
/> />
</NFormItemGi> </NFormItemGi>
</NGrid> </NGrid>
<NP>提示使用物理坐标尺寸</NP>
</NForm> </NForm>
</div> </div>
</template> </template>