Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vclass committed Sep 8, 2024
2 parents 2fd67b6 + 10859d6 commit aa35dc2
Show file tree
Hide file tree
Showing 22 changed files with 561 additions and 91 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
## 其他事项

- 使用tauri做的,所以会有web页面,改动一下应该是可以做一个通过网页控制的应用
- tauri发布2.0正式版后是可以打包安卓和ios的,不过正常应该没有这个需求
- tauri发布2.0正式版后是可以打包安卓和ios的, ~~不过正常应该没有这个需求~~ 怎么说呢,安卓应该是可以保持后台运行的,ios由于有墓碑机制,不一定可能顺利做出来。需求来自[这里](https://github.com/orgs/MaaAssistantArknights/discussions/10468)
- 稳定性如何?
- 实话实说,由于本来我技术栈不在前端和rust,所以我自己也对这个没有保障,目前阶段将就着用吧
- 为什么不发布windows包?
Expand Down
3 changes: 3 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AboutMaaBo: typeof import('./src/components/AboutMaaBo.vue')['default']
AwardSetting: typeof import('./src/components/OneKey/AwardSetting.vue')['default']
ElAffix: typeof import('element-plus/es')['ElAffix']
ElButton: typeof import('element-plus/es')['ElButton']
Expand All @@ -30,10 +31,12 @@ declare module 'vue' {
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSlider: typeof import('element-plus/es')['ElSlider']
ElSpace: typeof import('element-plus/es')['ElSpace']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
ElTabPane: typeof import('element-plus/es')['ElTabPane']
ElTabs: typeof import('element-plus/es')['ElTabs']
ElTag: typeof import('element-plus/es')['ElTag']
ElText: typeof import('element-plus/es')['ElText']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
FightSetting: typeof import('./src/components/OneKey/FightSetting.vue')['default']
Expand Down
108 changes: 54 additions & 54 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"element-plus": "^2.8.1",
"moment": "^2.30.1",
"pinia": "^2.1.7",
"vue": "^3.4.29",
"vue": "^3.5.2",
"vue-router": "^4.3.3"
},
"devDependencies": {
Expand Down
9 changes: 6 additions & 3 deletions src-tauri/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pub const SUCCESS: i32 = 0;
pub const MAA_CLI_NEED_UPDATE:i32 = 50;
pub const MAA_CLI_NEED_UPDATE: i32 = 50;
pub const DONE: i32 = 1;
pub const ERROR: i32 = -999;
pub const MAA_STATUS_STOP:u8 = 0;
pub const MAA_STATUS_RUNNING:u8 = 1;
pub const MAA_STATUS_STOP: u8 = 0;
pub const MAA_STATUS_RUNNING: u8 = 1;
pub const MAABO_ONLINE_VERSION_URL: &str =
"https://api.github.com/repos/BoredTape/MaaBo/releases/latest";
pub const REQUEST_QA:&str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0";
18 changes: 18 additions & 0 deletions src-tauri/src/events/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,22 @@ pub fn get_item_index() -> payload::Payload<serde_json::Value> {
.unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"item_index.json").to_str().unwrap(), err.to_string()));
let data =serde_json::from_str(&item_index_str).unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"item_index.json").to_str().unwrap(), err.to_string()));
payload::new(consts::SUCCESS, "success".to_string(), data)
}

#[tauri::command]
pub fn get_fight_stages() -> payload::Payload<serde_json::Value> {
let fight_stages_str =
fs::read_to_string(maa_cli::data_dir().join(&"resource").join(&"stages.json"))
.unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"stages.json").to_str().unwrap(), err.to_string()));
let data =serde_json::from_str(&fight_stages_str).unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"resource").join(&"stages").to_str().unwrap(), err.to_string()));
payload::new(consts::SUCCESS, "success".to_string(), data)
}

#[tauri::command]
pub fn get_current_sidestory() -> payload::Payload<serde_json::Value> {
let sidestory_stages_str =
fs::read_to_string(maa_cli::data_dir().join(&"MaaResource").join(&"cache").join(&"resource").join(&"tasks.json"))
.unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"MaaResource").join(&"cache").join(&"resource").join(&"tasks.json").to_str().unwrap(), err.to_string()));
let data =serde_json::from_str(&sidestory_stages_str).unwrap_or_else(|err| panic!("读取{}失败:{}",maa_cli::data_dir().join(&"MaaResource").join(&"cache").join(&"resource").join(&"tasks.json").to_str().unwrap(), err.to_string()));
payload::new(consts::SUCCESS, "success".to_string(), data)
}
2 changes: 1 addition & 1 deletion src-tauri/src/events/consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const EVENT_GLOBAL_NOTIFICATION: &str = "global_notification";
pub const EVENT_INIT_MSG: &str = "init_msg";
pub const EVENT_UPDATE_CONFIG_STATUS: &str = "update_config_status";
pub const EVENT_UPDATE_MAA_CLI:&str = "maa_cli_update_msg";
pub const EVENT_UPDATE_MAA_CLI: &str = "maa_cli_update_msg";
6 changes: 4 additions & 2 deletions src-tauri/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ mod init;
mod payload;
mod run;
mod update;
mod version;
pub use config::{
delete_user_config, get_cli_config, get_item_index, get_user_configs, save_cli_config,
save_core_config, save_task_config,
delete_user_config, get_cli_config, get_current_sidestory, get_fight_stages, get_item_index,
get_user_configs, save_cli_config, save_core_config, save_task_config,
};
pub use init::init_process;
pub use run::{copilot, one_key, stop};
pub use update::{ignore_maa_cli_update, maa_cli_update_process};
pub use version::{check_update, version_info};
58 changes: 58 additions & 0 deletions src-tauri/src/events/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use serde::Serialize;

use crate::consts;
use crate::events::payload;
use crate::maa_cli;
use crate::utils;

#[derive(Debug, Clone, Serialize)]
pub struct VersionInfo {
maabo: String,
maa_cli: String,
maa_core: String,
tauri: String,
webview: String,
}

#[tauri::command]
pub fn version_info() -> payload::Payload<VersionInfo> {
let wv_version = tauri::webview_version().unwrap_or_else(|error| {
log::info!("获取webview版本失败,请确认是否安装\n{}", error.to_string());
"获取失败".to_string()
});
let (maa_cli_version, maa_core_version) =
maa_cli::get_current_version().unwrap_or_else(|error| {
log::info!("获取本地组件版本失败\n{}", error.to_string());
return ("获取失败".to_string(), "获取失败".to_string());
});
let info = VersionInfo {
maabo: env!("CARGO_PKG_VERSION").to_string(),
maa_cli: maa_cli_version,
maa_core: maa_core_version,
tauri: tauri::VERSION.to_string(),
webview: wv_version,
};
payload::new(consts::SUCCESS, "success".to_string(), info)
}

#[derive(Debug, Clone, Serialize)]
pub struct CheckUpdateData {
require_update: bool,
from: String,
to: String,
}

#[tauri::command]
pub fn check_update() -> payload::Payload<CheckUpdateData> {
let online_version = semver::Version::parse(&utils::fetch_online_version())
.unwrap_or_else(|_| semver::Version::parse(&"0.0.0").unwrap());
let current_version = semver::Version::parse(env!("CARGO_PKG_VERSION"))
.unwrap_or_else(|_| semver::Version::parse(&"0.0.0").unwrap());

let resp_data = CheckUpdateData {
require_update: online_version > current_version,
from: current_version.to_string(),
to: online_version.to_string(),
};
payload::new(consts::SUCCESS, "success".to_string(), resp_data)
}
14 changes: 13 additions & 1 deletion src-tauri/src/maa_cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn init_process(tx: Sender<(i32, String)>) {
});
}

maa_utils::get_current_version().unwrap_or_else(|error| {
let (maa_cli_version, _) = maa_utils::get_current_version().unwrap_or_else(|error| {
tx.send((
pconsts::SUCCESS,
format!("获取MAA CLI本地版本失败:\n{}", error.to_string()),
Expand All @@ -209,11 +209,20 @@ pub fn init_process(tx: Sender<(i32, String)>) {
panic!("获取MAA CLI本地版本失败");
});

version::set_maa_cli_current_version(&maa_cli_version).unwrap_or_else(|error| {
tx.send((
pconsts::SUCCESS,
format!("设置MAA CLI本地版本失败:\n{}", error.to_string()),
))
.unwrap_or_else(|err| log::error!("{}", err.to_string()));
panic!("设置MAA CLI本地版本失败");
});
let core_lib_dir = maa_utils::core_lib_dir();
if !core_lib_dir.exists() || !core_lib_dir.join(maa_utils::core_lib_name()).exists() {
tx.send((pconsts::SUCCESS, "安装MAA CORE".to_string()))
.unwrap_or_else(|err| log::error!("{}", err.to_string()));
if let Err(error_msg) = maa_utils::install_maa_core() {
log::error!("安装MAA CORE失败,错误:{}", error_msg.to_string());
tx.send((pconsts::ERROR, error_msg.to_string()))
.unwrap_or_else(|err| log::error!("{}", err.to_string()));
}
Expand All @@ -224,6 +233,7 @@ pub fn init_process(tx: Sender<(i32, String)>) {

let mut maa_update_msg = (pconsts::SUCCESS, "更新资源成功".to_string());
if let Err(error_msg) = maa_utils::maa_update() {
log::error!("更新资源失败{}", error_msg.to_string());
maa_update_msg = (pconsts::ERROR, error_msg.to_string());
}
tx.send(maa_update_msg)
Expand All @@ -233,6 +243,7 @@ pub fn init_process(tx: Sender<(i32, String)>) {
loop {
if !version::get_maa_cli_ignore_update() {
maa_utils::get_remote_version_info().unwrap_or_else(|error| {
log::error!("获取MAA CLI远程更新信息失败:\n{}", error.to_string());
tx.send((
pconsts::ERROR,
format!("获取MAA CLI远程更新信息失败:\n{}", error.to_string()),
Expand All @@ -250,6 +261,7 @@ pub fn init_process(tx: Sender<(i32, String)>) {
}
thread::sleep(Duration::from_secs(3600));
if let Err(error_msg) = maa_utils::maa_hot_update() {
log::error!("资源热更新失败,错误:{}", error_msg.to_string());
maa_hot_update_msg = (
pconsts::ERROR,
format!("资源热更新失败,错误:{}", error_msg.to_string()),
Expand Down
Loading

0 comments on commit aa35dc2

Please sign in to comment.