diff --git a/apps/desktop2/public/404.jpg b/apps/desktop2/public/404.jpg new file mode 100644 index 00000000..7485a5e8 Binary files /dev/null and b/apps/desktop2/public/404.jpg differ diff --git a/apps/desktop2/src/components/note/content.tsx b/apps/desktop2/src/components/note/content.tsx index 2b9564a9..d0cecc67 100644 --- a/apps/desktop2/src/components/note/content.tsx +++ b/apps/desktop2/src/components/note/content.tsx @@ -102,7 +102,7 @@ export function NoteContent({
500 ? "max-h-[300px] gradient-mask-b-0" : "", className, )} diff --git a/apps/desktop2/src/components/note/contentLarge.tsx b/apps/desktop2/src/components/note/contentLarge.tsx index 03ee1625..c8614470 100644 --- a/apps/desktop2/src/components/note/contentLarge.tsx +++ b/apps/desktop2/src/components/note/contentLarge.tsx @@ -145,7 +145,9 @@ export function NoteContentLarge({ return (
-
{content}
+
+ {content} +
); } diff --git a/apps/desktop2/src/components/note/mentions/note.tsx b/apps/desktop2/src/components/note/mentions/note.tsx index 74dc23a2..d341fcca 100644 --- a/apps/desktop2/src/components/note/mentions/note.tsx +++ b/apps/desktop2/src/components/note/mentions/note.tsx @@ -48,7 +48,7 @@ export function MentionNote({
100 ? "max-h-[150px] gradient-mask-b-0" : "", )} > diff --git a/apps/desktop2/src/components/note/preview/image.tsx b/apps/desktop2/src/components/note/preview/image.tsx index ae1b0678..730b25fb 100644 --- a/apps/desktop2/src/components/note/preview/image.tsx +++ b/apps/desktop2/src/components/note/preview/image.tsx @@ -1,61 +1,44 @@ -import { CheckCircleIcon, DownloadIcon } from "@lume/icons"; -import { downloadDir } from "@tauri-apps/api/path"; import { WebviewWindow } from "@tauri-apps/api/webviewWindow"; -import { download } from "@tauri-apps/plugin-upload"; -import { type SyntheticEvent, useState } from "react"; export function ImagePreview({ url }: { url: string }) { - const [downloaded, setDownloaded] = useState(false); + const open = async (url: string) => { + const name = new URL(url).pathname + .split("/") + .pop() + .replace(/[^a-zA-Z ]/g, ""); + const label = `viewer-${name}`; + const window = WebviewWindow.getByLabel(label); - const downloadImage = async (e: { stopPropagation: () => void }) => { - try { - e.stopPropagation(); + if (!window) { + const newWindow = new WebviewWindow(label, { + url, + title: "Image Viewer", + width: 800, + height: 800, + titleBarStyle: "overlay", + }); - const downloadDirPath = await downloadDir(); - const filename = url.substring(url.lastIndexOf("/") + 1); - await download(url, `${downloadDirPath}/${filename}`); - - setDownloaded(true); - } catch (e) { - console.error(e); + return newWindow; } - }; - const open = async () => { - const name = new URL(url).pathname.split("/").pop(); - return new WebviewWindow("image-viewer", { - url, - title: name, - }); - }; - - const fallback = (event: SyntheticEvent) => { - event.currentTarget.src = "/fallback-image.jpg"; + return await window.setFocus(); }; return ( - // biome-ignore lint/a11y/useKeyWithClickEvents: -
open()} className="group relative my-1"> +
{url} open(url)} + onError={({ currentTarget }) => { + currentTarget.onerror = null; + currentTarget.src = "/404.jpg"; + }} /> -
); } diff --git a/apps/desktop2/src/components/note/preview/images.tsx b/apps/desktop2/src/components/note/preview/images.tsx index feecbe79..a92c8541 100644 --- a/apps/desktop2/src/components/note/preview/images.tsx +++ b/apps/desktop2/src/components/note/preview/images.tsx @@ -36,6 +36,10 @@ export function Images({ urls }: { urls: string[] }) { style={{ contentVisibility: "auto" }} className="max-h-[400px] w-auto object-cover rounded-lg outline outline-1 -outline-offset-1 outline-black/15" onClick={() => open(urls[0])} + onError={({ currentTarget }) => { + currentTarget.onerror = null; + currentTarget.src = "/404.jpg"; + }} />
); @@ -54,6 +58,10 @@ export function Images({ urls }: { urls: string[] }) { style={{ contentVisibility: "auto" }} className="w-full h-full object-cover rounded-lg outline outline-1 -outline-offset-1 outline-black/15" onClick={() => open(item)} + onError={({ currentTarget }) => { + currentTarget.onerror = null; + currentTarget.src = "/404.jpg"; + }} /> )} diff --git a/apps/desktop2/src/routes/index.tsx b/apps/desktop2/src/routes/index.tsx index 7e11d38b..d7f8ef0a 100644 --- a/apps/desktop2/src/routes/index.tsx +++ b/apps/desktop2/src/routes/index.tsx @@ -57,7 +57,10 @@ function Screen() { }); return ( -
+

diff --git a/packages/system/src/commands.ts b/packages/system/src/commands.ts index 1a2dd3bd..244cacf6 100644 --- a/packages/system/src/commands.ts +++ b/packages/system/src/commands.ts @@ -1,404 +1,596 @@ - // This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually. +// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually. - export const commands = { -async getRelays() : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_relays") }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async connectRelay(relay: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("connect_relay", { relay }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async removeRelay(relay: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("remove_relay", { relay }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getAccounts() : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_accounts") }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async createAccount() : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("create_account") }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async saveAccount(nsec: string, password: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("save_account", { nsec, password }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getEncryptedKey(npub: string, password: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_encrypted_key", { npub, password }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async connectRemoteAccount(uri: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("connect_remote_account", { uri }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async loadAccount(npub: string, bunker: string | null) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("load_account", { npub, bunker }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async eventToBech32(id: string, relays: string[]) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("event_to_bech32", { id, relays }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async userToBech32(key: string, relays: string[]) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("user_to_bech32", { key, relays }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async verifyNip05(key: string, nip05: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("verify_nip05", { key, nip05 }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getActivities(account: string, kind: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_activities", { account, kind }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getCurrentUserProfile() : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_current_user_profile") }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getProfile(id: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_profile", { id }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getContactList() : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_contact_list") }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async setContactList(pubkeys: string[]) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("set_contact_list", { pubkeys }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async createProfile(name: string, displayName: string, about: string, picture: string, banner: string, nip05: string, lud16: string, website: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("create_profile", { name, displayName, about, picture, banner, nip05, lud16, website }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async follow(id: string, alias: string | null) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("follow", { id, alias }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async unfollow(id: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("unfollow", { id }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getNstore(key: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_nstore", { key }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async setNstore(key: string, content: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("set_nstore", { key, content }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async setNwc(uri: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("set_nwc", { uri }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async loadNwc() : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("load_nwc") }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getBalance() : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_balance") }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async zapProfile(id: string, amount: string, message: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("zap_profile", { id, amount, message }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async zapEvent(id: string, amount: string, message: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("zap_event", { id, amount, message }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async friendToFriend(npub: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("friend_to_friend", { npub }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getEvent(id: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_event", { id }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getReplies(id: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_replies", { id }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getEventsBy(publicKey: string, asOf: string | null) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_events_by", { publicKey, asOf }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getLocalEvents(pubkeys: string[], until: string | null) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_local_events", { pubkeys, until }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getGlobalEvents(until: string | null) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_global_events", { until }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async getHashtagEvents(hashtags: string[], until: string | null) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("get_hashtag_events", { hashtags, until }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async publish(content: string, tags: string[][]) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("publish", { content, tags }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async repost(raw: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("repost", { raw }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async showInFolder(path: string) : Promise { -await TAURI_INVOKE("show_in_folder", { path }); -}, -async createColumn(label: string, x: number, y: number, width: number, height: number, url: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("create_column", { label, x, y, width, height, url }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async closeColumn(label: string) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("close_column", { label }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async repositionColumn(label: string, x: number, y: number) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("reposition_column", { label, x, y }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async resizeColumn(label: string, width: number, height: number) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("resize_column", { label, width, height }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async openWindow(label: string, title: string, url: string, width: number, height: number) : Promise> { -try { - return { status: "ok", data: await TAURI_INVOKE("open_window", { label, title, url, width, height }) }; -} catch (e) { - if(e instanceof Error) throw e; - else return { status: "error", error: e as any }; -} -}, -async setBadge(count: number) : Promise { -await TAURI_INVOKE("set_badge", { count }); -} -} +/** user-defined commands **/ +export const commands = { + async getRelays(): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_relays") }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async connectRelay(relay: string): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("connect_relay", { relay }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async removeRelay(relay: string): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("remove_relay", { relay }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getAccounts(): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_accounts") }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async createAccount(): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("create_account") }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async saveAccount( + nsec: string, + password: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("save_account", { nsec, password }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getEncryptedKey( + npub: string, + password: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("get_encrypted_key", { npub, password }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async connectRemoteAccount(uri: string): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("connect_remote_account", { uri }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async loadAccount( + npub: string, + bunker: string | null, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("load_account", { npub, bunker }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async eventToBech32( + id: string, + relays: string[], + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("event_to_bech32", { id, relays }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async userToBech32( + key: string, + relays: string[], + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("user_to_bech32", { key, relays }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async verifyNip05( + key: string, + nip05: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("verify_nip05", { key, nip05 }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getActivities( + account: string, + kind: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("get_activities", { account, kind }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getCurrentUserProfile(): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("get_current_user_profile"), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getProfile(id: string): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_profile", { id }) }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getContactList(): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_contact_list") }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async setContactList(pubkeys: string[]): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("set_contact_list", { pubkeys }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async createProfile( + name: string, + displayName: string, + about: string, + picture: string, + banner: string, + nip05: string, + lud16: string, + website: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("create_profile", { + name, + displayName, + about, + picture, + banner, + nip05, + lud16, + website, + }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async follow( + id: string, + alias: string | null, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("follow", { id, alias }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async unfollow(id: string): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("unfollow", { id }) }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getNstore(key: string): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_nstore", { key }) }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async setNstore( + key: string, + content: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("set_nstore", { key, content }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async setNwc(uri: string): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("set_nwc", { uri }) }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async loadNwc(): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("load_nwc") }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getBalance(): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_balance") }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async zapProfile( + id: string, + amount: string, + message: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("zap_profile", { id, amount, message }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async zapEvent( + id: string, + amount: string, + message: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("zap_event", { id, amount, message }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async friendToFriend(npub: string): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("friend_to_friend", { npub }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getEvent(id: string): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_event", { id }) }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getReplies(id: string): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("get_replies", { id }) }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getEventsBy( + publicKey: string, + asOf: string | null, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("get_events_by", { publicKey, asOf }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getLocalEvents( + pubkeys: string[], + until: string | null, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("get_local_events", { pubkeys, until }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getGlobalEvents( + until: string | null, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("get_global_events", { until }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async getHashtagEvents( + hashtags: string[], + until: string | null, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("get_hashtag_events", { hashtags, until }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async publish( + content: string, + tags: string[][], + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("publish", { content, tags }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async repost(raw: string): Promise> { + try { + return { status: "ok", data: await TAURI_INVOKE("repost", { raw }) }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async showInFolder(path: string): Promise { + await TAURI_INVOKE("show_in_folder", { path }); + }, + async createColumn( + label: string, + x: number, + y: number, + width: number, + height: number, + url: string, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("create_column", { + label, + x, + y, + width, + height, + url, + }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async closeColumn(label: string): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("close_column", { label }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async repositionColumn( + label: string, + x: number, + y: number, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("reposition_column", { label, x, y }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async resizeColumn( + label: string, + width: number, + height: number, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("resize_column", { label, width, height }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async openWindow( + label: string, + title: string, + url: string, + width: number, + height: number, + ): Promise> { + try { + return { + status: "ok", + data: await TAURI_INVOKE("open_window", { + label, + title, + url, + width, + height, + }), + }; + } catch (e) { + if (e instanceof Error) throw e; + else return { status: "error", error: e as any }; + } + }, + async setBadge(count: number): Promise { + await TAURI_INVOKE("set_badge", { count }); + }, +}; +/** user-defined events **/ + +/** user-defined statics **/ /** user-defined types **/ -export type Account = { npub: string; nsec: string } -export type Relays = { connected: string[]; read: string[] | null; write: string[] | null; both: string[] | null } +export type Account = { npub: string; nsec: string }; +export type Relays = { + connected: string[]; + read: string[] | null; + write: string[] | null; + both: string[] | null; +}; /** tauri-specta globals **/ - import { invoke as TAURI_INVOKE } from "@tauri-apps/api/core"; +import { invoke as TAURI_INVOKE } from "@tauri-apps/api/core"; import * as TAURI_API_EVENT from "@tauri-apps/api/event"; import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow"; type __EventObj__ = { - listen: ( - cb: TAURI_API_EVENT.EventCallback - ) => ReturnType>; - once: ( - cb: TAURI_API_EVENT.EventCallback - ) => ReturnType>; - emit: T extends null - ? (payload?: T) => ReturnType - : (payload: T) => ReturnType; + listen: ( + cb: TAURI_API_EVENT.EventCallback, + ) => ReturnType>; + once: ( + cb: TAURI_API_EVENT.EventCallback, + ) => ReturnType>; + emit: T extends null + ? (payload?: T) => ReturnType + : (payload: T) => ReturnType; }; export type Result = - | { status: "ok"; data: T } - | { status: "error"; error: E }; + | { status: "ok"; data: T } + | { status: "error"; error: E }; function __makeEvents__>( - mappings: Record + mappings: Record, ) { - return new Proxy( - {} as unknown as { - [K in keyof T]: __EventObj__ & { - (handle: __WebviewWindow__): __EventObj__; - }; - }, - { - get: (_, event) => { - const name = mappings[event as keyof T]; + return new Proxy( + {} as unknown as { + [K in keyof T]: __EventObj__ & { + (handle: __WebviewWindow__): __EventObj__; + }; + }, + { + get: (_, event) => { + const name = mappings[event as keyof T]; - return new Proxy((() => {}) as any, { - apply: (_, __, [window]: [__WebviewWindow__]) => ({ - listen: (arg: any) => window.listen(name, arg), - once: (arg: any) => window.once(name, arg), - emit: (arg: any) => window.emit(name, arg), - }), - get: (_, command: keyof __EventObj__) => { - switch (command) { - case "listen": - return (arg: any) => TAURI_API_EVENT.listen(name, arg); - case "once": - return (arg: any) => TAURI_API_EVENT.once(name, arg); - case "emit": - return (arg: any) => TAURI_API_EVENT.emit(name, arg); - } - }, - }); - }, - } - ); + return new Proxy((() => {}) as any, { + apply: (_, __, [window]: [__WebviewWindow__]) => ({ + listen: (arg: any) => window.listen(name, arg), + once: (arg: any) => window.once(name, arg), + emit: (arg: any) => window.emit(name, arg), + }), + get: (_, command: keyof __EventObj__) => { + switch (command) { + case "listen": + return (arg: any) => TAURI_API_EVENT.listen(name, arg); + case "once": + return (arg: any) => TAURI_API_EVENT.once(name, arg); + case "emit": + return (arg: any) => TAURI_API_EVENT.emit(name, arg); + } + }, + }); + }, + }, + ); } - - \ No newline at end of file diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 73fbba25..b71b62cb 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -5841,8 +5841,9 @@ dependencies = [ [[package]] name = "tauri-specta" -version = "2.0.0-rc.10" -source = "git+https://github.com/cloudcad/tauri-specta?branch=main#806eb18e50d7015a5ff27f800b5fc5a74a4d41a6" +version = "2.0.0-rc.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85f26e4ded13fbeab2216dcb5a59b5cf8b475740afea932918888402bcc62a02" dependencies = [ "heck 0.5.0", "indoc", @@ -5857,7 +5858,8 @@ dependencies = [ [[package]] name = "tauri-specta-macros" version = "2.0.0-rc.5" -source = "git+https://github.com/cloudcad/tauri-specta?branch=main#806eb18e50d7015a5ff27f800b5fc5a74a4d41a6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6f9e90bf2012877e2c4029a1bf756277183e9c7c77b850ef965711553998012" dependencies = [ "heck 0.5.0", "proc-macro2", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 71a30f4c..fd5f2604 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -37,10 +37,8 @@ tauri-plugin-decorum = "0.1.0" webpage = { version = "2.0", features = ["serde"] } keyring = "2" keyring-search = "0.2.0" -specta = "=2.0.0-rc.12" -tauri-specta = { git = "https://github.com/cloudcad/tauri-specta", branch = "main", features = [ - "typescript", -] } +specta = "^2.0.0-rc.12" +tauri-specta = { version = "^2.0.0-rc.11", features = ["typescript"] } tauri-plugin-theme = "0.4.1" [target.'cfg(target_family = "unix")'.dependencies]