feat: adapt latest changes in tauri v2

This commit is contained in:
reya 2024-07-19 08:25:36 +07:00
parent 113d69a4df
commit 3b99926f3b
17 changed files with 80 additions and 69 deletions

View File

@ -3,7 +3,7 @@ import type { LumeColumn } from "@lume/types";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu"; import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu";
import { getCurrent } from "@tauri-apps/api/webviewWindow"; import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { memo, useCallback, useEffect, useRef, useState } from "react"; import { memo, useCallback, useEffect, useRef, useState } from "react";
type WindowEvent = { type WindowEvent = {
@ -106,7 +106,7 @@ function Header({
const [isChanged, setIsChanged] = useState(false); const [isChanged, setIsChanged] = useState(false);
const saveNewTitle = async () => { const saveNewTitle = async () => {
const mainWindow = getCurrent(); const mainWindow = getCurrentWebviewWindow();
await mainWindow.emit("columns", { type: "set_title", label, title }); await mainWindow.emit("columns", { type: "set_title", label, title });
// update search params // update search params
@ -135,7 +135,7 @@ function Header({
MenuItem.new({ MenuItem.new({
text: "Move left", text: "Move left",
action: async () => { action: async () => {
await getCurrent().emit("columns", { await getCurrentWebviewWindow().emit("columns", {
type: "move", type: "move",
label, label,
direction: "left", direction: "left",
@ -145,7 +145,7 @@ function Header({
MenuItem.new({ MenuItem.new({
text: "Move right", text: "Move right",
action: async () => { action: async () => {
await getCurrent().emit("columns", { await getCurrentWebviewWindow().emit("columns", {
type: "move", type: "move",
label, label,
direction: "right", direction: "right",
@ -156,7 +156,10 @@ function Header({
MenuItem.new({ MenuItem.new({
text: "Close", text: "Close",
action: async () => { action: async () => {
await getCurrent().emit("columns", { type: "remove", label }); await getCurrentWebviewWindow().emit("columns", {
type: "remove",
label,
});
}, },
}), }),
]); ]);

View File

@ -5,7 +5,7 @@ import { NostrQuery } from "@lume/system";
import type { ColumnEvent, LumeColumn } from "@lume/types"; import type { ColumnEvent, LumeColumn } from "@lume/types";
import { createFileRoute } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import useEmblaCarousel from "embla-carousel-react"; import useEmblaCarousel from "embla-carousel-react";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
@ -38,15 +38,15 @@ function Screen() {
}, [emblaApi]); }, [emblaApi]);
const emitScrollEvent = useCallback(() => { const emitScrollEvent = useCallback(() => {
getCurrent().emit("child_webview", { scroll: true }); getCurrentWindow().emit("child_webview", { scroll: true });
}, []); }, []);
const emitResizeEvent = useCallback(() => { const emitResizeEvent = useCallback(() => {
getCurrent().emit("child_webview", { resize: true, direction: "x" }); getCurrentWindow().emit("child_webview", { resize: true, direction: "x" });
}, []); }, []);
const openLumeStore = useCallback(async () => { const openLumeStore = useCallback(async () => {
await getCurrent().emit("columns", { await getCurrentWindow().emit("columns", {
type: "add", type: "add",
column: { column: {
label: "store", label: "store",

View File

@ -9,7 +9,7 @@ import { LumeWindow, NostrAccount, NostrQuery } from "@lume/system";
import { cn } from "@lume/utils"; import { cn } from "@lume/utils";
import { Outlet, createFileRoute } from "@tanstack/react-router"; import { Outlet, createFileRoute } from "@tanstack/react-router";
import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu"; import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import { message } from "@tauri-apps/plugin-dialog"; import { message } from "@tauri-apps/plugin-dialog";
import { memo, useCallback, useState } from "react"; import { memo, useCallback, useState } from "react";
@ -30,7 +30,7 @@ function Screen() {
const { settings, platform } = Route.useRouteContext(); const { settings, platform } = Route.useRouteContext();
const openLumeStore = async () => { const openLumeStore = async () => {
await getCurrent().emit("columns", { await getCurrentWindow().emit("columns", {
type: "add", type: "add",
column: { column: {
label: "store", label: "store",
@ -137,7 +137,7 @@ const Accounts = memo(function Accounts() {
if (select) { if (select) {
// Reset current columns // Reset current columns
await getCurrent().emit("columns", { type: "reset" }); await getCurrentWindow().emit("columns", { type: "reset" });
// Redirect to new account // Redirect to new account
return navigate({ return navigate({

View File

@ -3,7 +3,7 @@ import { NostrQuery } from "@lume/system";
import { Spinner } from "@lume/ui"; import { Spinner } from "@lume/ui";
import { insertImage, isImagePath } from "@lume/utils"; import { insertImage, isImagePath } from "@lume/utils";
import type { UnlistenFn } from "@tauri-apps/api/event"; import type { UnlistenFn } from "@tauri-apps/api/event";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import { message } from "@tauri-apps/plugin-dialog"; import { message } from "@tauri-apps/plugin-dialog";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useSlateStatic } from "slate-react"; import { useSlateStatic } from "slate-react";
@ -32,7 +32,7 @@ export function MediaButton() {
let unlisten: UnlistenFn = undefined; let unlisten: UnlistenFn = undefined;
async function listenFileDrop() { async function listenFileDrop() {
const window = getCurrent(); const window = getCurrentWindow();
if (!unlisten) { if (!unlisten) {
unlisten = await window.listen("tauri://file-drop", async (event) => { unlisten = await window.listen("tauri://file-drop", async (event) => {
// @ts-ignore, lfg !!! // @ts-ignore, lfg !!!

View File

@ -3,7 +3,7 @@ import { LumeEvent, NostrQuery } from "@lume/system";
import type { Meta } from "@lume/types"; import type { Meta } from "@lume/types";
import * as ScrollArea from "@radix-ui/react-scroll-area"; import * as ScrollArea from "@radix-ui/react-scroll-area";
import { createFileRoute } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { Virtualizer } from "virtua"; import { Virtualizer } from "virtua";
import NoteParent from "./-components/parent"; import NoteParent from "./-components/parent";
@ -83,14 +83,17 @@ function ReplyList() {
const [replies, setReplies] = useState<LumeEvent[]>([]); const [replies, setReplies] = useState<LumeEvent[]>([]);
useEffect(() => { useEffect(() => {
const unlistenEvent = getCurrent().listen<Payload>("new_reply", (data) => { const unlistenEvent = getCurrentWindow().listen<Payload>(
const event = LumeEvent.from(data.payload.raw, data.payload.parsed); "new_reply",
setReplies((prev) => [event, ...prev]); (data) => {
}); const event = LumeEvent.from(data.payload.raw, data.payload.parsed);
setReplies((prev) => [event, ...prev]);
},
);
const unlistenWindow = getCurrent().onCloseRequested(async () => { const unlistenWindow = getCurrentWindow().onCloseRequested(async () => {
await event.unlistenEventReply(); await event.unlistenEventReply();
await getCurrent().destroy(); await getCurrentWindow().destroy();
}); });
return () => { return () => {

View File

@ -10,7 +10,7 @@ import * as ScrollArea from "@radix-ui/react-scroll-area";
import { type InfiniteData, useInfiniteQuery } from "@tanstack/react-query"; import { type InfiniteData, useInfiniteQuery } from "@tanstack/react-query";
import { createFileRoute, redirect } from "@tanstack/react-router"; import { createFileRoute, redirect } from "@tanstack/react-router";
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import { useCallback, useEffect, useRef, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
import { Virtualizer } from "virtua"; import { Virtualizer } from "virtua";
@ -195,7 +195,7 @@ function Listerner() {
}; };
useEffect(() => { useEffect(() => {
const unlisten = getCurrent().listen<Payload>("new_event", (data) => { const unlisten = getCurrentWindow().listen<Payload>("new_event", (data) => {
const event = LumeEvent.from(data.payload.raw, data.payload.parsed); const event = LumeEvent.from(data.payload.raw, data.payload.parsed);
setEvents((prev) => [event, ...prev]); setEvents((prev) => [event, ...prev]);
}); });

View File

@ -15,7 +15,7 @@ import { useQuery } from "@tanstack/react-query";
import { createFileRoute } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu"; import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import { open } from "@tauri-apps/plugin-shell"; import { open } from "@tauri-apps/plugin-shell";
import { type ReactNode, useCallback, useEffect, useRef } from "react"; import { type ReactNode, useCallback, useEffect, useRef } from "react";
import { Virtualizer } from "virtua"; import { Virtualizer } from "virtua";
@ -110,7 +110,7 @@ function Screen() {
}, []); }, []);
useEffect(() => { useEffect(() => {
const unlisten = getCurrent().listen("notification", async (data) => { const unlisten = getCurrentWindow().listen("notification", async (data) => {
const event: LumeEvent = JSON.parse(data.payload as string); const event: LumeEvent = JSON.parse(data.payload as string);
await queryClient.setQueryData( await queryClient.setQueryData(
["notification", account], ["notification", account],

View File

@ -1,7 +1,7 @@
import { Button, init } from "@getalby/bitcoin-connect-react"; import { Button, init } from "@getalby/bitcoin-connect-react";
import { NostrAccount } from "@lume/system"; import { NostrAccount } from "@lume/system";
import { createFileRoute } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import { getCurrent } from "@tauri-apps/api/webviewWindow"; import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
export const Route = createFileRoute("/settings/bitcoin-connect")({ export const Route = createFileRoute("/settings/bitcoin-connect")({
beforeLoad: () => { beforeLoad: () => {
@ -17,7 +17,7 @@ export const Route = createFileRoute("/settings/bitcoin-connect")({
function Screen() { function Screen() {
const setNwcUri = async (uri: string) => { const setNwcUri = async (uri: string) => {
const cmd = await NostrAccount.setWallet(uri); const cmd = await NostrAccount.setWallet(uri);
if (cmd) getCurrent().close(); if (cmd) getCurrentWebviewWindow().close();
}; };
return ( return (

View File

@ -3,7 +3,7 @@ import type { LumeColumn } from "@lume/types";
import * as ScrollArea from "@radix-ui/react-scroll-area"; import * as ScrollArea from "@radix-ui/react-scroll-area";
import { createFileRoute } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import { resolveResource } from "@tauri-apps/api/path"; import { resolveResource } from "@tauri-apps/api/path";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import { readTextFile } from "@tauri-apps/plugin-fs"; import { readTextFile } from "@tauri-apps/plugin-fs";
export const Route = createFileRoute("/store")({ export const Route = createFileRoute("/store")({
@ -24,7 +24,7 @@ function Screen() {
const { officialColumns } = Route.useRouteContext(); const { officialColumns } = Route.useRouteContext();
const install = async (column: LumeColumn) => { const install = async (column: LumeColumn) => {
const mainWindow = getCurrent(); const mainWindow = getCurrentWindow();
await mainWindow.emit("columns", { type: "add", column }); await mainWindow.emit("columns", { type: "add", column });
}; };

View File

@ -1,7 +1,7 @@
import { User } from "@/components/user"; import { User } from "@/components/user";
import { NostrQuery } from "@lume/system"; import { NostrQuery } from "@lume/system";
import { createFileRoute } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import { getCurrent } from "@tauri-apps/api/webviewWindow"; import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import { message } from "@tauri-apps/plugin-dialog"; import { message } from "@tauri-apps/plugin-dialog";
import { useState } from "react"; import { useState } from "react";
import CurrencyInput from "react-currency-input-field"; import CurrencyInput from "react-currency-input-field";
@ -35,7 +35,7 @@ function Screen() {
if (val) { if (val) {
setIsCompleted(true); setIsCompleted(true);
// close current window // close current window
await getCurrent().close(); await getCurrentWebviewWindow().close();
} }
} catch (e) { } catch (e) {
setIsLoading(false); setIsLoading(false);

View File

@ -1,28 +1,31 @@
{ {
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json", "$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": { "organizeImports": {
"enabled": true "enabled": true
}, },
"files": { "files": {
"ignore": ["apps/desktop2/src/router.gen.ts"] "ignore": [
}, "apps/desktop2/src/router.gen.ts",
"linter": { "packages/system/src/commands.ts"
"enabled": true, ]
"rules": { },
"recommended": true, "linter": {
"style": { "enabled": true,
"noNonNullAssertion": "warn", "rules": {
"noUselessElse": "off" "recommended": true,
}, "style": {
"correctness": { "noNonNullAssertion": "warn",
"useExhaustiveDependencies": "off" "noUselessElse": "off"
}, },
"a11y": { "correctness": {
"noSvgWithoutTitle": "off" "useExhaustiveDependencies": "off"
}, },
"complexity": { "a11y": {
"noStaticOnlyClass": "off" "noSvgWithoutTitle": "off"
} },
} "complexity": {
} "noStaticOnlyClass": "off"
}
}
}
} }

View File

@ -1,6 +1,6 @@
import type { LumeColumn, Metadata, NostrEvent, Relay } from "@lume/types"; import type { LumeColumn, Metadata, NostrEvent, Relay } from "@lume/types";
import { resolveResource } from "@tauri-apps/api/path"; import { resolveResource } from "@tauri-apps/api/path";
import { getCurrent } from "@tauri-apps/api/window"; import { getCurrentWindow } from "@tauri-apps/api/window";
import { open } from "@tauri-apps/plugin-dialog"; import { open } from "@tauri-apps/plugin-dialog";
import { readFile, readTextFile } from "@tauri-apps/plugin-fs"; import { readFile, readTextFile } from "@tauri-apps/plugin-fs";
import { relaunch } from "@tauri-apps/plugin-process"; import { relaunch } from "@tauri-apps/plugin-process";
@ -201,7 +201,7 @@ export const NostrQuery = {
} }
}, },
listenLocalEvent: async () => { listenLocalEvent: async () => {
const label = getCurrent().label; const label = getCurrentWindow().label;
const query = await commands.listenLocalEvent(label); const query = await commands.listenLocalEvent(label);
if (query.status === "ok") { if (query.status === "ok") {
@ -394,7 +394,7 @@ export const NostrQuery = {
} }
}, },
unlisten: async (id?: string) => { unlisten: async (id?: string) => {
const label = id ? id : getCurrent().label; const label = id ? id : getCurrentWindow().label;
const query = await commands.unlisten(label); const query = await commands.unlisten(label);
if (query.status === "ok") { if (query.status === "ok") {

7
src-tauri/Cargo.lock generated
View File

@ -5406,8 +5406,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-plugin-decorum" name = "tauri-plugin-decorum"
version = "0.1.3" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/reyamir/tauri-plugin-decorum?branch=feat/tauri-v2#d19a643f8574c8f6ba9f5793672d7baaf05ba001"
checksum = "fccbcf16f789b3fb01470511cbed050d98803d7580bdd55f53f8ef6d8737e8f1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cocoa", "cocoa",
@ -5663,7 +5662,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-specta" name = "tauri-specta"
version = "2.0.0-rc.11" version = "2.0.0-rc.11"
source = "git+https://github.com/oscartbeaumont/tauri-specta#a49885967adc01c80e33962e3ecac25fe7497839" source = "git+https://github.com/reyamir/tauri-specta?branch=feat/tauri-v2#5c09319b345814bfce3c4c02527e481d18339051"
dependencies = [ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"indoc", "indoc",
@ -5678,7 +5677,7 @@ dependencies = [
[[package]] [[package]]
name = "tauri-specta-macros" name = "tauri-specta-macros"
version = "2.0.0-rc.5" version = "2.0.0-rc.5"
source = "git+https://github.com/oscartbeaumont/tauri-specta#a49885967adc01c80e33962e3ecac25fe7497839" source = "git+https://github.com/reyamir/tauri-specta?branch=feat/tauri-v2#5c09319b345814bfce3c4c02527e481d18339051"
dependencies = [ dependencies = [
"heck 0.5.0", "heck 0.5.0",
"proc-macro2", "proc-macro2",

View File

@ -33,11 +33,11 @@ tauri-plugin-process = { git = "https://github.com/tauri-apps/plugins-workspace"
tauri-plugin-shell = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-shell = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-updater = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-updater = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } tauri-plugin-upload = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-specta = { git = "https://github.com/oscartbeaumont/tauri-specta", features = [ tauri-specta = { git = "https://github.com/reyamir/tauri-specta", branch = "feat/tauri-v2", features = [
"typescript", "typescript",
] } ] }
tauri-plugin-theme = "0.4.1" tauri-plugin-theme = "0.4.1"
tauri-plugin-decorum = "0.1.3" tauri-plugin-decorum = { git = "https://github.com/reyamir/tauri-plugin-decorum", branch = "feat/tauri-v2" }
specta = "^2.0.0-rc.12" specta = "^2.0.0-rc.12"
keyring = "2" keyring = "2"
keyring-search = "0.2.0" keyring-search = "0.2.0"

View File

@ -1,6 +1,6 @@
use std::ffi::CString; use std::ffi::CString;
use tauri::{AppHandle, Manager, WebviewWindow}; use tauri::{AppHandle, Emitter, Listener, Manager, WebviewWindow};
use tauri_nspanel::{ use tauri_nspanel::{
block::ConcreteBlock, block::ConcreteBlock,
cocoa::{ cocoa::{

View File

@ -5,7 +5,7 @@ use serde::Serialize;
use specta::Type; use specta::Type;
use std::collections::HashSet; use std::collections::HashSet;
use std::time::Duration; use std::time::Duration;
use tauri::{EventTarget, Manager, State}; use tauri::{Emitter, EventTarget, Manager, State};
use tauri_plugin_notification::NotificationExt; use tauri_plugin_notification::NotificationExt;
use crate::commands::tray::create_tray_panel; use crate::commands::tray::create_tray_panel;

View File

@ -39,7 +39,8 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result<Relays, String> {
match client.get_events_of(vec![filter], None).await { match client.get_events_of(vec![filter], None).await {
Ok(events) => { Ok(events) => {
if let Some(event) = events.first() { if let Some(event) = events.first() {
let nip65_list = nip65::extract_relay_list(event); let nip65_list = nip65::extract_relay_list(event).collect::<Vec<_>>();
let read = nip65_list let read = nip65_list
.iter() .iter()
.filter_map(|(url, meta)| { .filter_map(|(url, meta)| {
@ -50,6 +51,7 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result<Relays, String> {
} }
}) })
.collect(); .collect();
let write = nip65_list let write = nip65_list
.iter() .iter()
.filter_map(|(url, meta)| { .filter_map(|(url, meta)| {
@ -60,6 +62,7 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result<Relays, String> {
} }
}) })
.collect(); .collect();
let both = nip65_list let both = nip65_list
.iter() .iter()
.filter_map(|(url, meta)| { .filter_map(|(url, meta)| {