提交 6a4f5388 authored 作者: Will Chen's avatar Will Chen

Update setup/settings flow for runtime

上级 3074634c
...@@ -8,9 +8,9 @@ import { RuntimeMode } from "@/lib/schemas"; ...@@ -8,9 +8,9 @@ import { RuntimeMode } from "@/lib/schemas";
function formatRuntimeMode(runtimeMode: RuntimeMode | undefined) { function formatRuntimeMode(runtimeMode: RuntimeMode | undefined) {
switch (runtimeMode) { switch (runtimeMode) {
case "web-sandbox": case "web-sandbox":
return "Sandbox"; return "Sandboxed";
case "local-node": case "local-node":
return "Local"; return "Full Access";
default: default:
return runtimeMode; return runtimeMode;
} }
...@@ -33,7 +33,7 @@ export const TitleBar = () => { ...@@ -33,7 +33,7 @@ export const TitleBar = () => {
<div className="pl-24"></div> <div className="pl-24"></div>
<div className="hidden @md:block text-sm font-medium">{displayText}</div> <div className="hidden @md:block text-sm font-medium">{displayText}</div>
<div className="text-sm font-medium pl-4"> <div className="text-sm font-medium pl-4">
{formatRuntimeMode(settings?.runtimeMode)} runtime {formatRuntimeMode(settings?.runtimeMode)} mode
</div> </div>
<div className="flex-1 text-center text-sm font-medium">Dyad</div> <div className="flex-1 text-center text-sm font-medium">Dyad</div>
</div> </div>
......
...@@ -209,7 +209,59 @@ async function executeAppLocalNode({ ...@@ -209,7 +209,59 @@ async function executeAppLocalNode({
}); });
} }
function checkCommandExists(command: string): Promise<string | null> {
return new Promise((resolve) => {
let output = "";
const process = spawn(command, ["--version"], {
shell: true,
stdio: ["ignore", "pipe", "pipe"], // ignore stdin, pipe stdout/stderr
});
process.stdout?.on("data", (data) => {
output += data.toString();
});
process.stderr?.on("data", (data) => {
// Log stderr but don't treat it as a failure unless the exit code is non-zero
console.warn(
`Stderr from "${command} --version": ${data.toString().trim()}`
);
});
process.on("error", (error) => {
console.error(`Error executing command "${command}":`, error.message);
resolve(null); // Command execution failed
});
process.on("close", (code) => {
if (code === 0) {
resolve(output.trim()); // Command succeeded, return trimmed output
} else {
console.error(
`Command "${command} --version" failed with code ${code}`
);
resolve(null); // Command failed
}
});
});
}
export function registerAppHandlers() { export function registerAppHandlers() {
ipcMain.handle(
"nodejs-status",
async (): Promise<{
nodeVersion: string | null;
npmVersion: string | null;
}> => {
// Run checks in parallel
const [nodeVersion, npmVersion] = await Promise.all([
checkCommandExists("node"),
checkCommandExists("npm"),
]);
return { nodeVersion, npmVersion };
}
);
ipcMain.handle( ipcMain.handle(
"get-app-sandbox-config", "get-app-sandbox-config",
async (_, { appId }: { appId: number }): Promise<SandboxConfig> => { async (_, { appId }: { appId: number }): Promise<SandboxConfig> => {
......
...@@ -488,4 +488,21 @@ export class IpcClient { ...@@ -488,4 +488,21 @@ export class IpcClient {
throw error; throw error;
} }
} }
// Check Node.js and npm status
public async getNodejsStatus(): Promise<{
nodeVersion: string | null;
npmVersion: string | null;
}> {
try {
const result = await this.ipcRenderer.invoke("nodejs-status");
return result as {
nodeVersion: string | null;
npmVersion: string | null;
};
} catch (error) {
showError(error);
throw error;
}
}
} }
...@@ -20,7 +20,7 @@ export default function HomePage() { ...@@ -20,7 +20,7 @@ export default function HomePage() {
const search = useSearch({ from: "/" }); const search = useSearch({ from: "/" });
const setSelectedAppId = useSetAtom(selectedAppIdAtom); const setSelectedAppId = useSetAtom(selectedAppIdAtom);
const { refreshApps } = useLoadApps(); const { refreshApps } = useLoadApps();
const { settings, isAnyProviderSetup, updateSettings } = useSettings(); const { settings, isAnyProviderSetup } = useSettings();
const setIsPreviewOpen = useSetAtom(isPreviewOpenAtom); const setIsPreviewOpen = useSetAtom(isPreviewOpenAtom);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const { streamMessage } = useStreamChat(); const { streamMessage } = useStreamChat();
...@@ -35,10 +35,6 @@ export default function HomePage() { ...@@ -35,10 +35,6 @@ export default function HomePage() {
} }
}, [appId, navigate]); }, [appId, navigate]);
const handleSetRuntimeMode = async (mode: RuntimeMode) => {
await updateSettings({ runtimeMode: mode });
};
const handleSubmit = async () => { const handleSubmit = async () => {
if (!inputValue.trim()) return; if (!inputValue.trim()) return;
...@@ -90,7 +86,7 @@ export default function HomePage() { ...@@ -90,7 +86,7 @@ export default function HomePage() {
// Runtime Setup Flow // Runtime Setup Flow
// Render this only if runtimeMode is not set in settings // Render this only if runtimeMode is not set in settings
if (settings?.runtimeMode === "unset") { if (settings?.runtimeMode === "unset") {
return <SetupRuntimeFlow onRuntimeSelected={handleSetRuntimeMode} />; return <SetupRuntimeFlow />;
} }
// Main Home Page Content (Rendered only if runtimeMode is set) // Main Home Page Content (Rendered only if runtimeMode is set)
......
差异被折叠。
...@@ -31,6 +31,7 @@ const validInvokeChannels = [ ...@@ -31,6 +31,7 @@ const validInvokeChannels = [
"get-env-vars", "get-env-vars",
"open-external-url", "open-external-url",
"reset-all", "reset-all",
"nodejs-status",
] as const; ] as const;
// Add valid receive channels // Add valid receive channels
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论