Files
STARTLINER/src/invoke.ts
2025-04-04 22:14:09 +00:00

40 lines
923 B
TypeScript

import {
InvokeArgs,
InvokeOptions,
invoke as real_invoke,
} from '@tauri-apps/api/core';
import { emit } from '@tauri-apps/api/event';
export const invoke = async <T>(
cmd: string,
args?: InvokeArgs,
options?: InvokeOptions
): Promise<T> => {
try {
return await real_invoke(cmd, args, options);
} catch (e: unknown) {
if (typeof e === 'string') {
emit('invoke-error', {
message: e,
header: `${cmd} failed`,
});
} else {
console.error(`Unresolved error: ${e}`);
}
throw e;
}
};
export const invoke_nopopup = async <T>(
cmd: string,
args?: InvokeArgs,
options?: InvokeOptions
): Promise<T> => {
try {
return await real_invoke(cmd, args, options);
} catch (e: unknown) {
console.error(`Error invoking ${cmd}: ${e}`);
throw e;
}
};