fix: command
This commit is contained in:
@@ -5,16 +5,17 @@ use border::WebviewWindowExt as BorderWebviewWindowExt;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use specta::Type;
|
use specta::Type;
|
||||||
use tauri::utils::config::WindowEffectsConfig;
|
use tauri::utils::config::WindowEffectsConfig;
|
||||||
|
use tauri::webview::PageLoadEvent;
|
||||||
use tauri::window::Effect;
|
use tauri::window::Effect;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use tauri::TitleBarStyle;
|
use tauri::TitleBarStyle;
|
||||||
use tauri::{LogicalPosition, LogicalSize, Manager, WebviewUrl};
|
use tauri::{LogicalPosition, LogicalSize, Manager, WebviewUrl, Window};
|
||||||
use tauri::{WebviewBuilder, WebviewWindowBuilder};
|
use tauri::{WebviewBuilder, WebviewWindowBuilder};
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use tauri_plugin_decorum::WebviewWindowExt;
|
use tauri_plugin_decorum::WebviewWindowExt;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Type)]
|
#[derive(Serialize, Deserialize, Type)]
|
||||||
pub struct Window {
|
pub struct NewWindow {
|
||||||
label: String,
|
label: String,
|
||||||
title: String,
|
title: String,
|
||||||
url: String,
|
url: String,
|
||||||
@@ -38,29 +39,39 @@ pub struct Column {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
pub async fn create_column(column: Column, app_handle: tauri::AppHandle) -> Result<String, String> {
|
pub async fn create_column(
|
||||||
match app_handle.get_window("main") {
|
column: Column,
|
||||||
Some(main_window) => match app_handle.get_webview(&column.label) {
|
app_handle: tauri::AppHandle,
|
||||||
Some(_) => Ok(column.label),
|
main_window: Window,
|
||||||
None => {
|
) -> Result<String, String> {
|
||||||
let path = PathBuf::from(column.url);
|
match app_handle.get_webview(&column.label) {
|
||||||
let webview_url = WebviewUrl::App(path);
|
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)
|
let builder = WebviewBuilder::new(column.label, webview_url)
|
||||||
.incognito(true)
|
.incognito(true)
|
||||||
.transparent(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(
|
match main_window.add_child(
|
||||||
builder,
|
builder,
|
||||||
LogicalPosition::new(column.x, column.y),
|
LogicalPosition::new(column.x, column.y),
|
||||||
LogicalSize::new(column.width, column.height),
|
LogicalSize::new(column.width, column.height),
|
||||||
) {
|
) {
|
||||||
Ok(webview) => Ok(webview.label().into()),
|
Ok(webview) => Ok(webview.label().into()),
|
||||||
Err(e) => Err(e.to_string()),
|
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]
|
#[tauri::command]
|
||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
#[cfg(target_os = "macos")]
|
pub fn open_window(window: NewWindow, app_handle: tauri::AppHandle) -> Result<String, String> {
|
||||||
pub fn open_window(window: Window, app_handle: tauri::AppHandle) -> Result<String, String> {
|
|
||||||
if let Some(current_window) = app_handle.get_window(&window.label) {
|
if let Some(current_window) = app_handle.get_window(&window.label) {
|
||||||
if current_window.is_visible().unwrap_or_default() {
|
if current_window.is_visible().unwrap_or_default() {
|
||||||
let _ = current_window.set_focus();
|
let _ = current_window.set_focus();
|
||||||
|
|||||||
@@ -488,7 +488,7 @@ async closeColumn(label: string) : Promise<Result<boolean, string>> {
|
|||||||
else return { status: "error", error: e as any };
|
else return { status: "error", error: e as any };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async openWindow(window: Window) : Promise<Result<string, string>> {
|
async openWindow(window: NewWindow) : Promise<Result<string, string>> {
|
||||||
try {
|
try {
|
||||||
return { status: "ok", data: await TAURI_INVOKE("open_window", { window }) };
|
return { status: "ok", data: await TAURI_INVOKE("open_window", { window }) };
|
||||||
} catch (e) {
|
} 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 Meta = { content: string; images: string[]; events: string[]; mentions: string[]; hashtags: string[] }
|
||||||
export type NegentropyEvent = { kind: NegentropyKind; total_event: number }
|
export type NegentropyEvent = { kind: NegentropyKind; total_event: number }
|
||||||
export type NegentropyKind = "Profile" | "Metadata" | "Events" | "EventIds" | "Global" | "Notification" | "Others"
|
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 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 Relays = { connected: string[]; read: string[] | null; write: string[] | null; both: string[] | null }
|
||||||
export type RichEvent = { raw: string; parsed: Meta | 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 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 Subscription = { label: string; kind: SubscriptionMethod; event_id: string | null; contacts: string[] | null }
|
||||||
export type SubscriptionMethod = "Subscribe" | "Unsubscribe"
|
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 **/
|
/** tauri-specta globals **/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user