mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
♻️ 姑且没登录的功能都给试了下
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
//! @since Beta v0.5.0
|
||||
|
||||
use tauri::{AppHandle, Manager, WebviewWindowBuilder};
|
||||
use tauri_utils::config::WindowConfig;
|
||||
use tauri_utils::config::{WebviewUrl, WindowConfig};
|
||||
|
||||
// 放一个常数,用来判断应用是否初始化
|
||||
static mut APP_INITIALIZED: bool = false;
|
||||
@@ -20,7 +20,7 @@ pub async fn init_app(app_handle: AppHandle) {
|
||||
let _mhy = app_handle.get_webview_window("mhy_client");
|
||||
if _mhy.is_some() {
|
||||
// todo 这里应该延时,否则可能造成 macOS 平台的崩溃
|
||||
// _mhy.unwrap().close().unwrap();
|
||||
_mhy.unwrap().destroy().unwrap();
|
||||
}
|
||||
app_handle.emit("initApp", ()).unwrap();
|
||||
unsafe {
|
||||
@@ -30,17 +30,27 @@ pub async fn init_app(app_handle: AppHandle) {
|
||||
|
||||
// 创建窗口
|
||||
#[tauri::command]
|
||||
pub async fn create_window(app_handle: tauri::AppHandle, label: String, mut option: WindowConfig) {
|
||||
let window_old = app_handle.get_webview_window(&label);
|
||||
option.label = label.clone();
|
||||
if window_old.is_some() {
|
||||
dbg!("window exists");
|
||||
window_old.unwrap().close().unwrap();
|
||||
pub async fn create_window(
|
||||
app_handle: AppHandle,
|
||||
label: String,
|
||||
url: String,
|
||||
option: WindowConfig,
|
||||
) {
|
||||
let window_find = app_handle.get_webview_window(&label);
|
||||
if window_find.is_some() {
|
||||
let window = window_find.unwrap();
|
||||
window.destroy().unwrap();
|
||||
return;
|
||||
}
|
||||
let window_new =
|
||||
Some(WebviewWindowBuilder::from_config(&app_handle, &option).expect("failed to create window"));
|
||||
window_new.unwrap();
|
||||
let url_parse = WebviewUrl::App(url.parse().unwrap());
|
||||
WebviewWindowBuilder::new(&app_handle, &label, url_parse)
|
||||
.inner_size(option.width, option.height)
|
||||
.resizable(option.resizable)
|
||||
.visible(option.visible)
|
||||
.title(option.title)
|
||||
.center()
|
||||
.build()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// 执行 js
|
||||
|
||||
@@ -22,11 +22,11 @@ fn window_event_handler(app: &tauri::Window, event: &tauri::WindowEvent) {
|
||||
for label in SUB_WINDOW_LABELS.iter() {
|
||||
let sub = app.get_webview_window(label);
|
||||
if sub.is_some() {
|
||||
sub.unwrap().close().unwrap();
|
||||
sub.unwrap().destroy().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
app.close().unwrap();
|
||||
app.destroy().unwrap();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -36,10 +36,12 @@ fn main() {
|
||||
tauri::Builder::default()
|
||||
.on_window_event(move |app, event| window_event_handler(app, event))
|
||||
.plugin(tauri_plugin_deep_link::init())
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(plugins::build_sql_plugin())
|
||||
.plugin(plugins::build_log_plugin())
|
||||
.setup(|_app| {
|
||||
|
||||
Reference in New Issue
Block a user