The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Studio: a project shown in the remembered subtitle look keeps it, so exports burn it (#287)
HEOJUNFOd71b72eda800
diff --git a/.changeset/subtitle-style-inherited.md b/.changeset/subtitle-style-inherited.mdnew file mode 100644index 0000000..ce2284a--- /dev/null+++ b/.changeset/subtitle-style-inherited.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Studio: a new project starts in the subtitle look used last, written to it as it is made, so burned-in subtitles match what Studio shows; an opened project shows its own look or the default, as its exports dodiff --git a/packages/openfilm/studio/server/server.mjs b/packages/openfilm/studio/server/server.mjsindex 3941dbc..8ca2784 100644--- a/packages/openfilm/studio/server/server.mjs+++ b/packages/openfilm/studio/server/server.mjs@@ -54,7 +54,7 @@ import { FILM_FILE, clipKind, isPage } from '../../src/film-doc.mjs';import { moveToTrash } from './trash.mjs';import { listSkills, removeSkill, setSkillCover, setSkillInstalled, setSkillOn, skillOrigins, skillsInstalled, skillsOff } from '../../src/skills.mjs';import { providersRoute } from './providers/index.mjs';-import { captionRoutes } from './captions.mjs';+import { captionRoutes, writeSubtitleStyle } from './captions.mjs';import { projectSettingsRoute } from './project-settings.mjs';import { markersRoute } from './markers.mjs';import { transitionPageRoutes } from './transition-pages.mjs';@@ -521,8 +521,15 @@ export async function startStudio({ port = 4747, key, openBrowser = systemBrowseif (req.method === 'GET') return json(res, 200, { projects: (await listProjects()).map((p) => (agentIn(p.path) ? { ...p, working: true } : p)) });/* `create` false: only a folder holding a film opens (the editor asks before starting one in a folder) */if (req.method === 'POST') {- const body = /** @type {{ path?: string, name?: string, create?: boolean }} */ (await readJson(req));- return json(res, 200, { project: body.path ? await openProject(body.path, { create: body.create !== false }) : await createProject(body.name) });+ const body = /** @type {{ path?: string, name?: string, create?: boolean, subtitleStyle?: unknown }} */ (await readJson(req));+ if (body.path) return json(res, 200, { project: await openProject(body.path, { create: body.create !== false }) });+ const project = await createProject(body.name);+ /* a new film starts in the subtitle look this person used last (Studio remembers it): written before its first+ version, so the project, its exports and Studio agree. An opened project keeps its own, or the default (#286). */+ if (body.subtitleStyle && typeof body.subtitleStyle === 'object') {+ await writeSubtitleStyle(project.path, body.subtitleStyle).catch(() => { /* the film still opens, in the default look */ });+ }+ return json(res, 200, { project });}}/* a film from GitHub (fetch-repo.mjs): POST { url } `projects/fetch` starts it → { job }; GET `projects/fetch/:id`diff --git a/packages/openfilm/studio/server/server.test.mjs b/packages/openfilm/studio/server/server.test.mjsindex f5a0c5c..8b126ee 100644--- a/packages/openfilm/studio/server/server.test.mjs+++ b/packages/openfilm/studio/server/server.test.mjs@@ -1026,3 +1026,17 @@ test('a project deleted: every page showing it is told it is gone; several deletconst { projects } = await (await api('/api/projects')).json();assert.deepEqual(projects.filter((p) => made.some((m) => m.id === p.id)), []);});++test('a new project starts in the subtitle look Studio sends with it, written before anything else; an opened one gets none (#286)', async () => {+ const look = { on: true, fill: '#ffd400', align: 'left' };+ const { project } = await (await api('/api/projects', { method: 'POST', body: { name: 'Remembered look', subtitleStyle: look } })).json();+ const kept = JSON.parse(readFileSync(join(project.path, '.film', 'subtitles.json'), 'utf8'));+ assert.equal(kept.fill, '#ffd400');+ assert.equal(kept.align, 'left');+ /* no look sent, or a folder opened as it is: no file, so it is shown and exported in the default look */+ const { project: plain } = await (await api('/api/projects', { method: 'POST', body: { name: 'No look' } })).json();+ assert.equal(existsSync(join(plain.path, '.film', 'subtitles.json')), false);+ const folder = join(scratch, 'Opened with a look');+ const { project: opened } = await (await api('/api/projects', { method: 'POST', body: { path: folder, subtitleStyle: look } })).json();+ assert.equal(existsSync(join(opened.path, '.film', 'subtitles.json')), false);+});diff --git a/packages/openfilm/studio/ui/src/api.ts b/packages/openfilm/studio/ui/src/api.tsindex 0508d87..8404ed3 100644--- a/packages/openfilm/studio/ui/src/api.ts+++ b/packages/openfilm/studio/ui/src/api.ts@@ -3,6 +3,7 @@* cookie `/open` set; writes are refused from any other origin.*/import type { ExportJob } from '@/lib/export-jobs';+import type { SubtitleStyle } from '@/lib/subtitles';import { studioHost } from '@/lib/host';import { watchStudioVersion } from '@/lib/studio-version';@@ -136,7 +137,7 @@ export const api = {/** the system's folder dialog, opened by Studio (a page in a browser cannot learn a path): the folder, or null whencancelled; throws (501) where this system has none */pickFolder: (title: string, at?: string) => call<{ path: string | null }>('pick-folder', { method: 'POST', json: { title, ...(at ? { at } : {}) } }).then((r) => r.path),- newProject: (name?: string) => call<{ project: Project }>('projects', { method: 'POST', json: { name } }).then((r) => r.project),+ newProject: (name?: string, subtitleStyle?: SubtitleStyle) => call<{ project: Project }>('projects', { method: 'POST', json: { name, subtitleStyle } }).then((r) => r.project),/** open a folder (its full path) as a project: made one when it is not yet */openFolder: (path: string) => call<{ project: Project }>('projects', { method: 'POST', json: { path } }).then((r) => r.project),rename: (id: string, name: string) => call<{ project: Project }>(p(id), { method: 'PATCH', json: { name } }).then((r) => {diff --git a/packages/openfilm/studio/ui/src/components/ProjectsLibrary.tsx b/packages/openfilm/studio/ui/src/components/ProjectsLibrary.tsxindex ef5713b..bafb710 100644--- a/packages/openfilm/studio/ui/src/components/ProjectsLibrary.tsx+++ b/packages/openfilm/studio/ui/src/components/ProjectsLibrary.tsx@@ -25,6 +25,7 @@ import { stillThere } from '@/lib/project-delete';import { studioHost } from '@/lib/host';import { SourceError, sourcesApi } from '@/lib/project-sources';import { LIST_WAIT_MS, within } from '@/lib/projects-page';+import { readLastSubtitleStyle } from '@/lib/subtitles';import { ConfirmDialog } from './ConfirmDialog';import { ProjectsView, type LibraryProject } from './ProjectsView';import { FolderBrowserDialog, GitHubDialog } from './ProjectSources';@@ -336,7 +337,7 @@ export function ProjectsPopover({async function newProject(folderId: string | null) {setBusy('creating');try {- const project = await newProjectIn(folderId, { create: () => api.newProject(t('project.untitled')), move: folderApi.move });+ const project = await newProjectIn(folderId, { create: () => api.newProject(t('project.untitled'), readLastSubtitleStyle() ?? undefined), move: folderApi.move });go(project.id, 'creating');} catch {setBusy(null);diff --git a/packages/openfilm/studio/ui/src/lib/subtitles.ts b/packages/openfilm/studio/ui/src/lib/subtitles.tsindex 65573b5..2e95b32 100644--- a/packages/openfilm/studio/ui/src/lib/subtitles.ts+++ b/packages/openfilm/studio/ui/src/lib/subtitles.ts@@ -130,8 +130,8 @@ export function joinColor(hex: string, alpha: number): string {/*** The style is kept per project (in the project folder, see useSubtitleStyle); this browser also remembers the look- * last used, the starting point for a project whose style was never changed: someone who set up large yellow- * subtitles wants them in the next film too.+ * last used, the look a new project starts in (written to it as it is made, see api.newProject): someone who set up+ * large yellow subtitles wants them in the next film too.*/const STORE_KEY = 'openfilm.subtitles';diff --git a/packages/openfilm/studio/ui/src/lib/use-subtitle-style.ts b/packages/openfilm/studio/ui/src/lib/use-subtitle-style.tsindex f68bdfb..457cc52 100644--- a/packages/openfilm/studio/ui/src/lib/use-subtitle-style.ts+++ b/packages/openfilm/studio/ui/src/lib/use-subtitle-style.ts@@ -3,8 +3,9 @@* 500 ms after the last change. It is the person's look of this film, kept with the project and used by its exports,* and not in film.html, so an agent rewriting the film never resets it.*- * A project whose style was never changed starts from the look this person used last (this browser remembers it,- * see readLastSubtitleStyle), else the default; nothing is written for it until the person changes something. A+ * A project with no style of its own shows the default, the look its exports burn; nothing is written for it until+ * the person changes something. A new project starts in the look this person used last instead: Studio writes it to+ * the project as the project is made (see readLastSubtitleStyle and api.newProject), so it is the project's own. A* version restored (the project's `{ type: 'history', moved }` event) brings its own: read again.*/import * as React from 'react';@@ -14,7 +15,6 @@ import { historyMoved } from './project-history';import {fetchSubtitleStyle,- readLastSubtitleStyle,saveSubtitleStyle,SUBTITLE_DEFAULT,writeLastSubtitleStyle,@@ -24,10 +24,8 @@ import {/** Dragging a color slider makes dozens of values: one write for all of them. */const SAVE_DEBOUNCE_MS = 500;-const startingStyle = (): SubtitleStyle => readLastSubtitleStyle() ?? SUBTITLE_DEFAULT;-export function useSubtitleStyle(projectId: string): [SubtitleStyle, React.Dispatch<React.SetStateAction<SubtitleStyle>>] {- const [style, setStyle] = React.useState<SubtitleStyle>(startingStyle);+ const [style, setStyle] = React.useState<SubtitleStyle>(SUBTITLE_DEFAULT);/* the JSON last known to match the project's file (null: not loaded yet; '': unknown, the next change is written) */const saved = React.useRef<string | null>(null);const styleRef = React.useRef(style);@@ -37,7 +35,7 @@ export function useSubtitleStyle(projectId: string): [SubtitleStyle, React.DispaReact.useEffect(() => {saved.current = null;- const start = startingStyle();+ const start = SUBTITLE_DEFAULT;const startJson = JSON.stringify(start);setStyle(start);const ask = new AbortController();