mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-12 11:59:40 +02:00
Fix lint errors
This commit is contained in:
@@ -29,7 +29,7 @@ export function useLicense() {
|
||||
await queryClient.invalidateQueries({ queryKey: CHECK_QUERY_KEY });
|
||||
});
|
||||
return () => {
|
||||
unlisten.then((fn) => fn());
|
||||
void unlisten.then((fn) => fn());
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
|
||||
const handleError = (err: unknown) => {
|
||||
showToast({
|
||||
id: `${err}`,
|
||||
message: `${err}`,
|
||||
id: err instanceof Error ? err.message : String(err),
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
color: 'danger',
|
||||
timeout: 5000,
|
||||
});
|
||||
@@ -186,16 +186,16 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
}
|
||||
|
||||
if (result.type === 'uncommitted_changes') {
|
||||
callbacks.promptUncommittedChanges().then(async (strategy) => {
|
||||
void callbacks.promptUncommittedChanges().then(async (strategy) => {
|
||||
if (strategy === 'cancel') return;
|
||||
|
||||
await invoke('cmd_git_reset_changes', { dir });
|
||||
return invoke<PullResult>('cmd_git_pull', { dir });
|
||||
}).then(async () => { onSuccess(); await callbacks.forceSync(); }, handleError);
|
||||
}).then(async () => { await onSuccess(); await callbacks.forceSync(); }, handleError);
|
||||
}
|
||||
|
||||
if (result.type === 'diverged') {
|
||||
callbacks.promptDiverged(result).then((strategy) => {
|
||||
void callbacks.promptDiverged(result).then((strategy) => {
|
||||
if (strategy === 'cancel') return;
|
||||
|
||||
if (strategy === 'force_reset') {
|
||||
@@ -211,7 +211,7 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => {
|
||||
remote: result.remote,
|
||||
branch: result.branch,
|
||||
});
|
||||
}).then(async () => { onSuccess(); await callbacks.forceSync(); }, handleError);
|
||||
}).then(async () => { await onSuccess(); await callbacks.forceSync(); }, handleError);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -39,7 +39,7 @@ export function watchWorkspaceFiles(
|
||||
channel,
|
||||
});
|
||||
|
||||
unlistenPromise.then(({ unlistenEvent }) => {
|
||||
void unlistenPromise.then(({ unlistenEvent }) => {
|
||||
addWatchKey(unlistenEvent);
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ export function watchWorkspaceFiles(
|
||||
}
|
||||
|
||||
function unlistenToWatcher(unlistenEvent: string) {
|
||||
emit(unlistenEvent).then(() => {
|
||||
void emit(unlistenEvent).then(() => {
|
||||
removeWatchKey(unlistenEvent);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ export class PluginInstance {
|
||||
);
|
||||
} catch (err: unknown) {
|
||||
await ctx.toast.show({
|
||||
message: `Failed to initialize plugin ${this.#workerData.bootRequest.dir.split('/').pop()}: ${err}`,
|
||||
message: `Failed to initialize plugin ${this.#workerData.bootRequest.dir.split('/').pop()}: ${err instanceof Error ? err.message : String(err)}`,
|
||||
color: 'notice',
|
||||
icon: 'alert_triangle',
|
||||
timeout: 30000,
|
||||
@@ -328,6 +328,7 @@ export class PluginInstance {
|
||||
payload.values = applyFormInputDefaults(args, payload.values);
|
||||
const resolvedArgs = await applyDynamicFormInput(ctx, args, payload);
|
||||
const resolvedActions: HttpAuthenticationAction[] = [];
|
||||
// oxlint-disable-next-line unbound-method
|
||||
for (const { onSelect: _onSelect, ...action } of actions ?? []) {
|
||||
resolvedActions.push(action);
|
||||
}
|
||||
@@ -474,7 +475,7 @@ export class PluginInstance {
|
||||
{
|
||||
type: 'call_template_function_response',
|
||||
value: null,
|
||||
error: `${err}`.replace(/^Error:\s*/g, ''),
|
||||
error: (err instanceof Error ? err.message : String(err)).replace(/^Error:\s*/g, ''),
|
||||
},
|
||||
replyId,
|
||||
);
|
||||
@@ -483,7 +484,7 @@ export class PluginInstance {
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
const error = `${err}`.replace(/^Error:\s*/g, '');
|
||||
const error = (err instanceof Error ? err.message : String(err)).replace(/^Error:\s*/g, '');
|
||||
console.log('Plugin call threw exception', payload.type, '→', error);
|
||||
this.#sendPayload(context, { type: 'error_response', error }, replyId);
|
||||
return;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* oxlint-disable unbound-method */
|
||||
import process from 'node:process';
|
||||
|
||||
export function interceptStdout(intercept: (text: string) => string) {
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
"moduleResolution": "node16",
|
||||
"resolveJsonModule": true,
|
||||
"sourceMap": true,
|
||||
"outDir": "build",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"*": ["node_modules/*", "src/types/*"]
|
||||
}
|
||||
"outDir": "build"
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ describe('template-function-faker', () => {
|
||||
it('renders date results as unquoted ISO strings', async () => {
|
||||
const { plugin } = await import('../src/index');
|
||||
const fn = plugin.templateFunctions?.find((fn) => fn.name === 'faker.date.future');
|
||||
// oxlint-disable-next-line unbound-method
|
||||
const onRender = fn?.onRender;
|
||||
|
||||
expect(onRender).toBeTypeOf('function');
|
||||
|
||||
@@ -173,7 +173,7 @@ function toHarRequest(request: Partial<HttpRequest>) {
|
||||
return har;
|
||||
}
|
||||
|
||||
function maybeParseJSON<T>(v: unknown, fallback: T): T | unknown {
|
||||
function maybeParseJSON<T>(v: unknown, fallback: T): unknown {
|
||||
if (typeof v !== 'string') return fallback;
|
||||
try {
|
||||
return JSON.parse(v);
|
||||
@@ -305,7 +305,7 @@ export const plugin: PluginDefinition = {
|
||||
});
|
||||
} catch (err) {
|
||||
await ctx.toast.show({
|
||||
message: `Failed to generate snippet: ${err}`,
|
||||
message: `Failed to generate snippet: ${err instanceof Error ? err.message : String(err)}`,
|
||||
icon: 'alert_triangle',
|
||||
color: 'danger',
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ export const plugin: PluginDefinition = {
|
||||
mcpServer = createMcpServer({ yaak: ctx }, serverPort);
|
||||
} catch (err) {
|
||||
console.error('Failed to start MCP server:', err);
|
||||
ctx.toast.show({
|
||||
void ctx.toast.show({
|
||||
message: `Failed to start MCP Server: ${err instanceof Error ? err.message : String(err)}`,
|
||||
icon: 'alert_triangle',
|
||||
color: 'danger',
|
||||
|
||||
@@ -30,7 +30,7 @@ export function createMcpServer(ctx: McpServerContext, port: number) {
|
||||
if (!mcpServer.isConnected()) {
|
||||
// Connect the mcp with the transport
|
||||
await mcpServer.connect(transport);
|
||||
ctx.yaak.toast.show({
|
||||
void ctx.yaak.toast.show({
|
||||
message: `MCP Server connected`,
|
||||
icon: 'info',
|
||||
color: 'info',
|
||||
@@ -48,7 +48,7 @@ export function createMcpServer(ctx: McpServerContext, port: number) {
|
||||
},
|
||||
(info) => {
|
||||
console.log('Started MCP server on ', info.address);
|
||||
ctx.yaak.toast.show({
|
||||
void ctx.yaak.toast.show({
|
||||
message: `MCP Server running on http://127.0.0.1:${info.port}`,
|
||||
icon: 'info',
|
||||
color: 'secondary',
|
||||
|
||||
@@ -590,11 +590,11 @@ export const plugin: PluginDefinition = {
|
||||
credentialsInBody,
|
||||
});
|
||||
} else {
|
||||
throw new Error(`Invalid grant type ${grantType}`);
|
||||
throw new Error(`Invalid grant type ${String(grantType)}`);
|
||||
}
|
||||
|
||||
const headerName = stringArg(values, 'headerName') || 'Authorization';
|
||||
const headerValue = `${headerPrefix} ${token.response[tokenName]}`.trim();
|
||||
const headerValue = `${headerPrefix} ${token.response[tokenName] ?? ''}`.trim();
|
||||
return { setHeaders: [{ name: headerName, value: headerValue }] };
|
||||
},
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ export const plugin: PluginDefinition = {
|
||||
const filtered = JSONPath({ path: args.filter, json: parsed });
|
||||
return { content: JSON.stringify(filtered, null, 2) };
|
||||
} catch (err) {
|
||||
return { content: '', error: `Invalid filter: ${err}` };
|
||||
return { content: '', error: `Invalid filter: ${err instanceof Error ? err.message : String(err)}` };
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -18,7 +18,7 @@ export const plugin: PluginDefinition = {
|
||||
// Not sure what cases this happens in (?)
|
||||
return { content: String(result) };
|
||||
} catch (err) {
|
||||
return { content: '', error: `Invalid filter: ${err}` };
|
||||
return { content: '', error: `Invalid filter: ${err instanceof Error ? err.message : String(err)}` };
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -203,7 +203,7 @@ function importEnvironment(
|
||||
variables: Object.entries(e.data).map(([name, value]) => ({
|
||||
enabled: true,
|
||||
name,
|
||||
value: `${value}`,
|
||||
value: String(value),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ function importFolder(
|
||||
variables: Object.entries(f.environment ?? {}).map(([name, value]) => ({
|
||||
enabled: true,
|
||||
name,
|
||||
value: `${value}`,
|
||||
value: String(value),
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -308,7 +308,7 @@ function importEnvironment(
|
||||
variables: Object.entries(e.data ?? {}).map(([name, value]) => ({
|
||||
enabled: true,
|
||||
name,
|
||||
value: `${value}`,
|
||||
value: String(value),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ function parseJSONToRecord<T>(jsonStr: string): Record<string, T> | null {
|
||||
}
|
||||
}
|
||||
|
||||
function toRecord<T>(value: Record<string, T> | unknown): Record<string, T> {
|
||||
function toRecord<T>(value: unknown): Record<string, T> {
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
return value as Record<string, T>;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ export function convertPostman(contents: string): ImportPluginResponse | undefin
|
||||
return { resources };
|
||||
}
|
||||
|
||||
function convertUrl(rawUrl: string | unknown): Pick<HttpRequest, 'url' | 'urlParameters'> {
|
||||
function convertUrl(rawUrl: unknown): Pick<HttpRequest, 'url' | 'urlParameters'> {
|
||||
if (typeof rawUrl === 'string') {
|
||||
return { url: rawUrl, urlParameters: [] };
|
||||
}
|
||||
@@ -173,7 +173,7 @@ function convertUrl(rawUrl: string | unknown): Pick<HttpRequest, 'url' | 'urlPar
|
||||
}
|
||||
|
||||
if ('host' in url) {
|
||||
v += `${Array.isArray(url.host) ? url.host.join('.') : url.host}`;
|
||||
v += `${Array.isArray(url.host) ? url.host.join('.') : String(url.host)}`;
|
||||
}
|
||||
|
||||
if ('port' in url && typeof url.port === 'string') {
|
||||
@@ -490,7 +490,7 @@ function parseJSONToRecord<T>(jsonStr: string): Record<string, T> | null {
|
||||
}
|
||||
}
|
||||
|
||||
function toRecord<T>(value: Record<string, T> | unknown): Record<string, T> {
|
||||
function toRecord<T>(value: unknown): Record<string, T> {
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
return value as Record<string, T>;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export const openWorkspaceFromSyncDir = createFastMutation<void, void, string>({
|
||||
|
||||
await applySync(workspace.id, dir, ops);
|
||||
|
||||
router.navigate({
|
||||
await router.navigate({
|
||||
to: '/workspaces/$workspaceId',
|
||||
params: { workspaceId: workspace.id },
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { DnsOverride, Workspace } from '@yaakapp-internal/models';
|
||||
import { patchModel } from '@yaakapp-internal/models';
|
||||
import { useCallback, useId, useMemo } from 'react';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { Button } from './core/Button';
|
||||
import { Checkbox } from './core/Checkbox';
|
||||
import { IconButton } from './core/IconButton';
|
||||
@@ -29,7 +30,7 @@ export function DnsOverridesEditor({ workspace }: Props) {
|
||||
|
||||
const handleChange = useCallback(
|
||||
(overrides: DnsOverride[]) => {
|
||||
patchModel(workspace, { settingDnsOverrides: overrides });
|
||||
fireAndForget(patchModel(workspace, { settingDnsOverrides: overrides }));
|
||||
},
|
||||
[workspace],
|
||||
);
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
useEnvironmentsBreakdown,
|
||||
} from '../hooks/useEnvironmentsBreakdown';
|
||||
import { deleteModelWithConfirm } from '../lib/deleteModelWithConfirm';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { isBaseEnvironment, isSubEnvironment } from '../lib/model_util';
|
||||
import { resolvedModelName } from '../lib/resolvedModelName';
|
||||
@@ -199,7 +200,7 @@ function EnvironmentEditDialogSidebar({
|
||||
// Not sure why this is needed, but without it the
|
||||
// edit input blurs immediately after opening.
|
||||
requestAnimationFrame(() => {
|
||||
actions['sidebar.selected.rename'].cb(items);
|
||||
fireAndForget(actions['sidebar.selected.rename'].cb(items));
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@ import { allRequestsAtom } from '../hooks/useAllRequests';
|
||||
import { useFolderActions } from '../hooks/useFolderActions';
|
||||
import { useLatestHttpResponse } from '../hooks/useLatestHttpResponse';
|
||||
import { sendAnyHttpRequest } from '../hooks/useSendAnyHttpRequest';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { showDialog } from '../lib/dialog';
|
||||
import { resolvedModelName } from '../lib/resolvedModelName';
|
||||
import { router } from '../lib/router';
|
||||
@@ -45,7 +46,7 @@ export function FolderLayout({ folder, style }: Props) {
|
||||
}, [folder.id, folders, requests]);
|
||||
|
||||
const handleSendAll = useCallback(() => {
|
||||
sendAllAction?.call(folder);
|
||||
if (sendAllAction) fireAndForget(sendAllAction.call(folder));
|
||||
}, [sendAllAction, folder]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { clear, readText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import * as m from 'motion/react-m';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { useImportCurl } from '../hooks/useImportCurl';
|
||||
import { useWindowFocus } from '../hooks/useWindowFocus';
|
||||
import { Button } from './core/Button';
|
||||
@@ -15,7 +16,7 @@ export function ImportCurlButton() {
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: none
|
||||
useEffect(() => {
|
||||
readText().then(setClipboardText);
|
||||
fireAndForget(readText().then(setClipboardText));
|
||||
}, [focused]);
|
||||
|
||||
if (!clipboardText?.trim().startsWith('curl ')) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { linter } from '@codemirror/lint';
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import { patchModel } from '@yaakapp-internal/models';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { useKeyValue } from '../hooks/useKeyValue';
|
||||
import { textLikelyContainsJsonComments } from '../lib/jsonComments';
|
||||
import { Banner } from './core/Banner';
|
||||
@@ -58,12 +59,12 @@ export function JsonBodyEditor({ forceUpdateKey, heightMode, request }: Props) {
|
||||
} else {
|
||||
delete newBody.sendJsonComments;
|
||||
}
|
||||
patchModel(request, { body: newBody });
|
||||
fireAndForget(patchModel(request, { body: newBody }));
|
||||
}, [request, autoFix]);
|
||||
|
||||
const handleDropdownOpen = useCallback(() => {
|
||||
if (!bannerDismissed) {
|
||||
setBannerDismissed(true);
|
||||
fireAndForget(setBannerDismissed(true));
|
||||
}
|
||||
}, [bannerDismissed, setBannerDismissed]);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getRecentCookieJars } from '../hooks/useRecentCookieJars';
|
||||
import { getRecentEnvironments } from '../hooks/useRecentEnvironments';
|
||||
import { getRecentRequests } from '../hooks/useRecentRequests';
|
||||
import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { router } from '../lib/router';
|
||||
|
||||
export function RedirectToLatestWorkspace() {
|
||||
@@ -20,7 +21,7 @@ export function RedirectToLatestWorkspace() {
|
||||
return;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
fireAndForget((async () => {
|
||||
const workspaceId = recentWorkspaces[0] ?? workspaces[0]?.id ?? 'n/a';
|
||||
const environmentId = (await getRecentEnvironments(workspaceId))[0] ?? null;
|
||||
const cookieJarId = (await getRecentCookieJars(workspaceId))[0] ?? null;
|
||||
@@ -34,7 +35,7 @@ export function RedirectToLatestWorkspace() {
|
||||
|
||||
console.log('Redirecting to workspace', params, search);
|
||||
await router.navigate({ to: '/workspaces/$workspaceId', params, search });
|
||||
})();
|
||||
})());
|
||||
}, [recentWorkspaces, workspaces, workspaces.length]);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -43,6 +43,7 @@ import { useSidebarHidden } from '../hooks/useSidebarHidden';
|
||||
import { getWebsocketRequestActions } from '../hooks/useWebsocketRequestActions';
|
||||
import { deepEqualAtom } from '../lib/atoms';
|
||||
import { deleteModelWithConfirm } from '../lib/deleteModelWithConfirm';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { resolvedModelName } from '../lib/resolvedModelName';
|
||||
import { isSidebarFocused } from '../lib/scopes';
|
||||
@@ -439,7 +440,7 @@ function Sidebar({ className }: { className?: string }) {
|
||||
leftSlot: <Icon icon="arrow_right_circle" />,
|
||||
hidden: workspaces.length <= 1 || requestItems.length === 0 || requestItems.length !== items.length,
|
||||
onSelect: () => {
|
||||
actions['sidebar.selected.move'].cb(items);
|
||||
fireAndForget(actions['sidebar.selected.move'].cb(items));
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -127,7 +127,7 @@ export function WorkspaceEncryptionSetting({ size, expanded, onDone, onEnabledEn
|
||||
await enableEncryption(workspaceMeta.workspaceId);
|
||||
setJustEnabledEncryption(true);
|
||||
} catch (err) {
|
||||
setError(`Failed to enable encryption: ${err}`);
|
||||
setError(`Failed to enable encryption: ${err instanceof Error ? err.message : String(err)}`);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
} from 'react';
|
||||
import { useKey, useWindowSize } from 'react-use';
|
||||
import { useClickOutside } from '../../hooks/useClickOutside';
|
||||
import { fireAndForget } from '../../lib/fireAndForget';
|
||||
import type { HotkeyAction } from '../../hooks/useHotKey';
|
||||
import { useHotKey } from '../../hooks/useHotKey';
|
||||
import { useStateWithDeps } from '../../hooks/useStateWithDeps';
|
||||
@@ -614,7 +615,7 @@ const Menu = forwardRef<Omit<DropdownRef, 'open' | 'isOpen' | 'toggle' | 'items'
|
||||
setActiveSubmenu({ item, parent, viaKeyboard: true });
|
||||
}
|
||||
} else if (item.onSelect) {
|
||||
handleSelect(item);
|
||||
fireAndForget(handleSelect(item));
|
||||
}
|
||||
},
|
||||
{},
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { useKeyValue } from '../../../hooks/useKeyValue';
|
||||
import { fireAndForget } from '../../../lib/fireAndForget';
|
||||
import { computeSideForDragMove } from '../../../lib/dnd';
|
||||
import { DropMarker } from '../../DropMarker';
|
||||
import { ErrorBoundary } from '../../ErrorBoundary';
|
||||
@@ -143,7 +144,7 @@ export const Tabs = forwardRef<TabsRef, Props>(function Tabs(
|
||||
forwardedRef,
|
||||
() => ({
|
||||
setActiveTab: (value: string) => {
|
||||
onChangeValue(value);
|
||||
fireAndForget(onChangeValue(value));
|
||||
},
|
||||
}),
|
||||
[onChangeValue],
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useRandomKey } from '../../hooks/useRandomKey';
|
||||
import { sync } from '../../init/sync';
|
||||
import { showConfirm, showConfirmDelete } from '../../lib/confirm';
|
||||
import { showDialog } from '../../lib/dialog';
|
||||
import { fireAndForget } from '../../lib/fireAndForget';
|
||||
import { showPrompt } from '../../lib/prompt';
|
||||
import { showErrorToast, showToast } from '../../lib/toast';
|
||||
import { Banner } from '../core/Banner';
|
||||
@@ -246,7 +247,7 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) {
|
||||
message: 'Changes have been reset',
|
||||
color: 'success',
|
||||
});
|
||||
sync({ force: true });
|
||||
fireAndForget(sync({ force: true }));
|
||||
},
|
||||
onError(err) {
|
||||
showErrorToast({
|
||||
@@ -293,7 +294,7 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) {
|
||||
</>
|
||||
),
|
||||
});
|
||||
sync({ force: true });
|
||||
fireAndForget(sync({ force: true }));
|
||||
},
|
||||
onError(err) {
|
||||
showErrorToast({
|
||||
|
||||
@@ -270,7 +270,7 @@ function GqlTypeInfo({
|
||||
{Object.entries(fields).map(([fieldName, field]) => {
|
||||
const fieldItem: ExplorerItem = toExplorerItem(field, item);
|
||||
return (
|
||||
<div key={`${field.type}::${field.name}`} className="my-4">
|
||||
<div key={`${String(field.type)}::${field.name}`} className="my-4">
|
||||
<GqlTypeRow
|
||||
item={fieldItem}
|
||||
setItem={setItem}
|
||||
@@ -363,7 +363,7 @@ function GqlTypeInfo({
|
||||
<Subheading>Arguments</Subheading>
|
||||
{item.type.args.map((a) => {
|
||||
return (
|
||||
<div key={`${a.type}::${a.name}`} className="my-4">
|
||||
<div key={`${String(a.type)}::${a.name}`} className="my-4">
|
||||
<GqlTypeRow
|
||||
name={{ value: a.name, color: 'info' }}
|
||||
item={{ kind: 'type', type: a.type, from: item }}
|
||||
@@ -393,7 +393,7 @@ function GqlTypeInfo({
|
||||
from: item,
|
||||
};
|
||||
return (
|
||||
<div key={`${field.type}::${field.name}`} className="my-4">
|
||||
<div key={`${String(field.type)}::${field.name}`} className="my-4">
|
||||
<GqlTypeRow
|
||||
item={fieldItem}
|
||||
setItem={setItem}
|
||||
@@ -431,7 +431,7 @@ function GqlTypeInfo({
|
||||
if (field == null) return null;
|
||||
const fieldItem: ExplorerItem = { kind: 'field', type: field, from: item };
|
||||
return (
|
||||
<div key={`${field.type}::${field.name}`} className="my-4">
|
||||
<div key={`${String(field.type)}::${field.name}`} className="my-4">
|
||||
<GqlTypeRow
|
||||
item={fieldItem}
|
||||
setItem={setItem}
|
||||
@@ -512,7 +512,7 @@ function GqlTypeRow({
|
||||
<span className="text-text-subtle">(</span>
|
||||
{item.type.args.map((arg) => (
|
||||
<div
|
||||
key={`${arg.type}::${arg.name}`}
|
||||
key={`${String(arg.type)}::${arg.name}`}
|
||||
className={classNames(item.type.args.length === 1 && 'inline-flex')}
|
||||
>
|
||||
{item.type.args.length > 1 && <> </>}
|
||||
|
||||
@@ -6,13 +6,14 @@ import type { PDFDocumentProxy } from 'pdfjs-dist';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Document, Page } from 'react-pdf';
|
||||
import { useContainerSize } from '../../hooks/useContainerQuery';
|
||||
import { fireAndForget } from '../../lib/fireAndForget';
|
||||
|
||||
import('react-pdf').then(({ pdfjs }) => {
|
||||
fireAndForget(import('react-pdf').then(({ pdfjs }) => {
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
||||
'pdfjs-dist/build/pdf.worker.min.mjs',
|
||||
import.meta.url,
|
||||
).toString();
|
||||
});
|
||||
}));
|
||||
|
||||
interface Props {
|
||||
bodyPath?: string;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Listen for settings changes, the re-compute theme
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import type { ModelPayload } from '@yaakapp-internal/models';
|
||||
import { fireAndForget } from './lib/fireAndForget';
|
||||
import { getSettings } from './lib/settings';
|
||||
|
||||
function setFontSizeOnDocument(fontSize: number) {
|
||||
@@ -13,4 +14,4 @@ listen<ModelPayload>('model_write', async (event) => {
|
||||
setFontSizeOnDocument(event.payload.model.interfaceFontSize);
|
||||
}).catch(console.error);
|
||||
|
||||
getSettings().then((settings) => setFontSizeOnDocument(settings.interfaceFontSize));
|
||||
fireAndForget(getSettings().then((settings) => setFontSizeOnDocument(settings.interfaceFontSize)));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Listen for settings changes, the re-compute theme
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import type { ModelPayload, Settings } from '@yaakapp-internal/models';
|
||||
import { fireAndForget } from './lib/fireAndForget';
|
||||
import { getSettings } from './lib/settings';
|
||||
|
||||
function setFonts(settings: Settings) {
|
||||
@@ -17,4 +18,4 @@ listen<ModelPayload>('model_write', async (event) => {
|
||||
setFonts(event.payload.model);
|
||||
}).catch(console.error);
|
||||
|
||||
getSettings().then((settings) => setFonts(settings));
|
||||
fireAndForget(getSettings().then((settings) => setFonts(settings)));
|
||||
|
||||
@@ -16,7 +16,7 @@ interface TypeMap {
|
||||
}
|
||||
|
||||
export function useActiveRequest<T extends keyof TypeMap>(
|
||||
model?: T | undefined,
|
||||
model?: T,
|
||||
): TypeMap[T] | null {
|
||||
const activeRequest = useAtomValue(activeRequestAtom);
|
||||
if (model == null) return activeRequest as TypeMap[T];
|
||||
|
||||
@@ -18,7 +18,7 @@ export function useCreateDropdownItems({
|
||||
}: {
|
||||
hideFolder?: boolean;
|
||||
hideIcons?: boolean;
|
||||
folderId?: string | null | 'active-folder';
|
||||
folderId?: string | null;
|
||||
} = {}): DropdownItem[] {
|
||||
const workspaceId = useAtomValue(activeWorkspaceIdAtom);
|
||||
const activeRequest = useAtomValue(activeRequestAtom);
|
||||
@@ -40,7 +40,7 @@ export function getCreateDropdownItems({
|
||||
}: {
|
||||
hideFolder?: boolean;
|
||||
hideIcons?: boolean;
|
||||
folderId?: string | null | 'active-folder';
|
||||
folderId?: string | null;
|
||||
workspaceId: string | null;
|
||||
activeRequest: HttpRequest | GrpcRequest | WebsocketRequest | null;
|
||||
onCreate?: (
|
||||
|
||||
@@ -42,7 +42,7 @@ export function createFastMutation<TData = unknown, TError = unknown, TVariables
|
||||
if (!disableToastError) {
|
||||
showToast({
|
||||
id: stringKey,
|
||||
message: `${err}`,
|
||||
message: err instanceof Error ? err.message : String(err),
|
||||
color: 'danger',
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
} from '@yaakapp-internal/models';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useEffect } from 'react';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
|
||||
export function useHttpResponseEvents(response: HttpResponse | null) {
|
||||
const allEvents = useAtomValue(httpResponseEventsAtom);
|
||||
@@ -18,10 +19,10 @@ export function useHttpResponseEvents(response: HttpResponse | null) {
|
||||
}
|
||||
|
||||
// Fetch events from database, filtering out events from other responses and merging atomically
|
||||
invoke<HttpResponseEvent[]>('cmd_get_http_response_events', { responseId: response.id }).then(
|
||||
fireAndForget(invoke<HttpResponseEvent[]>('cmd_get_http_response_events', { responseId: response.id }).then(
|
||||
(events) =>
|
||||
mergeModelsInStore('http_response_event', events, (e) => e.responseId === response.id),
|
||||
);
|
||||
));
|
||||
}, [response?.id]);
|
||||
|
||||
const events = allEvents.filter((e) => e.responseId === response?.id);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { atomWithKVStorage } from '../lib/atoms/atomWithKVStorage';
|
||||
import { activeRequestIdAtom } from './useActiveRequestId';
|
||||
|
||||
@@ -69,9 +70,9 @@ export function useGrpcEvents(connectionId: string | null) {
|
||||
}
|
||||
|
||||
// Fetch events from database, filtering out events from other connections and merging atomically
|
||||
invoke<GrpcEvent[]>('models_grpc_events', { connectionId }).then((events) =>
|
||||
fireAndForget(invoke<GrpcEvent[]>('models_grpc_events', { connectionId }).then((events) =>
|
||||
mergeModelsInStore('grpc_event', events, (e) => e.connectionId === connectionId),
|
||||
);
|
||||
));
|
||||
}, [connectionId]);
|
||||
|
||||
return useMemo(
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
import { atomWithKVStorage } from '../lib/atoms/atomWithKVStorage';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { activeRequestIdAtom } from './useActiveRequestId';
|
||||
@@ -56,9 +57,9 @@ export function useWebsocketEvents(connectionId: string | null) {
|
||||
}
|
||||
|
||||
// Fetch events from database, filtering out events from other connections and merging atomically
|
||||
invoke<WebsocketEvent[]>('models_websocket_events', { connectionId }).then((events) =>
|
||||
fireAndForget(invoke<WebsocketEvent[]>('models_websocket_events', { connectionId }).then((events) =>
|
||||
mergeModelsInStore('websocket_event', events, (e) => e.connectionId === connectionId),
|
||||
);
|
||||
));
|
||||
}, [connectionId]);
|
||||
|
||||
return useMemo(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { fireAndForget } from '../lib/fireAndForget';
|
||||
|
||||
export function useWindowFocus() {
|
||||
const [visible, setVisible] = useState(true);
|
||||
@@ -10,7 +11,7 @@ export function useWindowFocus() {
|
||||
});
|
||||
|
||||
return () => {
|
||||
unlisten.then((fn) => fn());
|
||||
fireAndForget(unlisten.then((fn) => fn()));
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ module.exports = {
|
||||
},
|
||||
plugins: [
|
||||
require('@tailwindcss/container-queries'),
|
||||
// oxlint-disable-next-line unbound-method
|
||||
plugin(function ({ addVariant }) {
|
||||
addVariant('hocus', ['&:hover', '&:focus-visible', '&.focus:focus']);
|
||||
addVariant('focus-visible-or-class', ['&:focus-visible', '&.focus:focus']);
|
||||
|
||||
Reference in New Issue
Block a user