feat(stage-tamagotchi): new WindowRouterLink & tauri plugin

This commit is contained in:
Neko Ayaka
2025-06-30 14:31:21 +08:00
parent 0f7505a382
commit 5d5c7c5505
8 changed files with 80 additions and 21 deletions
+14 -8
View File
@@ -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),
),
)
@@ -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"
]
}
+1 -1
View File
@@ -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")
@@ -1,3 +1,4 @@
pub mod window;
pub mod window_pass_through_on_hover;
pub mod window_persistence;
pub mod window_router_link;
@@ -0,0 +1,51 @@
use tauri::{
Manager,
Runtime,
plugin::{Builder, TauriPlugin},
};
use crate::app::windows::{chat, settings};
#[tauri::command]
async fn go<R: Runtime>(
window: tauri::Window<R>,
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<R: Runtime>() -> TauriPlugin<R> {
Builder::new("proj-airi-tauri-plugin-window-router-link")
.invoke_handler(tauri::generate_handler![go])
.setup(|_, _| Ok(()))
.build()
}
@@ -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,
})
@@ -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(() => {
</div>
<ul ml-4 mt-3>
<li>
<WindowLink to="/settings/modules/hearing" label="settings">
<WindowRouterLink to="/settings/modules/hearing" label="settings">
<div flex items-center gap-1>
<div flex items-center gap-1>
<div i-solar:microphone-3-bold-duotone text="neutral-500 dark:neutral-400" />
@@ -37,7 +37,7 @@ const totalProgress = computed(() => {
due to loading inference models...
</div>
</div>
</WindowLink>
</WindowRouterLink>
</li>
</ul>
</div>
@@ -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