mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-29 05:41:46 +02:00
Fix lint errors
This commit is contained in:
16
src-web/lib/fireAndForget.ts
Normal file
16
src-web/lib/fireAndForget.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { showErrorToast } from './toast';
|
||||
|
||||
/**
|
||||
* Handles a fire-and-forget promise by catching and reporting errors
|
||||
* via console.error and a toast notification.
|
||||
*/
|
||||
export function fireAndForget(promise: Promise<unknown>) {
|
||||
promise.catch((err: unknown) => {
|
||||
console.error('Unhandled async error:', err);
|
||||
showErrorToast({
|
||||
id: 'async-error',
|
||||
title: 'Unexpected Error',
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import { HStack, VStack } from '../components/core/Stacks';
|
||||
|
||||
// Listen for toasts
|
||||
import { listenToTauriEvent } from '../hooks/useListenToTauriEvent';
|
||||
import { fireAndForget } from './fireAndForget';
|
||||
import { updateAvailableAtom } from './atoms';
|
||||
import { stringToColor } from './color';
|
||||
import { generateId } from './generateId';
|
||||
@@ -81,7 +82,7 @@ export function initGlobalListeners() {
|
||||
done,
|
||||
},
|
||||
};
|
||||
emit(event.id, result);
|
||||
fireAndForget(emit(event.id, result));
|
||||
};
|
||||
|
||||
const values = await showPromptForm({
|
||||
@@ -110,7 +111,7 @@ export function initGlobalListeners() {
|
||||
// Listen for update events
|
||||
listenToTauriEvent<UpdateInfo>('update_available', async ({ payload }) => {
|
||||
console.log('Got update available', payload);
|
||||
showUpdateAvailableToast(payload);
|
||||
fireAndForget(showUpdateAvailableToast(payload));
|
||||
});
|
||||
|
||||
listenToTauriEvent<YaakNotification>('notification', ({ payload }) => {
|
||||
@@ -125,7 +126,7 @@ export function initGlobalListeners() {
|
||||
});
|
||||
|
||||
// Check for plugin initialization errors
|
||||
invokeCmd<[string, string][]>('cmd_plugin_init_errors').then((errors) => {
|
||||
fireAndForget(invokeCmd<[string, string][]>('cmd_plugin_init_errors').then((errors) => {
|
||||
for (const [dir, message] of errors) {
|
||||
const dirBasename = dir.split('/').pop() ?? dir;
|
||||
showToast({
|
||||
@@ -155,7 +156,7 @@ export function initGlobalListeners() {
|
||||
),
|
||||
});
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
function showUpdateInstalledToast(version: string) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import { fireAndForget } from '../fireAndForget';
|
||||
|
||||
export type Appearance = 'light' | 'dark';
|
||||
|
||||
@@ -22,13 +23,13 @@ export function subscribeToWindowAppearanceChange(
|
||||
unsubscribe: () => {},
|
||||
};
|
||||
|
||||
getCurrentWebviewWindow()
|
||||
fireAndForget(getCurrentWebviewWindow()
|
||||
.onThemeChanged((t) => {
|
||||
cb(t.payload);
|
||||
})
|
||||
.then((l) => {
|
||||
container.unsubscribe = l;
|
||||
});
|
||||
}));
|
||||
|
||||
return () => container.unsubscribe();
|
||||
}
|
||||
@@ -43,6 +44,6 @@ export function resolveAppearance(
|
||||
|
||||
export function subscribeToPreferredAppearance(cb: (a: Appearance) => void) {
|
||||
cb(getCSSAppearance());
|
||||
getWindowAppearance().then(cb);
|
||||
fireAndForget(getWindowAppearance().then(cb));
|
||||
subscribeToWindowAppearanceChange(cb);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user