debug macos and linux

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-02-19 12:01:46 +08:00
parent a333a261fd
commit 626fdefb18
2 changed files with 21 additions and 17 deletions

View File

@ -1,4 +1,8 @@
extern crate hbb_common;
#[cfg(target_os = "linux")]
use hbb_common::platform::linux;
#[cfg(target_os = "macos")]
use hbb_common::platform::macos;
fn main() {
#[cfg(target_os = "linux")]
@ -6,7 +10,7 @@ fn main() {
#[cfg(target_os = "macos")]
macos::alert(
"RustDesk".to_owned(),
"critical".to_owned(),
"warning".to_owned(),
"test title".to_owned(),
"test message".to_owned(),
["Ok".to_owned()].to_vec(),

View File

@ -1,5 +1,6 @@
use crate::ResultType;
use osascript;
use serde_derive;
use serde_derive::{Deserialize, Serialize};
#[derive(Serialize)]
struct AlertParams {
@ -20,36 +21,35 @@ struct AlertResult {
/// # Arguments
///
/// * `app` - The app to execute the script.
/// * `alert_type` - Alert type. critical
/// * `alert_type` - Alert type. . informational, warning, critical
/// * `title` - The alert title.
/// * `message` - The alert message.
/// * `buttons` - The buttons to show.
pub fn alert(
app: &str,
alert_type: &str,
title: &str,
app: String,
alert_type: String,
title: String,
message: String,
buttons: Vec<String>,
) -> ResultType<String> {
let script = osascript::JavaScript::new(format!(
let script = osascript::JavaScript::new(&format!(
"
var App = Application('{}');
App.includeStandardAdditions = true;
return App.displayAlert($params.title, {
return App.displayAlert($params.title, {{
message: $params.message,
'as': $params.alert_type,
buttons: $params.buttons,
});
}});
",
app
));
script
.execute_with_params(AlertParams {
title,
message,
alert_type,
buttons,
})?
.button
let result: AlertResult = script.execute_with_params(AlertParams {
title,
message,
alert_type,
buttons,
})?;
Ok(result.button)
}