Skip to content

Commit

Permalink
feat!: launch PlayCover App only on macOS (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangl-cc authored Dec 22, 2023
1 parent d223eda commit 2da906c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions maa-cli/src/config/task/client_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl ClientType {
}
}

#[cfg(target_os = "macos")]
pub fn app(self) -> &'static str {
match self {
ClientType::Official | ClientType::Bilibili | ClientType::Txwy => "明日方舟",
Expand Down Expand Up @@ -173,6 +174,7 @@ mod tests {
}

#[test]
#[cfg(target_os = "macos")]
fn client_to_app() {
assert_eq!(ClientType::Official.app(), "明日方舟");
assert_eq!(ClientType::Bilibili.app(), "明日方舟");
Expand Down
16 changes: 10 additions & 6 deletions maa-cli/src/run/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod message;
use message::callback;

#[cfg(target_os = "macos")]
mod playcover;
use playcover::PlayCoverApp;

mod fight;
pub use fight::fight;
Expand All @@ -15,7 +15,7 @@ pub use roguelike::{roguelike, Theme as RoguelikeTheme};

use crate::{
config::{
asst::{with_asst_config, with_mut_asst_config, AsstConfig, ConnectionConfig},
asst::{with_asst_config, with_mut_asst_config, AsstConfig},
task::TaskConfig,
},
consts::MAA_CORE_LIB,
Expand Down Expand Up @@ -132,16 +132,19 @@ where
asst.append_task(task_type, serde_json::to_string(params)?)?;
}

let playcover = with_asst_config(|config| {
#[cfg(target_os = "macos")]
let app = with_asst_config(|config| {
use crate::config::asst::ConnectionConfig;
if matches!(config.connection, ConnectionConfig::PlayTools { .. }) {
PlayCoverApp::from(&task_config)
playcover::PlayCoverApp::from(&task_config)
} else {
None
}
});

if !args.dry_run {
if let Some(app) = playcover.as_ref() {
#[cfg(target_os = "macos")]
if let Some(app) = app.as_ref() {
app.open()?;
}

Expand All @@ -161,7 +164,8 @@ where

asst.stop()?;

if let Some(app) = playcover.as_ref() {
#[cfg(target_os = "macos")]
if let Some(app) = app.as_ref() {
app.close()?;
}
}
Expand Down

0 comments on commit 2da906c

Please sign in to comment.