Fix uncatched errors from not having Tauri (#1379)

This commit is contained in:
Uriel authored and GitHub committed 2025-04-14 20:47:55 +02:00
1 parent 15e4f9d3a5
commit 6a6771a7da
3 files changed
+19 -15

No files matched your search

+11 -11
View File
@@ -106,6 +106,8 @@ export function TopBar({
const unshowVersionBind = useDoubleTap(() => setShowVersionMobile(false));
useEffect(() => {
if (!isTauri) return;
const unlistenTrayClose = listen('try-close', async () => {
const window = getCurrentWindow();
await window.show();
@@ -115,20 +117,18 @@ export function TopBar({
await tryCloseApp(true);
});
const unlistenCloseRequested = isTauri
? getCurrentWindow().listen(
TauriEvent.WINDOW_CLOSE_REQUESTED,
async (data) => {
const ev = new CloseRequestedEvent(data);
ev.preventDefault();
await tryCloseApp();
}
)
: undefined;
const unlistenCloseRequested = getCurrentWindow().listen(
TauriEvent.WINDOW_CLOSE_REQUESTED,
async (data) => {
const ev = new CloseRequestedEvent(data);
ev.preventDefault();
await tryCloseApp();
}
);
return () => {
unlistenTrayClose.then((fn) => fn());
unlistenCloseRequested?.then((fn) => fn());
unlistenCloseRequested.then((fn) => fn());
};
}, [
config?.useTray,
@@ -125,7 +125,11 @@ function ImportExportButtons() {
const onImport = async () => {
const file = await fileOpen({
mimeTypes: ['application/json'],
}).catch((err) => {
error(err);
return null;
});
if (!file) return;
const text = await file.text();
const config = JSON.parse(text) as SkeletonConfigExport;
+4 -4
View File
@@ -1,16 +1,16 @@
import { invoke } from '@tauri-apps/api/core';
import { invoke, isTauri } from '@tauri-apps/api/core';
export function log(...msgs: any[]) {
console.log(...msgs);
invoke('logging', { msg: msgs.join() });
if (isTauri()) invoke('logging', { msg: msgs.join() });
}
export function error(...msgs: any[]) {
console.error(...msgs);
invoke('erroring', { msg: msgs.join() });
if (isTauri()) invoke('erroring', { msg: msgs.join() });
}
export function warn(...msgs: any[]) {
console.warn(...msgs);
invoke('warning', { msg: msgs.join() });
if (isTauri()) invoke('warning', { msg: msgs.join() });
}