diff --git a/apps/stage-tamagotchi/src-tauri/build.rs b/apps/stage-tamagotchi/src-tauri/build.rs index 800af28bd..bc46cc478 100644 --- a/apps/stage-tamagotchi/src-tauri/build.rs +++ b/apps/stage-tamagotchi/src-tauri/build.rs @@ -1,6 +1,16 @@ fn main() { tauri_build::try_build( tauri_build::Attributes::new() + .plugin( + "proj-airi-tauri-plugin-window", + tauri_build::InlinedPlugin::new() + .commands(&[ + "get_display_info", + "get_current_window_info", + "set_position", + ]) + .default_permission(tauri_build::DefaultPermissionRule::AllowAllCommands), + ) .plugin( "proj-airi-tauri-plugin-window-pass-through-on-hover", tauri_build::InlinedPlugin::new() @@ -13,19 +23,15 @@ fn main() { .default_permission(tauri_build::DefaultPermissionRule::AllowAllCommands), ) .plugin( - "proj-airi-tauri-plugin-window-persistence", + "proj-airi-tauri-plugin-window-router-link", tauri_build::InlinedPlugin::new() - .commands(&["save", "restore"]) + .commands(&["go"]) .default_permission(tauri_build::DefaultPermissionRule::AllowAllCommands), ) .plugin( - "proj-airi-tauri-plugin-window", + "proj-airi-tauri-plugin-window-persistence", tauri_build::InlinedPlugin::new() - .commands(&[ - "get_display_info", - "get_current_window_info", - "set_position", - ]) + .commands(&["save", "restore"]) .default_permission(tauri_build::DefaultPermissionRule::AllowAllCommands), ), ) diff --git a/apps/stage-tamagotchi/src-tauri/capabilities/default.json b/apps/stage-tamagotchi/src-tauri/capabilities/default.json index 9e6e676f3..e2f3db9cd 100644 --- a/apps/stage-tamagotchi/src-tauri/capabilities/default.json +++ b/apps/stage-tamagotchi/src-tauri/capabilities/default.json @@ -22,6 +22,7 @@ "global-shortcut:allow-unregister-all", "proj-airi-tauri-plugin-window-pass-through-on-hover:default", "proj-airi-tauri-plugin-window-persistence:default", - "proj-airi-tauri-plugin-window:default" + "proj-airi-tauri-plugin-window:default", + "proj-airi-tauri-plugin-window-router-link:default" ] } diff --git a/apps/stage-tamagotchi/src-tauri/src/lib.rs b/apps/stage-tamagotchi/src-tauri/src/lib.rs index e0e07b9bb..ddd37a699 100644 --- a/apps/stage-tamagotchi/src-tauri/src/lib.rs +++ b/apps/stage-tamagotchi/src-tauri/src/lib.rs @@ -57,6 +57,7 @@ pub fn run() { .plugin(plugins::window::init()) .plugin(plugins::window_persistence::init()) .plugin(plugins::window_pass_through_on_hover::init()) + .plugin(plugins::window_router_link::init()) .setup(|app| { let mut builder = WebviewWindowBuilder::new(app, "main", WebviewUrl::default()) .title("AIRI") @@ -152,7 +153,6 @@ pub fn run() { app::commands::open_chat_window, app::commands::debug_println, load_models, - open_route_in_window, ]) .build(tauri::generate_context!()) .expect("error while building tauri application") diff --git a/apps/stage-tamagotchi/src-tauri/src/plugins/mod.rs b/apps/stage-tamagotchi/src-tauri/src/plugins/mod.rs index ea421e983..4917d8e0e 100644 --- a/apps/stage-tamagotchi/src-tauri/src/plugins/mod.rs +++ b/apps/stage-tamagotchi/src-tauri/src/plugins/mod.rs @@ -1,3 +1,4 @@ pub mod window; pub mod window_pass_through_on_hover; pub mod window_persistence; +pub mod window_router_link; diff --git a/apps/stage-tamagotchi/src-tauri/src/plugins/window_router_link/mod.rs b/apps/stage-tamagotchi/src-tauri/src/plugins/window_router_link/mod.rs new file mode 100644 index 000000000..490fce8e8 --- /dev/null +++ b/apps/stage-tamagotchi/src-tauri/src/plugins/window_router_link/mod.rs @@ -0,0 +1,51 @@ +use tauri::{ + Manager, + Runtime, + plugin::{Builder, TauriPlugin}, +}; + +use crate::app::windows::{chat, settings}; + +#[tauri::command] +async fn go( + window: tauri::Window, + route: String, + window_label: String, +) -> std::result::Result<(), String> { + let app = window.app_handle(); + + let target_window = match window_label.as_str() { + "chat" => match app.get_webview_window("chat") { + Some(window) => window, + None => { + chat::new_chat_window(app).map_err(|e| format!("Failed to create chat window: {}", e))? + }, + }, + "settings" => match app.get_webview_window("settings") { + Some(window) => window, + None => settings::new_settings_window(app) + .map_err(|e| format!("Failed to create settings window: {}", e))?, + }, + _ => { + return Err(format!("Unknown window label: {}", window_label)); + }, + }; + + let mut current_url = target_window + .url() + .map_err(|e| format!("Failed to get current URL: {}", e))?; + let route: String = "/".to_string() + route.trim_start_matches('/'); + current_url.set_fragment(Some(route.to_string().as_str())); + + let _ = target_window.show(); + let _ = target_window.navigate(current_url); + + Ok(()) +} + +pub fn init() -> TauriPlugin { + Builder::new("proj-airi-tauri-plugin-window-router-link") + .invoke_handler(tauri::generate_handler![go]) + .setup(|_, _| Ok(())) + .build() +} diff --git a/apps/stage-tamagotchi/src/components/Tauri/WindowLink.vue b/apps/stage-tamagotchi/src/components/Tauri/WindowRouterLink.vue similarity index 84% rename from apps/stage-tamagotchi/src/components/Tauri/WindowLink.vue rename to apps/stage-tamagotchi/src/components/Tauri/WindowRouterLink.vue index 7b114b2c3..fc4684bb6 100644 --- a/apps/stage-tamagotchi/src/components/Tauri/WindowLink.vue +++ b/apps/stage-tamagotchi/src/components/Tauri/WindowRouterLink.vue @@ -9,7 +9,7 @@ const props = defineProps<{ const { invoke } = useTauriCore() function handleClick() { - invoke('open_route_in_window', { + invoke('plugin:proj-airi-tauri-plugin-window-router-link|go', { route: props.to, windowLabel: props.label, }) diff --git a/apps/stage-tamagotchi/src/components/Widgets/ResourceStatusIsland/LoadingProgress.vue b/apps/stage-tamagotchi/src/components/Widgets/ResourceStatusIsland/LoadingProgress.vue index 66d2384cc..7a12d76e6 100644 --- a/apps/stage-tamagotchi/src/components/Widgets/ResourceStatusIsland/LoadingProgress.vue +++ b/apps/stage-tamagotchi/src/components/Widgets/ResourceStatusIsland/LoadingProgress.vue @@ -3,7 +3,7 @@ import type { ProgressInfo } from '../../../stores/resources' import { computed } from 'vue' -import WindowLink from '../../Tauri/WindowLink.vue' +import WindowRouterLink from '../../Tauri/WindowRouterLink.vue' const props = defineProps<{ progressInfo: ProgressInfo @@ -27,7 +27,7 @@ const totalProgress = computed(() => {
  • - +
    @@ -37,7 +37,7 @@ const totalProgress = computed(() => { due to loading inference models...
    - +
diff --git a/apps/stage-tamagotchi/src/composables/tauri.ts b/apps/stage-tamagotchi/src/composables/tauri.ts index ce206037c..53bfd87f9 100644 --- a/apps/stage-tamagotchi/src/composables/tauri.ts +++ b/apps/stage-tamagotchi/src/composables/tauri.ts @@ -148,13 +148,6 @@ export interface InvokeMethods { 'open_settings_window': { args: undefined, options: undefined, returns: void } 'open_chat_window': { args: undefined, options: undefined, returns: void } - // Plugin - WindowRouterLink - 'open_route_in_window': { - args: { route: string, windowLabel?: string } | undefined - options: undefined - returns: void - } - // Plugin - Window Pass through on hover 'plugin:proj-airi-tauri-plugin-window-pass-through-on-hover|start_monitor': { args: undefined, options: undefined, returns: void } 'plugin:proj-airi-tauri-plugin-window-pass-through-on-hover|stop_monitor': { args: undefined, options: undefined, returns: void } @@ -178,6 +171,13 @@ export interface InvokeMethods { returns: void } + // Plugin - WindowRouterLink + 'plugin:proj-airi-tauri-plugin-window-router-link|go': { + args: { route: string, windowLabel?: string } | undefined + options: undefined + returns: void + } + // // Plugin - Window Persistence // 'plugin:proj-airi-tauri-plugin-window-persistence|save': { // args: undefined