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