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 { listen } from "@tauri-apps/api/event";
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";
type WindowEvent = {
@@ -106,7 +106,7 @@ function Header({
const [isChanged, setIsChanged] = useState(false);
const saveNewTitle = async () => {
const mainWindow = getCurrent();
const mainWindow = getCurrentWebviewWindow();
await mainWindow.emit("columns", { type: "set_title", label, title });
// update search params
@@ -135,7 +135,7 @@ function Header({
MenuItem.new({
text: "Move left",
action: async () => {
await getCurrent().emit("columns", {
await getCurrentWebviewWindow().emit("columns", {
type: "move",
label,
direction: "left",
@@ -145,7 +145,7 @@ function Header({
MenuItem.new({
text: "Move right",
action: async () => {
await getCurrent().emit("columns", {
await getCurrentWebviewWindow().emit("columns", {
type: "move",
label,
direction: "right",
@@ -156,7 +156,10 @@ function Header({
MenuItem.new({
text: "Close",
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 { createFileRoute } from "@tanstack/react-router";
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 { nanoid } from "nanoid";
import { useCallback, useEffect, useState } from "react";
@@ -38,15 +38,15 @@ function Screen() {
}, [emblaApi]);
const emitScrollEvent = useCallback(() => {
getCurrent().emit("child_webview", { scroll: true });
getCurrentWindow().emit("child_webview", { scroll: true });
}, []);
const emitResizeEvent = useCallback(() => {
getCurrent().emit("child_webview", { resize: true, direction: "x" });
getCurrentWindow().emit("child_webview", { resize: true, direction: "x" });
}, []);
const openLumeStore = useCallback(async () => {
await getCurrent().emit("columns", {
await getCurrentWindow().emit("columns", {
type: "add",
column: {
label: "store",

View File

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

View File

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

View File

@@ -3,7 +3,7 @@ import { LumeEvent, NostrQuery } from "@lume/system";
import type { Meta } from "@lume/types";
import * as ScrollArea from "@radix-ui/react-scroll-area";
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 { Virtualizer } from "virtua";
import NoteParent from "./-components/parent";
@@ -83,14 +83,17 @@ function ReplyList() {
const [replies, setReplies] = useState<LumeEvent[]>([]);
useEffect(() => {
const unlistenEvent = getCurrent().listen<Payload>("new_reply", (data) => {
const event = LumeEvent.from(data.payload.raw, data.payload.parsed);
setReplies((prev) => [event, ...prev]);
});
const unlistenEvent = getCurrentWindow().listen<Payload>(
"new_reply",
(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 getCurrent().destroy();
await getCurrentWindow().destroy();
});
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 { createFileRoute, redirect } from "@tanstack/react-router";
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 { Virtualizer } from "virtua";
@@ -195,7 +195,7 @@ function Listerner() {
};
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);
setEvents((prev) => [event, ...prev]);
});

View File

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

View File

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

View File

@@ -3,7 +3,7 @@ import type { LumeColumn } from "@lume/types";
import * as ScrollArea from "@radix-ui/react-scroll-area";
import { createFileRoute } from "@tanstack/react-router";
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";
export const Route = createFileRoute("/store")({
@@ -24,7 +24,7 @@ function Screen() {
const { officialColumns } = Route.useRouteContext();
const install = async (column: LumeColumn) => {
const mainWindow = getCurrent();
const mainWindow = getCurrentWindow();
await mainWindow.emit("columns", { type: "add", column });
};

View File

@@ -1,7 +1,7 @@
import { User } from "@/components/user";
import { NostrQuery } from "@lume/system";
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 { useState } from "react";
import CurrencyInput from "react-currency-input-field";
@@ -35,7 +35,7 @@ function Screen() {
if (val) {
setIsCompleted(true);
// close current window
await getCurrent().close();
await getCurrentWebviewWindow().close();
}
} catch (e) {
setIsLoading(false);