fix: toast are not shown because of delay in webview2 initialization

This commit is contained in:
anatawa12 2026-05-29 09:30:19 +09:00
commit f44633a2ad
No known key found for this signature in database
GPG key ID: BD2F16922830A7DC

View file

@ -3,7 +3,7 @@
import { QueryClientProvider } from "@tanstack/react-query";
import { useNavigate } from "@tanstack/react-router";
import type React from "react";
import { Suspense, useCallback, useEffect } from "react";
import { Suspense, useCallback, useEffect, useEffectEvent } from "react";
import { useTranslation } from "react-i18next";
import { ToastContainer } from "react-toastify";
import Loading from "@/app/-loading";
@ -27,8 +27,7 @@ import { useTauriListen } from "@/lib/use-tauri-listen";
export function Providers({ children }: { children: React.ReactNode }) {
const navigate = useNavigate();
useTauriListen<LogEntry>("log", (event) => {
const entry = event.payload as LogEntry;
const showToastForLog = useEffectEvent((entry: LogEntry) => {
if (entry.level === "Error" && (entry.gui_toast ?? true)) {
toastError(entry.message);
} else if (entry.level === "Warn" && (entry.gui_toast ?? false)) {
@ -36,6 +35,18 @@ export function Providers({ children }: { children: React.ReactNode }) {
}
});
useTauriListen<LogEntry>("log", (event) => {
showToastForLog(event.payload);
});
useEffect(() => {
commands.utilGetLogEntries().then((value) => {
for (const entry of value) {
showToastForLog(entry);
}
});
}, []);
const moveToRepositories = useCallback(() => {
if (location.pathname !== "/packages/repositories") {
navigate({ to: "/packages/repositories" });