The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Desktop: the native Settings command and shortcut (#63)
mikas4802dfdaa27e
diff --git a/.changeset/quiet-settings-debug.md b/.changeset/quiet-settings-debug.mdnew file mode 100644index 0000000..1286e55--- /dev/null+++ b/.changeset/quiet-settings-debug.md@@ -0,0 +1,6 @@+---+"@openfilm/desktop": patch+"openfilm": patch+---++Open Settings from the native menu with Command-comma on macOS or Control-comma on Windows and Linux, including when no project is open.diff --git a/apps/desktop/shell/bridge.ts b/apps/desktop/shell/bridge.tsindex 95cb175..0e4d041 100644--- a/apps/desktop/shell/bridge.ts+++ b/apps/desktop/shell/bridge.ts@@ -37,6 +37,7 @@ interface Native {setTheme(theme: Theme): void;onFullScreen(listener: Listener<boolean>): Stop;onToggleChat(listener: Listener<void>): Stop;+ onOpenSettings(listener: Listener<void>): Stop;onStudioBrowser(listener: Listener<unknown>): Stop;onFfmpeg(listener: Listener<unknown>): Stop;onUpdate(listener: Listener<unknown>): Stop;@@ -264,6 +265,7 @@ const host: StudioHost = {onSelection: (next) => selection.set(next),onHover: (ref) => hover.set(ref ?? null),onCommand: (listener) => { command = listener; },+ settings: { onOpen: (listener) => native.onOpenSettings(listener) },/* read live: Studio may read the panel before or after the kept layout arrives */panel: {label: 'Chat',diff --git a/apps/desktop/src/main.mjs b/apps/desktop/src/main.mjsindex 01e7f21..5767c7d 100644--- a/apps/desktop/src/main.mjs+++ b/apps/desktop/src/main.mjs@@ -21,7 +21,7 @@ import { startWindowStudio } from './studio.mjs';import { CHAT_MIN, STUDIO_MIN, WINDOW_MIN, placeOnDisplays, readWindowState, writeWindowState } from './window-state.mjs';import { createPagePresentation, preparePage, revealPage } from './page-presentation.mjs';import { closeTabOrWindow, keepWindowOnClose, quitAfterStudio } from './window-lifecycle.mjs';-import { applicationMenu } from './menu.mjs';+import { applicationMenuTemplate } from './menu.mjs';import { registerLocalAgentIpc } from './local-agents-ipc.mjs';import { readPreferences, registerChatIpc } from './chat-ipc.mjs';import { registerSkillsIpc } from './skills-ipc.mjs';@@ -618,11 +618,12 @@ async function start() {ipcMain.handle('desktop:update-state', (event) => (fromPage(event) ? updates?.snapshot() ?? null : null));ipcMain.handle('desktop:update-check', (event) => (fromPage(event) ? updates?.check() ?? null : null));- Menu.setApplicationMenu(applicationMenu({+ Menu.setApplicationMenu(Menu.buildFromTemplate(applicationMenuTemplate({productName: PRODUCT_NAME,packaged: app.isPackaged,toggleChat: () => activeView()?.webContents.send('desktop:toggle-chat'),openProject: () => void openProjectFolder(),+ openSettings: () => { focusWindow(); activeView()?.webContents.send('desktop:open-settings'); },reload: () => activeView()?.webContents.reload(),devTools: () => activeView()?.webContents.toggleDevTools(),tabs: {@@ -642,7 +643,7 @@ async function start() {beta: updates.channel() === 'beta',setBeta: (on) => updates.setChannel(on ? 'beta' : 'stable'),} : null,- }));+ })));win.show();if (needFfmpeg) {diff --git a/apps/desktop/src/menu.mjs b/apps/desktop/src/menu.mjsindex bc14008..e794359 100644--- a/apps/desktop/src/menu.mjs+++ b/apps/desktop/src/menu.mjs@@ -1,7 +1,4 @@-/** The menu bar. Studio's own shortcuts live in its page; these are the window's, its tabs' among them. */-import { Menu } from 'electron';--const mac = process.platform === 'darwin';+/** Pure native menu template, built by Electron in main.mjs. Studio's editing shortcuts stay in its page. *//*** `updates`: the packaged app's (updates.mjs), for "Check for Updates…" (the app menu on macOS, Help on Windows) and@@ -9,11 +6,14 @@ const mac = process.platform === 'darwin';* `tabs`: a new tab (its launcher), the one in front closed, the one closed last opened again, the next or previous,* the nth (9: the last).* @param {{ productName: string, packaged: boolean, toggleChat: () => void, openProject: () => void, reload: () => void,- * devTools: () => void,+ * devTools: () => void, openSettings: () => void,* tabs: { open: () => void, close: () => void, reopen: () => void, step: (by: number) => void, pick: (n: number) => void },* updates?: { check: () => Promise<void>, beta: boolean, setBeta: (on: boolean) => void } | null }} actions*/-export function applicationMenu({ productName, packaged, toggleChat, openProject, reload, devTools, tabs, updates = null }) {+export function applicationMenuTemplate({ productName, packaged, toggleChat, openProject, reload, devTools, openSettings, tabs, updates = null }, platform = process.platform) {+ const mac = platform === 'darwin';+ /** @type {Electron.MenuItemConstructorOptions} */+ const settings = { label: 'Settings…', accelerator: 'CmdOrCtrl+,', click: openSettings };/** @type {Electron.MenuItemConstructorOptions[]} */const updateItems = updates ? [{@@ -34,6 +34,8 @@ export function applicationMenu({ productName, packaged, toggleChat, openProject{ role: 'about' },...updateItems,{ type: 'separator' },+ settings,+ { type: 'separator' },{ role: 'services' },{ type: 'separator' },{ role: 'hide' },@@ -48,6 +50,7 @@ export function applicationMenu({ productName, packaged, toggleChat, openProjectsubmenu: [{ label: 'New Tab', accelerator: 'CmdOrCtrl+T', click: () => tabs.open() },{ label: 'Open Project…', accelerator: 'CmdOrCtrl+O', click: openProject },+ ...(!mac ? [{ type: 'separator' }, settings] : []),{ type: 'separator' },{ label: 'Close Tab', accelerator: 'CmdOrCtrl+W', click: () => tabs.close() },{ label: 'Reopen Closed Tab', accelerator: 'CmdOrCtrl+Shift+T', click: () => tabs.reopen() },@@ -86,5 +89,5 @@ export function applicationMenu({ productName, packaged, toggleChat, openProject},...(!mac && updateItems.length ? [{ role: 'help', submenu: updateItems }] : []),];- return Menu.buildFromTemplate(template);+ return template;}diff --git a/apps/desktop/src/menu.test.mjs b/apps/desktop/src/menu.test.mjsnew file mode 100644index 0000000..7e675e2--- /dev/null+++ b/apps/desktop/src/menu.test.mjs@@ -0,0 +1,50 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { applicationMenuTemplate } from './menu.mjs';++function fixture(platform, packaged = true, updates = null) {+ let opened = 0;+ const noop = () => {};+ const menu = applicationMenuTemplate({+ productName: 'OpenFilm', packaged, toggleChat: noop, openProject: noop,+ reload: noop, devTools: noop, openSettings: () => { opened++; },+ tabs: { open: noop, close: noop, reopen: noop, step: noop, pick: noop },+ updates,+ }, platform);+ return { menu, opened: () => opened };+}+for (const platform of ['darwin', 'win32', 'linux']) {+ for (const packaged of [true, false]) {+ test(`Settings is discoverable and has its native accelerator on ${platform}, packaged=${packaged}`, () => {+ const f = fixture(platform, packaged);+ const parent = f.menu.find((item) => item.label === (platform === 'darwin' ? 'OpenFilm' : 'File'));+ const settings = parent.submenu.find((item) => item.label === 'Settings…');+ assert.equal(settings.accelerator, 'CmdOrCtrl+,');+ assert.notEqual(settings.enabled, false);+ settings.click();+ assert.equal(f.opened(), 1);+ assert.equal(f.menu.flatMap((item) => Array.isArray(item.submenu) ? item.submenu : []).filter((item) => item.label === 'Settings…').length, 1);+ });+ }+}++for (const updates of [null, { check: async () => {}, beta: false, setBeta: () => {} }]) {+ test(`macOS puts updates before Settings and Services after it, updates=${!!updates}`, () => {+ const { menu } = fixture('darwin', true, updates);+ const items = menu.find((item) => item.label === 'OpenFilm').submenu;+ const settings = items.findIndex((item) => item.label === 'Settings…');+ const services = items.findIndex((item) => item.role === 'services');+ assert.equal(items[0].role, 'about');+ assert.equal(items[settings - 1].type, 'separator');+ assert.equal(items[settings + 1].type, 'separator');+ assert.equal(services, settings + 2);+ if (updates) {+ const check = items.findIndex((item) => item.label === 'Check for Updates…');+ const channel = items.findIndex((item) => item.type === 'checkbox');+ assert.ok(check > 0 && check < settings);+ assert.ok(channel > check && channel < settings);+ } else {+ assert.equal(settings, 2);+ }+ });+}diff --git a/apps/desktop/src/preload.cjs b/apps/desktop/src/preload.cjsindex d5ef43a..ef64c1f 100644--- a/apps/desktop/src/preload.cjs+++ b/apps/desktop/src/preload.cjs@@ -118,6 +118,8 @@ contextBridge.exposeInMainWorld('openfilmNative', {onFullScreen: on('desktop:full-screen'),/* View → Chat in the app's menu */onToggleChat: on('desktop:toggle-chat'),+ /* Native Settings menu and Cmd/Ctrl+,; no renderer can invoke a privileged action here. */+ onOpenSettings: on('desktop:open-settings'),onStudioBrowser: on('desktop:studio-browser'),onFfmpeg: on('desktop:ffmpeg'),onUpdate: on('desktop:update'),diff --git a/packages/openfilm/studio/ui/src/components/Launcher.tsx b/packages/openfilm/studio/ui/src/components/Launcher.tsxindex abc344e..67b0761 100644--- a/packages/openfilm/studio/ui/src/components/Launcher.tsx+++ b/packages/openfilm/studio/ui/src/components/Launcher.tsx@@ -3,16 +3,16 @@* it) and the projects window over it, as `+` opens it, only with nothing behind to close it to. The project picked* opens in its tab.*/-import React from 'react';import { BrandLogo } from './BrandLogo';import { ProjectsPopover } from './ProjectsLibrary';-import { SettingsModal, type SettingsSection } from './settings/SettingsModal';+import { SettingsModal } from './settings/SettingsModal';+import { useSettings } from './settings/use-settings';import { Tooltip } from './Tooltip';import { useT } from '@/i18n';export function Launcher({ onOpen }: { onOpen: (projectId: string) => void }) {const t = useT();- const [settings, setSettings] = React.useState<SettingsSection | null>(null);+ const [settings, setSettings] = useSettings();return (<div className="workspace-shell flex flex-col bg-[var(--dock-shell)]"><div data-titlebar className="relative flex h-8 min-w-0 shrink-0 items-center gap-1 px-[6px]">diff --git a/packages/openfilm/studio/ui/src/components/ProjectView.tsx b/packages/openfilm/studio/ui/src/components/ProjectView.tsxindex ba4ec7c..1a13339 100644--- a/packages/openfilm/studio/ui/src/components/ProjectView.tsx+++ b/packages/openfilm/studio/ui/src/components/ProjectView.tsx@@ -48,7 +48,8 @@ import { canvasFor, fitToCanvas } from '@/lib/canvas-fit';import { factsOfProbe, mediaListingOf, resourceKindOf, srcHitsAsset, warmProjectMedia, type MediaListing, type MediaProxy, type MediaResult, type MediaSources, type WorkspaceResource } from '@/lib/workspace-resources';import { BrandLoadingScreen } from './BrandLoadingScreen';import { BrandLogo } from './BrandLogo';-import { SettingsModal, type SettingsSection } from './settings/SettingsModal';+import { SettingsModal } from './settings/SettingsModal';+import { useSettings } from './settings/use-settings';import { DesktopDialog } from './DesktopDialog';import type { ContextMenuEntry } from './ContextMenu';import { studioHost, useHostPanel, type CommunityItem, type HostPanel, type StageBox, type StudioCommand, type StudioRef } from '../lib/host';@@ -2439,7 +2440,7 @@ export function ProjectView({ projectId, onProject, onLeave }: {/* the examples over the film, opened from the app's chat *//* the Community over the film: closed, open on its list (true), or on one skill's or example's page */const [examplesOpen, setExamplesOpen] = React.useState<boolean | CommunityItem>(false);- const [settingsOpen, setSettingsOpen] = React.useState<SettingsSection | null>(null);+ const [settingsOpen, setSettingsOpen] = useSettings();/* making subtitles: what went wrong, shown on the CC button; with no service to transcribe, it opens Providers */const [subtitleProblem, setSubtitleProblem] = React.useState<{ text: string; connect: boolean } | null>(null);const makeSubtitles = React.useCallback(() => {diff --git a/packages/openfilm/studio/ui/src/components/settings/SettingsModal.tsx b/packages/openfilm/studio/ui/src/components/settings/SettingsModal.tsxindex b6a8efb..e4f9fe1 100644--- a/packages/openfilm/studio/ui/src/components/settings/SettingsModal.tsx+++ b/packages/openfilm/studio/ui/src/components/settings/SettingsModal.tsx@@ -488,6 +488,7 @@ function ShortcutsSection() {};const groups: Array<{ title: string; items: Array<{ label: string; keys: string[] }> }> = [+ ...(studioHost?.settings ? [{ title: t('settings.sections.general'), items: [{ label: t('settings.title'), keys: [k(',', { mod: true })] }] }] : []),...SHORTCUTS.map((group) => ({title: t(`settings.shortcuts.${group.group}`),items: group.rows.map((row) => ({ label: t(`settings.shortcuts.${row.label}`), keys: row.keys.map(keyText) })),diff --git a/packages/openfilm/studio/ui/src/components/settings/use-settings.ts b/packages/openfilm/studio/ui/src/components/settings/use-settings.tsnew file mode 100644index 0000000..59a6cb9--- /dev/null+++ b/packages/openfilm/studio/ui/src/components/settings/use-settings.ts@@ -0,0 +1,10 @@+import React from 'react';+import { studioHost } from '../../lib/host';+import type { SettingsSection } from './SettingsModal';++/** Both editor and launcher follow the native Settings command; each page has its own dialog. */+export function useSettings() {+ const [section, setSection] = React.useState<SettingsSection | null>(null);+ React.useEffect(() => studioHost?.settings?.onOpen(() => setSection('general')), []);+ return [section, setSection] as const;+}diff --git a/packages/openfilm/studio/ui/src/lib/host.ts b/packages/openfilm/studio/ui/src/lib/host.tsindex 468e123..5957af7 100644--- a/packages/openfilm/studio/ui/src/lib/host.ts+++ b/packages/openfilm/studio/ui/src/lib/host.ts@@ -15,6 +15,8 @@ export interface HostDeveloper { logs: boolean; changes: boolean }export interface StudioHost {/** the version of this interface the app speaks */version: 1;+ /** The native Settings menu asks the current page to open General, including the launcher. */+ settings?: { onOpen: (listener: () => void) => () => void };/** the app's name, for the person */name?: string;/**