From f8e58f1cac58525dacfa35199e0a0be91f3a1a88 Mon Sep 17 00:00:00 2001 From: 403F <4o3f@proton.me> Date: Fri, 1 Mar 2024 23:29:24 +0800 Subject: [PATCH] fix(custom-schema): fix schema not working for new opening and dialog not showing with certain route (#534) --- backend/tauri/src/main.rs | 19 +++++++++++++++++++ backend/tauri/src/utils/init/logging.rs | 2 ++ src/pages/_layout.tsx | 3 ++- src/pages/profiles.tsx | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/backend/tauri/src/main.rs b/backend/tauri/src/main.rs index 81db650867..9402f34662 100644 --- a/backend/tauri/src/main.rs +++ b/backend/tauri/src/main.rs @@ -10,6 +10,7 @@ mod enhance; mod feat; mod utils; +use crate::core::handle::Handle; use crate::{ config::Config, utils::{init, resolve}, @@ -92,6 +93,24 @@ fn main() -> std::io::Result<()> { resolve::resolve_setup(app); // setup custom scheme let handle = app.handle().clone(); + // For start new app from schema + #[cfg(not(target_os = "macos"))] + if let Some(url) = std::env::args().nth(1) { + log::info!(target: "app", "started with schema"); + if Config::verge().data().enable_silent_start.unwrap_or(true) { + resolve::create_window(&handle.clone()); + } + app.listen_global("init-complete", move |_| { + log::info!(target: "app", "frontend init-complete event received"); + Handle::global() + .app_handle + .lock() + .as_ref() + .unwrap() + .emit_all("scheme-request-received", url.clone()) + .unwrap(); + }); + } log_err!(tauri_plugin_deep_link::register( "clash-nyanpasu", move |request| { diff --git a/backend/tauri/src/utils/init/logging.rs b/backend/tauri/src/utils/init/logging.rs index cb5f7730e8..6e9787aa09 100644 --- a/backend/tauri/src/utils/init/logging.rs +++ b/backend/tauri/src/utils/init/logging.rs @@ -15,6 +15,7 @@ use tracing_appender::{ non_blocking::{NonBlocking, WorkerGuard}, rolling::Rotation, }; +use tracing_log::log_tracer; use tracing_subscriber::{filter, fmt, layer::SubscriberExt, reload, EnvFilter}; pub type ReloadSignal = (Option, Option); @@ -130,6 +131,7 @@ pub fn init() -> Result<()> { #[cfg(debug_assertions)] let subscriber = subscriber.with(terminal_layer); + log_tracer::LogTracer::init()?; tracing::subscriber::set_global_default(subscriber) .map_err(|x| anyhow!("setup logging error: {}", x))?; Ok(()) diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index 60c21ff17d..588f3818b3 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -9,7 +9,7 @@ import { useVerge } from "@/hooks/use-verge"; import { getAxios } from "@/services/api"; import getSystem from "@/utils/get-system"; import { List, Paper, ThemeProvider, alpha } from "@mui/material"; -import { listen } from "@tauri-apps/api/event"; +import { emit, listen } from "@tauri-apps/api/event"; import { appWindow } from "@tauri-apps/api/window"; import dayjs from "dayjs"; import "dayjs/locale/ru"; @@ -104,6 +104,7 @@ export default function Layout() { appWindow.show(); appWindow.unminimize(); appWindow.setFocus(); + emit("init-complete"); }, 50); }, []); diff --git a/src/pages/profiles.tsx b/src/pages/profiles.tsx index 9eb0e59e8a..a2777ff397 100644 --- a/src/pages/profiles.tsx +++ b/src/pages/profiles.tsx @@ -104,7 +104,7 @@ export default function ProfilePage() { console.log(location.state.scheme); viewerRef.current?.create(); } - }, []); + }, [location]); const onImport = async () => { if (!url) return;