diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index 3ea7e866..fb2a8a80 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -5,16 +5,17 @@ use border::WebviewWindowExt as BorderWebviewWindowExt; use serde::{Deserialize, Serialize}; use specta::Type; use tauri::utils::config::WindowEffectsConfig; +use tauri::webview::PageLoadEvent; use tauri::window::Effect; #[cfg(target_os = "macos")] use tauri::TitleBarStyle; -use tauri::{LogicalPosition, LogicalSize, Manager, WebviewUrl}; +use tauri::{LogicalPosition, LogicalSize, Manager, WebviewUrl, Window}; use tauri::{WebviewBuilder, WebviewWindowBuilder}; #[cfg(target_os = "windows")] use tauri_plugin_decorum::WebviewWindowExt; #[derive(Serialize, Deserialize, Type)] -pub struct Window { +pub struct NewWindow { label: String, title: String, url: String, @@ -38,29 +39,39 @@ pub struct Column { #[tauri::command] #[specta::specta] -pub async fn create_column(column: Column, app_handle: tauri::AppHandle) -> Result { - match app_handle.get_window("main") { - Some(main_window) => match app_handle.get_webview(&column.label) { - Some(_) => Ok(column.label), - None => { - let path = PathBuf::from(column.url); - let webview_url = WebviewUrl::App(path); +pub async fn create_column( + column: Column, + app_handle: tauri::AppHandle, + main_window: Window, +) -> Result { + match app_handle.get_webview(&column.label) { + Some(_) => Ok(column.label), + None => { + let path = PathBuf::from(column.url); + let webview_url = WebviewUrl::App(path); - let builder = WebviewBuilder::new(column.label, webview_url) - .incognito(true) - .transparent(true); + let builder = WebviewBuilder::new(column.label, webview_url) + .incognito(true) + .transparent(true) + .on_page_load(|webview, payload| match payload.event() { + PageLoadEvent::Started => { + let url = payload.url(); + println!("#TODO, preload: {}", url) + } + PageLoadEvent::Finished => { + println!("{} finished loading", payload.url()); + } + }); - match main_window.add_child( - builder, - LogicalPosition::new(column.x, column.y), - LogicalSize::new(column.width, column.height), - ) { - Ok(webview) => Ok(webview.label().into()), - Err(e) => Err(e.to_string()), - } + match main_window.add_child( + builder, + LogicalPosition::new(column.x, column.y), + LogicalSize::new(column.width, column.height), + ) { + Ok(webview) => Ok(webview.label().into()), + Err(e) => Err(e.to_string()), } - }, - None => Err("Window not found".into()), + } } } @@ -113,8 +124,7 @@ pub async fn reload_column(label: String, app_handle: tauri::AppHandle) -> Resul #[tauri::command] #[specta::specta] -#[cfg(target_os = "macos")] -pub fn open_window(window: Window, app_handle: tauri::AppHandle) -> Result { +pub fn open_window(window: NewWindow, app_handle: tauri::AppHandle) -> Result { if let Some(current_window) = app_handle.get_window(&window.label) { if current_window.is_visible().unwrap_or_default() { let _ = current_window.set_focus(); diff --git a/src/commands.gen.ts b/src/commands.gen.ts index 7e79b36f..30ad4faa 100644 --- a/src/commands.gen.ts +++ b/src/commands.gen.ts @@ -488,7 +488,7 @@ async closeColumn(label: string) : Promise> { else return { status: "error", error: e as any }; } }, -async openWindow(window: Window) : Promise> { +async openWindow(window: NewWindow) : Promise> { try { return { status: "ok", data: await TAURI_INVOKE("open_window", { window }) }; } catch (e) { @@ -520,13 +520,13 @@ export type Mention = { pubkey: string; avatar: string; display_name: string; na export type Meta = { content: string; images: string[]; events: string[]; mentions: string[]; hashtags: string[] } export type NegentropyEvent = { kind: NegentropyKind; total_event: number } export type NegentropyKind = "Profile" | "Metadata" | "Events" | "EventIds" | "Global" | "Notification" | "Others" +export type NewWindow = { label: string; title: string; url: string; width: number; height: number; maximizable: boolean; minimizable: boolean; hidden_title: boolean; closable: boolean } export type Profile = { name: string; display_name: string; about: string | null; picture: string; banner: string | null; nip05: string | null; lud16: string | null; website: string | null } export type Relays = { connected: string[]; read: string[] | null; write: string[] | null; both: string[] | null } export type RichEvent = { raw: string; parsed: Meta | null } export type Settings = { proxy: string | null; image_resize_service: string | null; use_relay_hint: boolean; content_warning: boolean; trusted_only: boolean; display_avatar: boolean; display_zap_button: boolean; display_repost_button: boolean; display_media: boolean; transparent: boolean } export type Subscription = { label: string; kind: SubscriptionMethod; event_id: string | null; contacts: string[] | null } export type SubscriptionMethod = "Subscribe" | "Unsubscribe" -export type Window = { label: string; title: string; url: string; width: number; height: number; maximizable: boolean; minimizable: boolean; hidden_title: boolean; closable: boolean } /** tauri-specta globals **/