The minimize, maximize and close buttons did nothing. They were wired
correctly; the ACL rejected them. core:default resolves to
core🪟default, which grants only read-only queries — is-maximized
is in it, which is why the maximize icon tracked state correctly, but
minimize, toggle-maximize, close and start-dragging are not. Both
windows are decorations: false, so with close denied the main window
could not be closed at all except through the tray.
Add two capabilities rather than widening the shared one: the main
window gets the four controls it draws, and the pet window gets dragging
alone, since it is moved by dragging its body and must not be able to
close or resize itself.
Every one of these calls was a bare void expression, so the rejection
was swallowed and looked identical to an unwired button. Route them
through a helper that reports the failure in the shell error banner.
This is the second time a missing capability has surfaced as a silent
no-op — the pet window previously had no entry at all. Add tests that
read the shipped capability files and assert each permission the UI
calls is granted to the window that calls it.
Also translate the TypeError the Tauri shim throws outside the
application into a sentence a user can act on. The dev server is
reachable at 127.0.0.1:1420, so opening it in a browser and hitting save
produced "Cannot read properties of undefined (reading 'invoke')".
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
52 行
1.9 KiB
TypeScript
52 行
1.9 KiB
TypeScript
/**
|
|
* Normalizes a rejection reason into a human-readable string.
|
|
*
|
|
* Tauri `invoke` rejects with the deserialized Rust error value, which is a
|
|
* plain object (for example `RuntimeCommandError { code, message }`) rather
|
|
* than an `Error` instance. Passing such a value to `String()` yields
|
|
* "[object Object]", so every IPC failure has to go through this helper.
|
|
*/
|
|
/**
|
|
* The Tauri API shim reads `window.__TAURI_INTERNALS__.invoke`, so calling any
|
|
* command from a plain browser tab throws a `TypeError` about reading 'invoke'
|
|
* rather than anything a user could act on. The dev server is reachable at
|
|
* 127.0.0.1:1420, so this is easy to hit by accident.
|
|
*/
|
|
const IPC_UNAVAILABLE_PATTERN = /reading ['"]?invoke['"]?|__TAURI_INTERNALS__/;
|
|
|
|
export const IPC_UNAVAILABLE_MESSAGE =
|
|
"此页面不在 AstrBot Desktop 应用窗口内运行,无法使用本地功能。请在应用中操作。";
|
|
|
|
export function errorMessage(reason: unknown): string {
|
|
if (reason instanceof Error) {
|
|
if (IPC_UNAVAILABLE_PATTERN.test(reason.message)) {
|
|
return IPC_UNAVAILABLE_MESSAGE;
|
|
}
|
|
return reason.message;
|
|
}
|
|
if (typeof reason === "string") {
|
|
return reason;
|
|
}
|
|
if (typeof reason === "object" && reason !== null) {
|
|
const candidate = reason as { message?: unknown; code?: unknown };
|
|
if (typeof candidate.message === "string" && candidate.message.length > 0) {
|
|
return candidate.message;
|
|
}
|
|
if (typeof candidate.code === "string" && candidate.code.length > 0) {
|
|
return candidate.code;
|
|
}
|
|
}
|
|
return String(reason);
|
|
}
|
|
|
|
/** Rust returns this code when a request was cancelled on purpose. */
|
|
export const CANCELLED_ERROR_CODE = "cancelled";
|
|
|
|
/** True when a rejection reason is a deliberate cancellation rather than a failure. */
|
|
export function isCancelledError(reason: unknown): boolean {
|
|
return (
|
|
typeof reason === "object" &&
|
|
reason !== null &&
|
|
(reason as { code?: unknown }).code === CANCELLED_ERROR_CODE
|
|
);
|
|
}
|