update: rust/ rename to win32_api.rs

fix: setForegroundWindow
This commit is contained in:
2024-04-28 22:28:48 +08:00
parent 288df33b39
commit 3dbf993099
13 changed files with 236 additions and 236 deletions

View File

@ -4,4 +4,4 @@
pub mod http_api;
pub mod rs_process;
pub mod notify_api;
pub mod win32_api;

View File

@ -1,19 +0,0 @@
use notify_rust::Notification;
pub fn send_notify(summary: Option<String>, body: Option<String>, app_name: Option<String>, app_id: Option<String>) -> anyhow::Result<()> {
let mut n = Notification::new();
if let Some(summary) = summary {
n.summary(&summary);
}
if let Some(body) = body {
n.body(&body);
}
if let Some(app_name) = app_name {
n.appname(&app_name);
}
if let Some(app_id) = app_id {
n.app_id(&app_id);
}
n.show()?;
Ok(())
}

View File

@ -9,9 +9,6 @@ use tokio::io::AsyncWriteExt;
use tokio::io::BufReader;
use tokio::process::ChildStdin;
use tokio::sync::Mutex;
use windows::core::{HSTRING, PCWSTR};
use windows::Win32::Foundation::HWND;
use windows::Win32::UI::WindowsAndMessaging;
use crate::frb_generated::StreamSink;
@ -163,18 +160,4 @@ async fn _process_output<R>(
};
stream_sink.add(message).unwrap();
}
}
pub fn set_foreground_window(window_name: &str) -> anyhow::Result<bool> {
let window_name_p: PCWSTR = PCWSTR(HSTRING::from(window_name).as_ptr());
let h = unsafe { WindowsAndMessaging::FindWindowW(PCWSTR::null(), window_name_p) };
if h == HWND::default() {
return Ok(false);
}
let sr = unsafe { WindowsAndMessaging::ShowWindow(h, WindowsAndMessaging::SW_RESTORE) };
if !sr.as_bool() {
return Ok(false);
}
let r = unsafe { WindowsAndMessaging::SetForegroundWindow(h) };
Ok(r.as_bool())
}
}

36
rust/src/api/win32_api.rs Normal file
View File

@ -0,0 +1,36 @@
use notify_rust::Notification;
use windows::core::{HSTRING, PCWSTR};
use windows::Win32::Foundation::HWND;
use windows::Win32::UI::WindowsAndMessaging;
pub fn send_notify(summary: Option<String>, body: Option<String>, app_name: Option<String>, app_id: Option<String>) -> anyhow::Result<()> {
let mut n = Notification::new();
if let Some(summary) = summary {
n.summary(&summary);
}
if let Some(body) = body {
n.body(&body);
}
if let Some(app_name) = app_name {
n.appname(&app_name);
}
if let Some(app_id) = app_id {
n.app_id(&app_id);
}
n.show()?;
Ok(())
}
pub fn set_foreground_window(window_name: &str) -> anyhow::Result<bool> {
let window_name_p: PCWSTR = PCWSTR(HSTRING::from(window_name).as_ptr());
let h = unsafe { WindowsAndMessaging::FindWindowW(PCWSTR::null(), window_name_p) };
if h == HWND::default() {
return Ok(false);
}
let sr = unsafe { WindowsAndMessaging::ShowWindow(h, WindowsAndMessaging::SW_RESTORE) };
if !sr.as_bool() {
return Ok(false);
}
let r = unsafe { WindowsAndMessaging::SetForegroundWindow(h) };
Ok(r.as_bool())
}

View File

@ -204,25 +204,6 @@ pub extern "C" fn frbgen_starcitizen_doctor_wire_set_default_header(
wire_set_default_header_impl(port_, headers)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_send_notify(
port_: i64,
summary: *mut wire_cst_list_prim_u_8_strict,
body: *mut wire_cst_list_prim_u_8_strict,
app_name: *mut wire_cst_list_prim_u_8_strict,
app_id: *mut wire_cst_list_prim_u_8_strict,
) {
wire_send_notify_impl(port_, summary, body, app_name, app_id)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_set_foreground_window(
port_: i64,
window_name: *mut wire_cst_list_prim_u_8_strict,
) {
wire_set_foreground_window_impl(port_, window_name)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_start(
port_: i64,
@ -243,6 +224,25 @@ pub extern "C" fn frbgen_starcitizen_doctor_wire_write(
wire_write_impl(port_, rs_pid, data)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_send_notify(
port_: i64,
summary: *mut wire_cst_list_prim_u_8_strict,
body: *mut wire_cst_list_prim_u_8_strict,
app_name: *mut wire_cst_list_prim_u_8_strict,
app_id: *mut wire_cst_list_prim_u_8_strict,
) {
wire_send_notify_impl(port_, summary, body, app_name, app_id)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_wire_set_foreground_window(
port_: i64,
window_name: *mut wire_cst_list_prim_u_8_strict,
) {
wire_set_foreground_window_impl(port_, window_name)
}
#[no_mangle]
pub extern "C" fn frbgen_starcitizen_doctor_cst_new_box_autoadd_u_64(value: u64) -> *mut u64 {
flutter_rust_bridge::for_generated::new_leak_box_ptr(value)

View File

@ -31,7 +31,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
default_rust_auto_opaque = RustAutoOpaqueNom,
);
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0-dev.32";
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -1186168522;
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1453545208;
// Section: executor
@ -139,57 +139,6 @@ fn wire_set_default_header_impl(
},
)
}
fn wire_send_notify_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
summary: impl CstDecode<Option<String>>,
body: impl CstDecode<Option<String>>,
app_name: impl CstDecode<Option<String>>,
app_id: impl CstDecode<Option<String>>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::DcoCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "send_notify",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let api_summary = summary.cst_decode();
let api_body = body.cst_decode();
let api_app_name = app_name.cst_decode();
let api_app_id = app_id.cst_decode();
move |context| {
transform_result_dco((move || {
crate::api::notify_api::send_notify(
api_summary,
api_body,
api_app_name,
api_app_id,
)
})())
}
},
)
}
fn wire_set_foreground_window_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
window_name: impl CstDecode<String>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::DcoCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "set_foreground_window",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let api_window_name = window_name.cst_decode();
move |context| {
transform_result_dco((move || {
crate::api::rs_process::set_foreground_window(&api_window_name)
})())
}
},
)
}
fn wire_start_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
executable: impl CstDecode<String>,
@ -259,6 +208,57 @@ fn wire_write_impl(
},
)
}
fn wire_send_notify_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
summary: impl CstDecode<Option<String>>,
body: impl CstDecode<Option<String>>,
app_name: impl CstDecode<Option<String>>,
app_id: impl CstDecode<Option<String>>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::DcoCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "send_notify",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let api_summary = summary.cst_decode();
let api_body = body.cst_decode();
let api_app_name = app_name.cst_decode();
let api_app_id = app_id.cst_decode();
move |context| {
transform_result_dco((move || {
crate::api::win32_api::send_notify(
api_summary,
api_body,
api_app_name,
api_app_id,
)
})())
}
},
)
}
fn wire_set_foreground_window_impl(
port_: flutter_rust_bridge::for_generated::MessagePort,
window_name: impl CstDecode<String>,
) {
FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::<flutter_rust_bridge::for_generated::DcoCodec, _, _>(
flutter_rust_bridge::for_generated::TaskInfo {
debug_name: "set_foreground_window",
port: Some(port_),
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
},
move || {
let api_window_name = window_name.cst_decode();
move |context| {
transform_result_dco((move || {
crate::api::win32_api::set_foreground_window(&api_window_name)
})())
}
},
)
}
// Section: dart2rust