mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
Fix home entry actions
Generated-By: looper 0.8.0 (runner=fixer, agent=codex)
This commit is contained in:
@@ -31,6 +31,7 @@ import type {
|
||||
SkillSummary,
|
||||
} from '../types';
|
||||
import { apiProtocolLabel } from '../utils/apiProtocol';
|
||||
import { formatPickAndImportFailure } from '../utils/pickAndImportError';
|
||||
import { CenteredLoader } from './Loading';
|
||||
import { DesignsTab } from './DesignsTab';
|
||||
import { DesignSystemPreviewModal } from './DesignSystemPreviewModal';
|
||||
@@ -107,28 +108,6 @@ function defaultPluginInputsForCreate(
|
||||
};
|
||||
}
|
||||
|
||||
function formatPickAndImportErrorDetails(details: unknown): string | undefined {
|
||||
if (typeof details === 'string' && details.length > 0) return details;
|
||||
if (details == null || typeof details !== 'object') return undefined;
|
||||
const record = details as Record<string, unknown>;
|
||||
const error = record.error;
|
||||
if (error != null && typeof error === 'object') {
|
||||
const errRecord = error as Record<string, unknown>;
|
||||
const message = errRecord.message;
|
||||
const nestedDetails = errRecord.details;
|
||||
if (typeof message === 'string' && message.length > 0) {
|
||||
if (nestedDetails != null && typeof nestedDetails === 'object') {
|
||||
const nestedReason = (nestedDetails as Record<string, unknown>).reason;
|
||||
if (typeof nestedReason === 'string' && nestedReason.length > 0) {
|
||||
return `${message} (${nestedReason})`;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Theme options exposed in the avatar-popover appearance submenu.
|
||||
// Mirrors the segmented control in `SettingsDialog` so the same three
|
||||
// choices (System / Light / Dark) are available from both surfaces.
|
||||
@@ -321,6 +300,7 @@ export function EntryShell({
|
||||
message: string;
|
||||
details?: string;
|
||||
} | null>(null);
|
||||
const [chipImporting, setChipImporting] = useState(false);
|
||||
const [integrationTab, setIntegrationTab] = useState<IntegrationTab>(integrationInitialTab);
|
||||
const [homePromptHandoff, setHomePromptHandoff] = useState<HomePromptHandoff | null>(null);
|
||||
const avatarMenuRef = useRef<HTMLDivElement | null>(null);
|
||||
@@ -443,6 +423,7 @@ export function EntryShell({
|
||||
// project. Browser-only shells fall back to the existing modal
|
||||
// path so the user can paste a baseDir.
|
||||
async function handleChipFolderImport() {
|
||||
if (chipImporting) return;
|
||||
// PR #974 trust boundary: the renderer cannot pick a folder directly
|
||||
// anymore — the bridge exposes `pickAndImport` instead (atomic
|
||||
// pick + HMAC-gated import). On the web (no electronAPI) or when
|
||||
@@ -453,22 +434,18 @@ export function EntryShell({
|
||||
typeof window.electronAPI?.pickAndImport === 'function' &&
|
||||
onImportFolderResponse
|
||||
) {
|
||||
const result = await window.electronAPI.pickAndImport();
|
||||
if (!result || ('canceled' in result && result.canceled === true)) return;
|
||||
if (result.ok === true) {
|
||||
await onImportFolderResponse(result.response);
|
||||
return;
|
||||
setChipImporting(true);
|
||||
try {
|
||||
const result = await window.electronAPI.pickAndImport();
|
||||
if (!result || ('canceled' in result && result.canceled === true)) return;
|
||||
if (result.ok === true) {
|
||||
await onImportFolderResponse(result.response);
|
||||
return;
|
||||
}
|
||||
setFolderImportError(formatPickAndImportFailure(result));
|
||||
} finally {
|
||||
setChipImporting(false);
|
||||
}
|
||||
const reason = 'reason' in result && typeof result.reason === 'string'
|
||||
? result.reason
|
||||
: 'unknown failure';
|
||||
const details = 'details' in result && result.details != null
|
||||
? formatPickAndImportErrorDetails(result.details)
|
||||
: undefined;
|
||||
setFolderImportError({
|
||||
message: `Open folder failed: ${reason}`,
|
||||
...(details ? { details } : {}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
openNewProject('prototype');
|
||||
|
||||
@@ -42,40 +42,11 @@ import {
|
||||
VIDEO_LENGTHS_SEC,
|
||||
VIDEO_MODELS,
|
||||
} from '../media/models';
|
||||
import { formatPickAndImportFailure } from '../utils/pickAndImportError';
|
||||
import { Icon } from './Icon';
|
||||
import { Skeleton } from './Loading';
|
||||
import { Toast } from './Toast';
|
||||
|
||||
/**
|
||||
* Best-effort flattening of the `details` field that the
|
||||
* pickAndImport main-process handler attaches when the daemon returned
|
||||
* a structured error envelope (PR #974 round-4 mrcfps). Daemon errors
|
||||
* carry `error.message` and sometimes nested `error.details.reason`;
|
||||
* we surface the most operator-actionable string we can find without
|
||||
* over-coupling to any particular error code.
|
||||
*/
|
||||
function formatPickAndImportErrorDetails(details: unknown): string | undefined {
|
||||
if (typeof details === 'string' && details.length > 0) return details;
|
||||
if (details == null || typeof details !== 'object') return undefined;
|
||||
const record = details as Record<string, unknown>;
|
||||
const error = record.error;
|
||||
if (error != null && typeof error === 'object') {
|
||||
const errRecord = error as Record<string, unknown>;
|
||||
const message = errRecord.message;
|
||||
const nestedDetails = errRecord.details;
|
||||
if (typeof message === 'string' && message.length > 0) {
|
||||
if (nestedDetails != null && typeof nestedDetails === 'object') {
|
||||
const nestedReason = (nestedDetails as Record<string, unknown>).reason;
|
||||
if (typeof nestedReason === 'string' && nestedReason.length > 0) {
|
||||
return `${message} (${nestedReason})`;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Snapshot of a curated prompt template, captured at New Project time and
|
||||
// folded into ProjectMetadata.promptTemplate. The user may have edited the
|
||||
// prompt body before clicking Create — that edited copy lives here.
|
||||
@@ -604,16 +575,7 @@ export function NewProjectPanel({
|
||||
// network errors). The pickAndImport handler already pre-shapes
|
||||
// these into a `{ ok: false, reason, details? }` envelope.
|
||||
if ('canceled' in result && result.canceled === true) return;
|
||||
const reason = 'reason' in result && typeof result.reason === 'string'
|
||||
? result.reason
|
||||
: 'unknown failure';
|
||||
const details = 'details' in result && result.details != null
|
||||
? formatPickAndImportErrorDetails(result.details)
|
||||
: undefined;
|
||||
setImportFolderError({
|
||||
message: `Open folder failed: ${reason}`,
|
||||
...(details ? { details } : {}),
|
||||
});
|
||||
setImportFolderError(formatPickAndImportFailure(result));
|
||||
} finally {
|
||||
setImportingFolder(false);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import type { DesktopPickAndImportResult } from '../types/electron';
|
||||
|
||||
/**
|
||||
* Best-effort flattening of the `details` field that the
|
||||
* pickAndImport main-process handler attaches when the daemon returned
|
||||
* a structured error envelope (PR #974 round-4 mrcfps). Daemon errors
|
||||
* carry `error.message` and sometimes nested `error.details.reason`;
|
||||
* we surface the most operator-actionable string we can find without
|
||||
* over-coupling to any particular error code.
|
||||
*/
|
||||
export function formatPickAndImportErrorDetails(details: unknown): string | undefined {
|
||||
if (typeof details === 'string' && details.length > 0) return details;
|
||||
if (details == null || typeof details !== 'object') return undefined;
|
||||
const record = details as Record<string, unknown>;
|
||||
const error = record.error;
|
||||
if (error != null && typeof error === 'object') {
|
||||
const errRecord = error as Record<string, unknown>;
|
||||
const message = errRecord.message;
|
||||
const nestedDetails = errRecord.details;
|
||||
if (typeof message === 'string' && message.length > 0) {
|
||||
if (nestedDetails != null && typeof nestedDetails === 'object') {
|
||||
const nestedReason = (nestedDetails as Record<string, unknown>).reason;
|
||||
if (typeof nestedReason === 'string' && nestedReason.length > 0) {
|
||||
return `${message} (${nestedReason})`;
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function formatPickAndImportFailure(
|
||||
result: DesktopPickAndImportResult,
|
||||
): { message: string; details?: string } {
|
||||
const reason = 'reason' in result && typeof result.reason === 'string'
|
||||
? result.reason
|
||||
: 'unknown failure';
|
||||
const details = 'details' in result && result.details != null
|
||||
? formatPickAndImportErrorDetails(result.details)
|
||||
: undefined;
|
||||
return {
|
||||
message: `Open folder failed: ${reason}`,
|
||||
...(details ? { details } : {}),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user