ffb4cb5d62
将资源卡本体化并补齐分区缩放滚动与依赖聚类 增加全进程三槽预览调度范围取消与安全分块读取 保持布局 CAS 预览缓存回收和依赖图权威合同 补齐资源管理前端 Tauri AppSurface 回归并同步文档
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
const PROJECT_RESOURCE_PREVIEW_CANCELLED_ERROR =
|
|
'project-resource-preview-scope-cancelled';
|
|
|
|
let projectResourcePreviewOpaqueIdSequence = 0;
|
|
|
|
function createProjectResourcePreviewOpaqueId(prefix: 'scope' | 'request') {
|
|
projectResourcePreviewOpaqueIdSequence += 1;
|
|
const cryptoApi = globalThis.crypto;
|
|
const randomId = cryptoApi?.randomUUID?.();
|
|
if (randomId) {
|
|
return `${prefix}:${randomId}`;
|
|
}
|
|
if (cryptoApi?.getRandomValues) {
|
|
const randomWords = cryptoApi.getRandomValues(new Uint32Array(4));
|
|
return `${prefix}:${Array.from(randomWords, (word) => word.toString(36)).join('-')}`;
|
|
}
|
|
return `${prefix}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}:${projectResourcePreviewOpaqueIdSequence.toString(36)}`;
|
|
}
|
|
|
|
export function createProjectResourcePreviewScopeId() {
|
|
return createProjectResourcePreviewOpaqueId('scope');
|
|
}
|
|
|
|
export function createProjectResourcePreviewRequestId() {
|
|
return createProjectResourcePreviewOpaqueId('request');
|
|
}
|
|
|
|
export function isProjectResourcePreviewCancellation(error: unknown) {
|
|
const message =
|
|
error instanceof Error
|
|
? error.message
|
|
: typeof error === 'string'
|
|
? error
|
|
: null;
|
|
return message === PROJECT_RESOURCE_PREVIEW_CANCELLED_ERROR;
|
|
}
|
|
|
|
export function cancelLocalProjectResourcePreviewScope(scopeId: string) {
|
|
const invoke = window.__TAURI__?.core?.invoke;
|
|
if (!invoke) {
|
|
return;
|
|
}
|
|
try {
|
|
void Promise.resolve(
|
|
invoke('cancel_local_project_resource_preview_scope', { scopeId }),
|
|
).catch(() => undefined);
|
|
} catch {
|
|
// The epoch/owner fence remains authoritative if the WebView is already
|
|
// tearing down and can no longer deliver the best-effort cancellation.
|
|
}
|
|
}
|