Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split shared types into maa-types crate #341

Merged
merged 4 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
[workspace]
resolver = "2"
members = ["maa-cli", "maa-dirs", "maa-sys"]
members = ["maa-*"]

[workspace.package]
license = "AGPL-3.0-only"
homepage = "https://github.com/MaaAssistantArknights/maa-cli"
repository = "https://github.com/MaaAssistantArknights/maa-cli"

[workspace.dependencies]
anyhow = "1"
thiserror = "1"
async-trait = "0.1.81"
serde = "1"
serde_json = "1"
serde_test = "1"
jsonrpsee = "0.24.7"

[workspace.dependencies.reqwest]
version = "0.12"
default-features = false
features = ["charset", "http2", "macos-system-configuration", "rustls-tls"]

[workspace.dependencies.tokio]
version = "1.31"
default-features = false
features = ["rt", "rt-multi-thread"]
17 changes: 7 additions & 10 deletions maa-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ name = "maa"
path = "src/main.rs"

[dependencies]
maa-sys = { path = "../maa-sys", version = "0.4.0", features = [
"runtime",
"serde",
] }
maa-sys = { path = "../maa-sys", version = "0.5.0", features = ["runtime"] }
maa-dirs = { path = "../maa-dirs", version = "0.1.1" }
maa-types = { path = "../maa-types", version = "0.1.0", features = ["serde"] }

anyhow = "1"
async-trait = "0.1.81"
Expand All @@ -51,7 +49,6 @@ clap_complete = { version = "4.4" }
clap_mangen = "0.2.20"
color-print = "0.3.6"
digest = { version = "0.10.7", optional = true }
directories = "5"
dunce = "1.0.4"
flate2 = { version = "1", optional = true }
futures-util = { version = "0.3.28", optional = true }
Expand All @@ -60,8 +57,8 @@ indicatif = { version = "0.17.7", optional = true }
log = "0.4.20"
prettytable = { version = "0.10.0", default-features = false }
semver = { version = "1.0.19", features = ["serde"], optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = "0.9.25"
sha2 = { version = "0.10.7", optional = true }
signal-hook = "0.3.17"
Expand All @@ -79,7 +76,7 @@ default-features = false
features = ["auto-color"]

[dependencies.reqwest]
version = "0.12"
workspace = true
default-features = false
features = [
# Default features without default-tls {{{
Expand All @@ -93,7 +90,7 @@ features = [
]

[dependencies.tokio]
version = "1.31"
workspace = true
default-features = false
features = ["rt", "rt-multi-thread"]

Expand All @@ -111,4 +108,4 @@ windows-sys = { version = "0.59.0", features = ["Win32_System_LibraryLoader"] }

[dev-dependencies]
regex = "1.10.2"
serde_test = "1"
serde_test = { workspace = true }
30 changes: 14 additions & 16 deletions maa-cli/src/config/asst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use anyhow::{Context, Result};
use log::{debug, info, warn};
use maa_sys::{Assistant, InstanceOptionKey, StaticOptionKey, TouchMode};
use maa_sys::Assistant;
use maa_types::{InstanceOptionKey, StaticOptionKey, TouchMode};
use serde::Deserialize;

use crate::dirs;
Expand Down Expand Up @@ -426,14 +427,12 @@
warn!("Both CPU OCR and GPU OCR are enabled, CPU OCR will be ignored");
}
debug!("Using GPU OCR with GPU ID {}", gpu_id);
StaticOptionKey::GpuOCR
.apply(gpu_id)
Assistant::set_static_option(StaticOptionKey::GpuOCR, gpu_id)

Check warning on line 430 in maa-cli/src/config/asst.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/config/asst.rs#L430

Added line #L430 was not covered by tests
.with_context(|| format!("Failed to enable GPU OCR with GPU ID {}", gpu_id))?;
}
(Some(cpu_ocr), None) if cpu_ocr => {
debug!("Using CPU OCR");
StaticOptionKey::CpuOCR
.apply(true)
Assistant::set_static_option(StaticOptionKey::CpuOCR, true)

Check warning on line 435 in maa-cli/src/config/asst.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/config/asst.rs#L435

Added line #L435 was not covered by tests
.context("Failed to enable CPU OCR")?;
}
(..) => {}
Expand Down Expand Up @@ -473,26 +472,25 @@
pub fn apply_to(&self, asst: &Assistant) -> Result<()> {
if let Some(touch_mode) = self.touch_mode {
debug!("Setting touch mode to {}", touch_mode);
InstanceOptionKey::TouchMode
.apply_to(asst, touch_mode)
asst.set_instance_option(InstanceOptionKey::TouchMode, touch_mode)

Check warning on line 475 in maa-cli/src/config/asst.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/config/asst.rs#L475

Added line #L475 was not covered by tests
.with_context(|| format!("Failed to set touch mode to {}", touch_mode))?;
}
if let Some(deployment_with_pause) = self.deployment_with_pause {
debug!("Setting deployment with pause to {}", deployment_with_pause);
InstanceOptionKey::DeploymentWithPause
.apply_to(asst, deployment_with_pause)
.context("Failed to set deployment with pause")?;
asst.set_instance_option(
InstanceOptionKey::DeploymentWithPause,
deployment_with_pause,

Check warning on line 482 in maa-cli/src/config/asst.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/config/asst.rs#L480-L482

Added lines #L480 - L482 were not covered by tests
)
.context("Failed to set deployment with pause")?;
}
if let Some(adb_lite_enabled) = self.adb_lite_enabled {
debug!("Setting adb lite enabled to {}", adb_lite_enabled);
InstanceOptionKey::AdbLiteEnabled
.apply_to(asst, adb_lite_enabled)
asst.set_instance_option(InstanceOptionKey::AdbLiteEnabled, adb_lite_enabled)

Check warning on line 488 in maa-cli/src/config/asst.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/config/asst.rs#L488

Added line #L488 was not covered by tests
.context("Failed to set adb lite enabled")?;
}
if let Some(kill_adb_on_exit) = self.kill_adb_on_exit {
debug!("Setting kill adb on exit to {}", kill_adb_on_exit);
InstanceOptionKey::KillAdbOnExit
.apply_to(asst, kill_adb_on_exit)
asst.set_instance_option(InstanceOptionKey::KillAdbOnExit, kill_adb_on_exit)

Check warning on line 493 in maa-cli/src/config/asst.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/config/asst.rs#L493

Added line #L493 was not covered by tests
.context("Failed to set kill adb on exit")?;
}
Ok(())
Expand Down Expand Up @@ -718,7 +716,7 @@

assert_de_tokens(
&InstanceOptions {
touch_mode: Some(TouchMode::ADB),
touch_mode: Some(TouchMode::Adb),
deployment_with_pause: Some(false),
adb_lite_enabled: Some(false),
kill_adb_on_exit: Some(false),
Expand Down Expand Up @@ -1130,7 +1128,7 @@

assert_matches!(
InstanceOptions {
touch_mode: Some(TouchMode::ADB),
touch_mode: Some(TouchMode::Adb),
..Default::default()
}
.force_playtools(),
Expand Down
4 changes: 2 additions & 2 deletions maa-cli/src/run/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ pub mod summary;
use std::{fmt::Write, sync::atomic::AtomicBool};

use log::{debug, error, info, trace, warn};
use maa_sys::binding::{AsstMsgId, AsstTaskId};
use maa_types::primitive::{AsstMsgId, AsstTaskId};
use serde_json::{Map, Value};
use summary::{edit_current_task_detail, end_current_task, start_task};

pub static MAA_CORE_ERRORED: AtomicBool = AtomicBool::new(false);

pub unsafe extern "C" fn default_callback(
code: maa_sys::binding::AsstMsgId,
code: AsstMsgId,
json_raw: *const ::std::os::raw::c_char,
_: *mut ::std::os::raw::c_void,
) {
Expand Down
3 changes: 2 additions & 1 deletion maa-cli/src/run/callback/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ pub use std::collections::BTreeMap as Map;
use std::sync::Mutex;

use chrono;
use maa_sys::{binding::AsstTaskId, TaskType};
use maa_sys::TaskType;
use maa_types::primitive::AsstTaskId;

use super::IterJoin;

Expand Down
8 changes: 3 additions & 5 deletions maa-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "maa-sys"
authors = ["Loong Wang <[email protected]>"]
version = "0.4.0"
version = "0.5.0"
edition = "2021"
description = "Low-level bindings to MAA (MaaAssistantArknights)"
license.workspace = true
Expand All @@ -12,8 +12,6 @@ homepage.workspace = true
runtime = ["libloading"]

[dependencies]
maa-types = { version = "0.1", path = "../maa-types" }
libloading = { version = "0.8", optional = true }
serde = { version = "1", optional = true }

[dev-dependencies]
serde_test = "1"
thiserror = { workspace = true }
Loading