mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
♻️ 调整代码结构
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
//! @file src/client/mod.rs
|
//! @file src/client/mod.rs
|
||||||
//! @desc 客户端模块,负责操作米游社客户端
|
//! @desc 客户端模块,负责操作米游社客户端
|
||||||
//! @since Beta v0.5.2
|
//! @since Beta v0.6.2
|
||||||
|
|
||||||
mod menu;
|
mod menu;
|
||||||
mod utils;
|
mod utils;
|
||||||
@@ -12,7 +12,7 @@ use tauri_utils::config::WebviewUrl;
|
|||||||
pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) {
|
pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) {
|
||||||
let mut win_width = 400.0;
|
let mut win_width = 400.0;
|
||||||
let mut win_height = 800.0;
|
let mut win_height = 800.0;
|
||||||
let win_ua = "Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/2.75.1";
|
let win_ua = "Mozilla/5.0 (Linux; Android 12) Mobile miHoYoBBS/2.76.1";
|
||||||
let url_parse;
|
let url_parse;
|
||||||
if url != "" {
|
if url != "" {
|
||||||
url_parse = WebviewUrl::External(url.parse().unwrap());
|
url_parse = WebviewUrl::External(url.parse().unwrap());
|
||||||
@@ -37,6 +37,7 @@ pub async fn create_mhy_client(handle: AppHandle, func: String, url: String) {
|
|||||||
.title("米游社")
|
.title("米游社")
|
||||||
.center()
|
.center()
|
||||||
.user_agent(win_ua)
|
.user_agent(win_ua)
|
||||||
|
// todo mac环境下没看到menu
|
||||||
.menu(menu::create_mhy_menu(handle.clone()))
|
.menu(menu::create_mhy_menu(handle.clone()))
|
||||||
.on_menu_event(move |app, event| menu::handle_menu_event(app, event))
|
.on_menu_event(move |app, event| menu::handle_menu_event(app, event))
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -1,20 +1,24 @@
|
|||||||
//! @file src/main.rs
|
//! @file src/main.rs
|
||||||
//! @desc 主模块,用于启动应用
|
//! @desc 主模块,用于启动应用
|
||||||
//! @since Beta v0.5.2
|
//! @since Beta v0.6.2
|
||||||
|
|
||||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use tauri::{Emitter, Manager};
|
|
||||||
mod client;
|
mod client;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod plugins;
|
mod plugins;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
use crate::client::create_mhy_client;
|
||||||
|
use crate::commands::{create_window, execute_js, get_dir_size, init_app};
|
||||||
|
use crate::plugins::{build_log_plugin, build_si_plugin};
|
||||||
|
use tauri::{generate_context, generate_handler, Builder, Manager, Window, WindowEvent};
|
||||||
|
|
||||||
// 窗口事件处理
|
// 窗口事件处理
|
||||||
fn window_event_handler(app: &tauri::Window, event: &tauri::WindowEvent) {
|
fn window_event_handler(app: &Window, event: &WindowEvent) {
|
||||||
match event {
|
match event {
|
||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
WindowEvent::CloseRequested { api, .. } => {
|
||||||
api.prevent_close();
|
api.prevent_close();
|
||||||
if app.label() == "TeyvatGuide" {
|
if app.label() == "TeyvatGuide" {
|
||||||
// 子窗口 label 的数组
|
// 子窗口 label 的数组
|
||||||
@@ -33,11 +37,9 @@ fn window_event_handler(app: &tauri::Window, event: &tauri::WindowEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
Builder::default()
|
||||||
.on_window_event(move |app, event| window_event_handler(app, event))
|
.on_window_event(move |app, event| window_event_handler(app, event))
|
||||||
.plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {
|
.plugin(build_si_plugin())
|
||||||
app.emit("active_deep_link", argv).unwrap();
|
|
||||||
}))
|
|
||||||
.plugin(tauri_plugin_deep_link::init())
|
.plugin(tauri_plugin_deep_link::init())
|
||||||
.plugin(tauri_plugin_dialog::init())
|
.plugin(tauri_plugin_dialog::init())
|
||||||
.plugin(tauri_plugin_fs::init())
|
.plugin(tauri_plugin_fs::init())
|
||||||
@@ -46,22 +48,22 @@ fn main() {
|
|||||||
.plugin(tauri_plugin_process::init())
|
.plugin(tauri_plugin_process::init())
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
.plugin(tauri_plugin_sql::Builder::default().build())
|
.plugin(tauri_plugin_sql::Builder::default().build())
|
||||||
.plugin(plugins::build_log_plugin())
|
.plugin(build_log_plugin())
|
||||||
.setup(|_app| {
|
.setup(|_app| {
|
||||||
let _window = _app.get_webview_window("TeyvatGuide");
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
let _window = _app.get_webview_window("TeyvatGuide");
|
||||||
if _window.is_some() {
|
if _window.is_some() {
|
||||||
_window.unwrap().open_devtools();
|
_window.unwrap().open_devtools();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(generate_handler![
|
||||||
commands::init_app,
|
init_app,
|
||||||
commands::create_window,
|
create_window,
|
||||||
commands::execute_js,
|
execute_js,
|
||||||
commands::get_dir_size,
|
get_dir_size,
|
||||||
client::create_mhy_client,
|
create_mhy_client
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,33 @@
|
|||||||
//! @file src/plugins.rs
|
//! @file src/plugins.rs
|
||||||
//! @desc 插件模块,用于注册插件
|
//! @desc 插件模块,用于注册插件
|
||||||
//! @since Beta v0.5.3
|
//! @since Beta v0.6.2
|
||||||
|
|
||||||
use super::utils;
|
use crate::utils::get_current_date;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use tauri::plugin::TauriPlugin;
|
use tauri::plugin::TauriPlugin;
|
||||||
use tauri::Runtime;
|
use tauri::{Emitter, Runtime};
|
||||||
use tauri_plugin_log::{Target, TargetKind, TimezoneStrategy};
|
use tauri_plugin_log::{Builder, Target, TargetKind, TimezoneStrategy};
|
||||||
|
use tauri_plugin_single_instance::init;
|
||||||
|
|
||||||
|
// 单例插件
|
||||||
|
pub fn build_si_plugin<R: Runtime>() -> TauriPlugin<R> {
|
||||||
|
init(move |app, argv, _cwd| app.emit("active_deep_link", argv).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
// 日志插件
|
// 日志插件
|
||||||
pub fn build_log_plugin<R: Runtime>() -> TauriPlugin<R> {
|
pub fn build_log_plugin<R: Runtime>() -> TauriPlugin<R> {
|
||||||
if cfg!(debug_assertions) {
|
#[cfg(debug_assertions)]
|
||||||
return tauri_plugin_log::Builder::default()
|
Builder::default()
|
||||||
.targets([Target::new(TargetKind::Webview)])
|
.targets([Target::new(TargetKind::Webview)])
|
||||||
.timezone_strategy(TimezoneStrategy::UseLocal)
|
.timezone_strategy(TimezoneStrategy::UseLocal)
|
||||||
.level(LevelFilter::Debug)
|
.level(LevelFilter::Debug)
|
||||||
.build();
|
.build::<R>();
|
||||||
}
|
Builder::default()
|
||||||
tauri_plugin_log::Builder::default()
|
|
||||||
.targets([
|
.targets([
|
||||||
Target::new(TargetKind::Webview),
|
Target::new(TargetKind::Webview),
|
||||||
Target::new(TargetKind::LogDir { file_name: utils::get_current_date().into() }),
|
Target::new(TargetKind::LogDir { file_name: get_current_date().into() }),
|
||||||
])
|
])
|
||||||
.timezone_strategy(TimezoneStrategy::UseLocal)
|
.timezone_strategy(TimezoneStrategy::UseLocal)
|
||||||
.level(LevelFilter::Info)
|
.level(LevelFilter::Info)
|
||||||
.build()
|
.build::<R>()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user