Keeping last project open

This commit is contained in:
2025-10-15 11:39:22 +02:00
parent d3a8396033
commit 1dc9d1114e
5 changed files with 71 additions and 13 deletions

View File

@ -21,6 +21,7 @@
templateRegistry,
type CsoundTemplate,
} from "./lib/templates/template-registry";
import { loadLastProjectId } from "./lib/project-system/persistence";
import { createAppContext, setAppContext } from "./lib/contexts/app-context";
import type { ProjectMode } from "./lib/project-system/types";
import {
@ -53,20 +54,43 @@
onMount(async () => {
await projectManager.init();
const result = await projectManager.getAllProjects();
if (result.success && result.data.length === 0) {
const classicTemplate = templateRegistry.getById("classic");
if (classicTemplate) {
await projectManager.createProject({
title: "Welcome",
author: "System",
content: classicTemplate.content,
tags: [],
mode: classicTemplate.mode,
});
const lastProjectId = loadLastProjectId();
let projectToLoad: CsoundProject | null = null;
if (lastProjectId) {
const result = await projectManager.getProject(lastProjectId);
if (result.success) {
projectToLoad = result.data;
}
}
if (!projectToLoad) {
const allProjectsResult = await projectManager.getAllProjects();
if (allProjectsResult.success) {
if (allProjectsResult.data.length > 0) {
projectToLoad = allProjectsResult.data[0];
} else {
const classicTemplate = templateRegistry.getById("classic");
if (classicTemplate) {
const createResult = await projectManager.createProject({
title: "Welcome",
author: "System",
content: classicTemplate.content,
tags: [],
mode: classicTemplate.mode,
});
if (createResult.success) {
projectToLoad = createResult.data;
}
}
}
}
}
if (projectToLoad) {
projectEditor.loadProject(projectToLoad);
}
logsUnsubscribe = csoundDerived.logs.subscribe((logs) => {
interpreterLogs = logs;
});
@ -344,6 +368,7 @@
onExecute={handleExecute}
logs={interpreterLogs}
{editorSettings}
mode={projectEditor.currentProject?.mode || 'composition'}
/>
</div>