Skip to content

🎥 Make videos programmatically with React

@remotion/studio: Hide unavailable settings in read-only Studio

Jonny Burgerf52e9c6c573c
diff --git a/packages/studio/src/components/KeyboardShortcutsSettings.tsx b/packages/studio/src/components/KeyboardShortcutsSettings.tsx
index 6030a88899..1672dde800 100644
--- a/packages/studio/src/components/KeyboardShortcutsSettings.tsx
+++ b/packages/studio/src/components/KeyboardShortcutsSettings.tsx
@@ -5,8 +5,15 @@ import type {
StudioKeyboardShortcutAction,
StudioKeyboardShortcuts,
} from '@remotion/studio-shared';
-import React, {useCallback, useEffect, useMemo, useState} from 'react';
+import React, {
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+} from 'react';
import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
import {
BLACK_ALPHA_60,
BORDER_WHITE_ALPHA_12,
@@ -14,6 +21,7 @@ import {
LIGHT_TEXT,
WHITE,
} from '../helpers/colors';
+import {canEditStudioConfig} from '../helpers/settings-tab-availability';
import {getStudioAskAIEnabled} from '../helpers/studio-runtime-config';
import {CaretDown} from '../icons/caret';
import {Checkbox} from './Checkbox';
@@ -177,6 +185,12 @@ const ShortcutChords: React.FC<{
export const KeyboardShortcutsSettings: React.FC = () => {
const {error: settingsError, revision, studioRuntimeConfig} = useSettings();
const isBrowserStudio = getBrowserStudioOperations() !== null;
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const canEdit = canEditStudioConfig({
+ isBrowserStudio,
+ previewServerConnected: previewServerState.type === 'connected',
+ readOnlyStudio: window.remotion_isReadOnlyStudio,
+ });
const [enabled, setEnabled] = useState(true);
const [configuredShortcuts, setConfiguredShortcuts] =
useState<StudioKeyboardShortcuts>({});
@@ -247,7 +261,7 @@ export const KeyboardShortcutsSettings: React.FC = () => {
const ready = studioRuntimeConfig !== null && syncedRevision === revision;
useAutoSaveConfig({
- enabled: ready && !isBrowserStudio,
+ enabled: ready && canEdit,
onError: setError,
ready,
syncRevision: syncedRevision,
@@ -260,7 +274,7 @@ export const KeyboardShortcutsSettings: React.FC = () => {
return (
<div style={container}>
- {isBrowserStudio ? null : (
+ {canEdit ? (
<>
<p style={dividerLabel}>General</p>
<label style={optionRow}>
@@ -274,7 +288,7 @@ export const KeyboardShortcutsSettings: React.FC = () => {
</div>
</label>
</>
- )}
+ ) : null}
{visibleShortcutGroups.map((group, groupIndex) => (
<div key={group.name}>
<p style={shortcutSectionTitle}>{group.name}</p>
@@ -376,7 +390,7 @@ export const KeyboardShortcutsSettings: React.FC = () => {
}
>
<span style={actionName}>{shortcut.action}</span>
- {shortcut.actionId === null || isBrowserStudio ? (
+ {shortcut.actionId === null || !canEdit ? (
<>
<span style={shortcutCell}>
<ShortcutChords values={shortcutValues} />
diff --git a/packages/studio/src/components/Modals.tsx b/packages/studio/src/components/Modals.tsx
index df58949441..cd49948c95 100644
--- a/packages/studio/src/components/Modals.tsx
+++ b/packages/studio/src/components/Modals.tsx
@@ -170,11 +170,7 @@ export const Modals: React.FC<{
{modalContextType && modalContextType.type === 'input-props-override' && (
<OverrideInputPropsModal />
)}
- {modalContextType &&
- modalContextType.type === 'settings' &&
- (!isBrowserStudio ||
- modalContextType.initialTab === 'packages' ||
- modalContextType.initialTab === 'shortcuts') ? (
+ {modalContextType && modalContextType.type === 'settings' ? (
<SettingsModal
key={`${modalContextType.initialTab}-${modalContextType.initialPublicLicenseKey}`}
initialTab={modalContextType.initialTab}
diff --git a/packages/studio/src/components/ModelsSettings.tsx b/packages/studio/src/components/ModelsSettings.tsx
index 89fdd35d42..4f3dfc64e5 100644
--- a/packages/studio/src/components/ModelsSettings.tsx
+++ b/packages/studio/src/components/ModelsSettings.tsx
@@ -1,6 +1,9 @@
-import React, {Suspense, useCallback, useState} from 'react';
+import React, {Suspense, useCallback, useContext, useState} from 'react';
+import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
import {BLUE, LIGHT_TEXT, WARNING_COLOR, WHITE} from '../helpers/colors';
import {TRANSFORMERS_PACKAGE} from '../helpers/optional-package-dependencies';
+import {canInstallPackagesInStudio} from '../helpers/settings-tab-availability';
import {Button} from './Button';
import {sectionHeader} from './InspectorPanel/styles';
import {
@@ -95,10 +98,11 @@ type InstallState =
const OptionalModelPackage: React.FC<{
readonly children: React.ReactNode;
+ readonly canInstall: boolean;
readonly label: string;
readonly packageName: string;
readonly style: React.CSSProperties;
-}> = ({children, label, packageName, style}) => {
+}> = ({canInstall, children, label, packageName, style}) => {
const installed = useOptionalPackageInstalled(packageName);
const [installState, setInstallState] = useState<InstallState>({
type: 'idle',
@@ -121,7 +125,7 @@ const OptionalModelPackage: React.FC<{
<h3 style={title}>{label}</h3>
<p style={packageNameStyle}>{packageName}</p>
</div>
- {installed ? null : (
+ {installed || !canInstall ? null : (
<Button
disabled={installState.type === 'installing'}
onClick={install}
@@ -139,8 +143,9 @@ const OptionalModelPackage: React.FC<{
) : (
<>
<p style={missingDescription}>
- Install the package and {TRANSFORMERS_PACKAGE} to download and
- manage its models.
+ {canInstall
+ ? `Install the package and ${TRANSFORMERS_PACKAGE} to download and manage its models.`
+ : 'Reconnect the Studio server to install this package and manage its models.'}
</p>
{installState.type === 'error' ? (
<p style={errorStyle}>{installState.message}</p>
@@ -152,6 +157,13 @@ const OptionalModelPackage: React.FC<{
};
export const ModelsSettings: React.FC = () => {
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const canInstall = canInstallPackagesInStudio({
+ isBrowserStudio: getBrowserStudioOperations() !== null,
+ previewServerConnected: previewServerState.type === 'connected',
+ readOnlyStudio: window.remotion_isReadOnlyStudio,
+ });
+
return (
<div style={container}>
<p style={overview}>
@@ -159,6 +171,7 @@ export const ModelsSettings: React.FC = () => {
browser cache here.
</p>
<OptionalModelPackage
+ canInstall={canInstall}
label="Transcription"
packageName={WHISPER_WEBGPU_PACKAGE}
style={section}
@@ -166,6 +179,7 @@ export const ModelsSettings: React.FC = () => {
<LazyWhisperModels description={null} indent={false} visible />
</OptionalModelPackage>
<OptionalModelPackage
+ canInstall={canInstall}
label="Video matting"
packageName={VIDEO_MATTING_PACKAGE}
style={lastSection}
diff --git a/packages/studio/src/components/RenderModal/WebRenderModal.tsx b/packages/studio/src/components/RenderModal/WebRenderModal.tsx
index d19b58bc8e..9db1e89b55 100644
--- a/packages/studio/src/components/RenderModal/WebRenderModal.tsx
+++ b/packages/studio/src/components/RenderModal/WebRenderModal.tsx
@@ -18,6 +18,8 @@ import {
import {useCallback, useContext, useMemo, useState} from 'react';
import {ShortcutHint} from '../../error-overlay/remotion-overlay/ShortcutHint';
import {getBrowserStudioOperations} from '../../helpers/browser-studio-operations';
+import {StudioServerConnectionCtx} from '../../helpers/client-id';
+import {canEditStudioConfig} from '../../helpers/settings-tab-availability';
import {AudioIcon} from '../../icons/audio';
import {CertificateIcon} from '../../icons/certificate';
import {FileIcon} from '../../icons/file';
@@ -189,6 +191,7 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({
const {setSelectedModal} = useContext(SetSelectedModalContext);
const {setSidebarCollapsedState} = useContext(SidebarContext);
const {addClientStillJob, addClientVideoJob} = useContext(RenderQueueContext);
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
if (!context) {
throw new Error(
'Should not be able to render without resolving comp first',
@@ -222,6 +225,11 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({
);
const [tab, setTab] = useState<TabType>('general');
const isBrowserStudio = getBrowserStudioOperations() !== null;
+ const canEditConfig = canEditStudioConfig({
+ isBrowserStudio,
+ previewServerConnected: previewServerState.type === 'connected',
+ readOnlyStudio: window.remotion_isReadOnlyStudio,
+ });
const [imageFormat, setImageFormat] = useState<RenderStillOnWebImageFormat>(
() => initialStillImageFormat ?? 'png',
);
@@ -712,7 +720,7 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({
>
Other
</VerticalTab>
- {isBrowserStudio ? null : (
+ {canEditConfig ? (
<VerticalTab
style={horizontalTab}
selected={false}
@@ -731,7 +739,7 @@ const WebRenderModal: React.FC<WebRenderModalProps> = ({
>
License
</VerticalTab>
- )}
+ ) : null}
</div>
<div style={optionsPanel} className={VERTICAL_SCROLLBAR_CLASSNAME}>
{tab === 'general' ? (
diff --git a/packages/studio/src/components/SettingsButton.tsx b/packages/studio/src/components/SettingsButton.tsx
index 256a16652f..ade26a99b6 100644
--- a/packages/studio/src/components/SettingsButton.tsx
+++ b/packages/studio/src/components/SettingsButton.tsx
@@ -1,6 +1,8 @@
import React, {useCallback, useContext} from 'react';
import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
import {WARNING_COLOR, WHITE_ALPHA_80} from '../helpers/colors';
+import {canEditStudioConfig} from '../helpers/settings-tab-availability';
import {GearIcon} from '../icons/gear';
import {SetSelectedModalContext} from '../state/modals';
import {ActionTooltip} from './ActionTooltip';
@@ -12,6 +14,7 @@ export const SettingsButton: React.FC<{
readonly showUpdates: boolean;
}> = ({showUpdates}) => {
const {setSelectedModal} = useContext(SetSelectedModalContext);
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
const {info, knownBugs} = useUpdateStatus();
const updateAvailable =
showUpdates &&
@@ -19,19 +22,25 @@ export const SettingsButton: React.FC<{
const hasBugfixesAvailable =
showUpdates &&
Boolean(info?.updateAvailable && knownBugs && knownBugs.length > 0);
+ const isBrowserStudio = getBrowserStudioOperations() !== null;
+ const canEditConfig = canEditStudioConfig({
+ isBrowserStudio,
+ previewServerConnected: previewServerState.type === 'connected',
+ readOnlyStudio: window.remotion_isReadOnlyStudio,
+ });
const openModal = useCallback(() => {
setSelectedModal({
type: 'settings',
initialTab: updateAvailable
? 'updates'
- : getBrowserStudioOperations() === null
+ : canEditConfig
? 'studio'
: 'shortcuts',
initialPublicLicenseKey:
window.remotion_renderDefaults?.publicLicenseKey ?? null,
});
- }, [setSelectedModal, updateAvailable]);
+ }, [canEditConfig, setSelectedModal, updateAvailable]);
const renderGearIcon: RenderInlineAction = useCallback((color) => {
return <GearIcon color={color} width={16} height={16} />;
diff --git a/packages/studio/src/components/SettingsModal.tsx b/packages/studio/src/components/SettingsModal.tsx
index 4ebc1cd1ae..45950200c5 100644
--- a/packages/studio/src/components/SettingsModal.tsx
+++ b/packages/studio/src/components/SettingsModal.tsx
@@ -3,14 +3,18 @@ import React, {
useContext,
useEffect,
useLayoutEffect,
+ useMemo,
useState,
} from 'react';
-import {
- canInstallPackages,
- getBrowserStudioOperations,
-} from '../helpers/browser-studio-operations';
+import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
import {canShowUpdates} from '../helpers/can-show-updates';
import {StudioServerConnectionCtx} from '../helpers/client-id';
+import {
+ canEditStudioConfig,
+ getAvailableSettingsTabs,
+ getSafeSettingsTab,
+ type SettingsTab,
+} from '../helpers/settings-tab-availability';
import {AppsIcon} from '../icons/apps';
import {CloudDownloadIcon} from '../icons/cloud-download';
import {KeyboardIcon} from '../icons/keyboard';
@@ -47,17 +51,6 @@ import {VerticalTab} from './Tabs/vertical';
import {UpdatesSettings} from './UpdatesSettings';
import {useUpdateStatus} from './UpdateStatusContext';
-type SettingsTab =
- | 'apps'
- | 'rendering'
- | 'studio'
- | 'packages'
- | 'models'
- | 'shortcuts'
- | 'skills'
- | 'license'
- | 'updates';
-
const hiddenPanel: React.CSSProperties = {
display: 'none',
};
@@ -113,10 +106,24 @@ export const SettingsModal: React.FC<{
window.remotion_packageManager === 'unknown'
? null
: window.remotion_packageManager;
- const showPackages =
- canInstallPackages() && (isBrowserStudio || packageManager !== null);
- const safeInitialTab =
- initialTab === 'updates' && !showUpdates ? 'shortcuts' : initialTab;
+ const previewServerConnected = previewServerState.type === 'connected';
+ const canEditConfig = canEditStudioConfig({
+ isBrowserStudio,
+ previewServerConnected,
+ readOnlyStudio: window.remotion_isReadOnlyStudio,
+ });
+ const availableTabs = useMemo(
+ () =>
+ getAvailableSettingsTabs({
+ isBrowserStudio,
+ packageManagerAvailable: packageManager !== null,
+ previewServerConnected,
+ readOnlyStudio: window.remotion_isReadOnlyStudio,
+ showUpdates,
+ }),
+ [isBrowserStudio, packageManager, previewServerConnected, showUpdates],
+ );
+ const safeInitialTab = getSafeSettingsTab(initialTab, availableTabs);
const [tab, setTab] = useState<SettingsTab>(safeInitialTab);
const [openedTabs, setOpenedTabs] = useState<SettingsTab[]>([safeInitialTab]);
const [packagesFooterContainer, setPackagesFooterContainer] =
@@ -136,10 +143,11 @@ export const SettingsModal: React.FC<{
});
}, []);
useLayoutEffect(() => {
- if (!showUpdates && tab === 'updates') {
- selectTab('shortcuts');
+ const safeTab = getSafeSettingsTab(tab, availableTabs);
+ if (safeTab !== tab) {
+ selectTab(safeTab);
}
- }, [selectTab, showUpdates, tab]);
+ }, [availableTabs, selectTab, tab]);
useEffect(() => {
setPublicLicenseKey(initialPublicLicenseKey);
}, [initialPublicLicenseKey, setPublicLicenseKey]);
@@ -150,7 +158,7 @@ export const SettingsModal: React.FC<{
<ModalHeader title="Settings" onClose={dismiss} />
<div style={horizontalLayout}>
<div style={settingsLeftSidebar}>
- {isBrowserStudio ? null : (
+ {availableTabs.includes('studio') ? (
<VerticalTab
style={horizontalTab}
selected={tab === 'studio'}
@@ -163,8 +171,8 @@ export const SettingsModal: React.FC<{
>
Studio
</VerticalTab>
- )}
- {isBrowserStudio ? null : (
+ ) : null}
+ {availableTabs.includes('rendering') ? (
<VerticalTab
style={horizontalTab}
selected={tab === 'rendering'}
@@ -177,7 +185,7 @@ export const SettingsModal: React.FC<{
>
Defaults
</VerticalTab>
- )}
+ ) : null}
<VerticalTab
style={horizontalTab}
selected={tab === 'shortcuts'}
@@ -190,7 +198,7 @@ export const SettingsModal: React.FC<{
>
Shortcuts
</VerticalTab>
- {showPackages ? (
+ {availableTabs.includes('packages') ? (
<VerticalTab
style={horizontalTab}
selected={tab === 'packages'}
@@ -204,7 +212,7 @@ export const SettingsModal: React.FC<{
Packages
</VerticalTab>
) : null}
- {isBrowserStudio ? null : (
+ {availableTabs.includes('skills') ? (
<VerticalTab
style={horizontalTab}
selected={tab === 'skills'}
@@ -217,20 +225,22 @@ export const SettingsModal: React.FC<{
>
Skills
</VerticalTab>
- )}
- <VerticalTab
- style={horizontalTab}
- selected={tab === 'models'}
- onClick={() => selectTab('models')}
- renderIcon={(color) => (
- <div style={iconContainer}>
- <ModelsIcon color={color} style={icon} />
- </div>
- )}
- >
- Models
- </VerticalTab>
- {isBrowserStudio ? null : (
+ ) : null}
+ {availableTabs.includes('models') ? (
+ <VerticalTab
+ style={horizontalTab}
+ selected={tab === 'models'}
+ onClick={() => selectTab('models')}
+ renderIcon={(color) => (
+ <div style={iconContainer}>
+ <ModelsIcon color={color} style={icon} />
+ </div>
+ )}
+ >
+ Models
+ </VerticalTab>
+ ) : null}
+ {availableTabs.includes('apps') ? (
<VerticalTab
style={horizontalTab}
selected={tab === 'apps'}
@@ -243,8 +253,8 @@ export const SettingsModal: React.FC<{
>
Apps
</VerticalTab>
- )}
- {isBrowserStudio ? null : (
+ ) : null}
+ {availableTabs.includes('license') ? (
<VerticalTab
style={horizontalTab}
selected={tab === 'license'}
@@ -257,8 +267,8 @@ export const SettingsModal: React.FC<{
>
License
</VerticalTab>
- )}
- {showUpdates ? (
+ ) : null}
+ {availableTabs.includes('updates') ? (
<VerticalTab
style={horizontalTab}
selected={tab === 'updates'}
@@ -273,7 +283,8 @@ export const SettingsModal: React.FC<{
</VerticalTab>
) : null}
</div>
- {openedTabs.includes('packages') ? (
+ {availableTabs.includes('packages') &&
+ openedTabs.includes('packages') ? (
<div style={tab === 'packages' ? optionsPanel : hiddenPanel}>
<InstallPackageSettings
footerContainer={packagesFooterContainer}
@@ -281,7 +292,7 @@ export const SettingsModal: React.FC<{
/>
</div>
) : null}
- {openedTabs.includes('apps') ? (
+ {availableTabs.includes('apps') && openedTabs.includes('apps') ? (
<div
style={tab === 'apps' ? settingsOptionsPanel : hiddenPanel}
className={VERTICAL_SCROLLBAR_CLASSNAME}
@@ -289,7 +300,7 @@ export const SettingsModal: React.FC<{
<DefaultEditorSettings />
</div>
) : null}
- {openedTabs.includes('models') ? (
+ {availableTabs.includes('models') && openedTabs.includes('models') ? (
<div
style={tab === 'models' ? settingsOptionsPanel : hiddenPanel}
className={VERTICAL_SCROLLBAR_CLASSNAME}
@@ -297,7 +308,8 @@ export const SettingsModal: React.FC<{
<ModelsSettings />
</div>
) : null}
- {openedTabs.includes('license') ? (
+ {availableTabs.includes('license') &&
+ openedTabs.includes('license') ? (
<div
style={tab === 'license' ? settingsOptionsPanel : hiddenPanel}
className={VERTICAL_SCROLLBAR_CLASSNAME}
@@ -305,7 +317,7 @@ export const SettingsModal: React.FC<{
<LicenseSettings />
</div>
) : null}
- {openedTabs.includes('skills') ? (
+ {availableTabs.includes('skills') && openedTabs.includes('skills') ? (
<div
style={tab === 'skills' ? settingsOptionsPanel : hiddenPanel}
className={VERTICAL_SCROLLBAR_CLASSNAME}
@@ -321,7 +333,8 @@ export const SettingsModal: React.FC<{
<KeyboardShortcutsSettings />
</div>
) : null}
- {openedTabs.includes('rendering') ? (
+ {availableTabs.includes('rendering') &&
+ openedTabs.includes('rendering') ? (
<div
style={tab === 'rendering' ? settingsOptionsPanel : hiddenPanel}
className={VERTICAL_SCROLLBAR_CLASSNAME}
@@ -329,7 +342,7 @@ export const SettingsModal: React.FC<{
<RenderingSettings />
</div>
) : null}
- {openedTabs.includes('studio') ? (
+ {availableTabs.includes('studio') && openedTabs.includes('studio') ? (
<div
style={tab === 'studio' ? settingsOptionsPanel : hiddenPanel}
className={VERTICAL_SCROLLBAR_CLASSNAME}
@@ -337,7 +350,8 @@ export const SettingsModal: React.FC<{
<StudioSettings />
</div>
) : null}
- {showUpdates && openedTabs.includes('updates') ? (
+ {availableTabs.includes('updates') &&
+ openedTabs.includes('updates') ? (
<div
style={tab === 'updates' ? settingsOptionsPanel : hiddenPanel}
className={VERTICAL_SCROLLBAR_CLASSNAME}
@@ -348,7 +362,7 @@ export const SettingsModal: React.FC<{
</div>
{tab === 'packages' ? (
<div ref={setPackagesFooterContainer} />
- ) : isBrowserStudio ||
+ ) : !canEditConfig ||
tab === 'models' ||
tab === 'updates' ||
tab === 'skills' ? null : (
diff --git a/packages/studio/src/helpers/settings-tab-availability.ts b/packages/studio/src/helpers/settings-tab-availability.ts
new file mode 100644
index 0000000000..02a38fd840
--- /dev/null
+++ b/packages/studio/src/helpers/settings-tab-availability.ts
@@ -0,0 +1,66 @@
+export type SettingsTab =
+ | 'apps'
+ | 'rendering'
+ | 'studio'
+ | 'packages'
+ | 'models'
+ | 'shortcuts'
+ | 'skills'
+ | 'license'
+ | 'updates';
+
+type StudioMode = {
+ readonly isBrowserStudio: boolean;
+ readonly previewServerConnected: boolean;
+ readonly readOnlyStudio: boolean;
+};
+
+export const canEditStudioConfig = ({
+ isBrowserStudio,
+ previewServerConnected,
+ readOnlyStudio,
+}: StudioMode) => {
+ return previewServerConnected && !readOnlyStudio && !isBrowserStudio;
+};
+
+export const canInstallPackagesInStudio = (studioMode: StudioMode) => {
+ return studioMode.isBrowserStudio || canEditStudioConfig(studioMode);
+};
+
+export const getAvailableSettingsTabs = ({
+ isBrowserStudio,
+ packageManagerAvailable,
+ previewServerConnected,
+ readOnlyStudio,
+ showUpdates,
+}: StudioMode & {
+ readonly packageManagerAvailable: boolean;
+ readonly showUpdates: boolean;
+}): SettingsTab[] => {
+ const studioMode = {
+ isBrowserStudio,
+ previewServerConnected,
+ readOnlyStudio,
+ };
+ const canEditConfig = canEditStudioConfig(studioMode);
+ const canInstallPackages =
+ canInstallPackagesInStudio(studioMode) &&
+ (isBrowserStudio || packageManagerAvailable);
+
+ return [
+ ...(canEditConfig ? (['studio', 'rendering'] as const) : []),
+ 'shortcuts',
+ ...(canInstallPackages ? (['packages'] as const) : []),
+ ...(canEditConfig ? (['skills'] as const) : []),
+ ...(isBrowserStudio || !readOnlyStudio ? (['models'] as const) : []),
+ ...(canEditConfig ? (['apps', 'license'] as const) : []),
+ ...(showUpdates ? (['updates'] as const) : []),
+ ];
+};
+
+export const getSafeSettingsTab = (
+ requestedTab: SettingsTab,
+ availableTabs: readonly SettingsTab[],
+): SettingsTab => {
+ return availableTabs.includes(requestedTab) ? requestedTab : 'shortcuts';
+};
diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsx
index 829600a37b..ebe445cdd6 100644
--- a/packages/studio/src/helpers/use-menu-structure.tsx
+++ b/packages/studio/src/helpers/use-menu-structure.tsx
@@ -41,6 +41,7 @@ import {getGitMenuItem} from './get-git-menu-item';
import {useMobileLayout} from './mobile-layout';
import {openInEditor, preloadCompositionComponentInfo} from './open-in-editor';
import {pickColor} from './pick-color';
+import {canEditStudioConfig} from './settings-tab-availability';
import {getStudioAskAIEnabled} from './studio-runtime-config';
import {areKeyboardShortcutsDisabled} from './use-keybinding';
import {useKeyboardShortcutLabel} from './use-keyboard-shortcut-label';
@@ -342,6 +343,11 @@ export const useMenuStructure = (
const {remotion_packageManager} = window;
const browserStudioOperations = getBrowserStudioOperations();
+ const studioConfigEditable = canEditStudioConfig({
+ isBrowserStudio: browserStudioOperations !== null,
+ previewServerConnected: type === 'connected',
+ readOnlyStudio,
+ });
const sizePreselectIndex = sizes.findIndex(
(s) => String(size.size) === String(s.size),
@@ -436,8 +442,7 @@ export const useMenuStructure = (
closeMenu();
setSelectedModal({
type: 'settings',
- initialTab:
- browserStudioOperations === null ? 'studio' : 'shortcuts',
+ initialTab: studioConfigEditable ? 'studio' : 'shortcuts',
initialPublicLicenseKey:
window.remotion_renderDefaults?.publicLicenseKey ?? null,
});
@@ -447,9 +452,6 @@ export const useMenuStructure = (
leftItem: null,
subMenu: null,
quickSwitcherLabel: 'Settings...',
- disabled:
- (browserStudioOperations === null && readOnlyStudio) ||
- type !== 'connected',
},
{
id: 'acknowledgements',
@@ -465,13 +467,13 @@ export const useMenuStructure = (
subMenu: null,
quickSwitcherLabel: 'Help: Acknowledgements',
},
- browserStudioOperations === null
+ studioConfigEditable
? {
type: 'divider' as const,
id: 'timeline-divider-1',
}
: null,
- browserStudioOperations === null
+ studioConfigEditable
? {
id: 'restart-studio',
value: 'restart-studio',
@@ -955,7 +957,7 @@ export const useMenuStructure = (
: null,
!canInstallPackages() ||
(browserStudioOperations === null &&
- remotion_packageManager === 'unknown')
+ (remotion_packageManager === 'unknown' || type !== 'connected'))
? null
: {
id: 'install-packages',
@@ -1196,6 +1198,7 @@ export const useMenuStructure = (
showKeyboardShortcutsShortcut,
toggleSnappingShortcut,
browserStudioOperations,
+ studioConfigEditable,
size.size,
setSize,
setEditorZoomGestures,
diff --git a/packages/studio/src/test/models-settings.test.tsx b/packages/studio/src/test/models-settings.test.tsx
index bddbf28e41..823979377e 100644
--- a/packages/studio/src/test/models-settings.test.tsx
+++ b/packages/studio/src/test/models-settings.test.tsx
@@ -3,29 +3,50 @@ import {cleanup, fireEvent, render, waitFor} from '@testing-library/react';
import {ModelsSettings} from '../components/ModelsSettings';
import {WHISPER_WEBGPU_PACKAGE} from '../components/Transcription/whisper-webgpu-capability';
import {VIDEO_MATTING_PACKAGE} from '../components/VideoMatting/video-matting-capability';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
import {TRANSFORMERS_PACKAGE} from '../helpers/optional-package-dependencies';
const originalInstalledPackages = window.remotion_installedPackages;
const originalIsStudio = window.remotion_isStudio;
+const originalIsReadOnlyStudio = window.remotion_isReadOnlyStudio;
const originalStaticBase = window.remotion_staticBase;
afterEach(() => {
cleanup();
window.remotion_installedPackages = originalInstalledPackages;
window.remotion_isStudio = originalIsStudio;
+ window.remotion_isReadOnlyStudio = originalIsReadOnlyStudio;
window.remotion_staticBase = originalStaticBase;
});
+const renderModelsSettings = (previewServerConnected: boolean) => {
+ return render(
+ <StudioServerConnectionCtx.Provider
+ value={{
+ configFileChangeRevision: 0,
+ previewServerState: previewServerConnected
+ ? {type: 'connected', clientId: 'test-client'}
+ : {type: 'disconnected'},
+ restartRequired: false,
+ subscribeToEvent: () => () => undefined,
+ }}
+ >
+ <ModelsSettings />
+ </StudioServerConnectionCtx.Provider>,
+ );
+};
+
test('offers to install missing model packages and loads models in place', async () => {
window.remotion_installedPackages = [];
window.remotion_isStudio = true;
+ window.remotion_isReadOnlyStudio = false;
window.remotion_staticBase = '';
const fetchSpy = spyOn(globalThis, 'fetch').mockResolvedValue(
new Response(JSON.stringify({success: true, data: {}})),
);
try {
- const {getAllByRole, getByRole} = render(<ModelsSettings />);
+ const {getAllByRole, getByRole} = renderModelsSettings(true);
expect(getAllByRole('button', {name: 'Install'})).toHaveLength(2);
fireEvent.click(getAllByRole('button', {name: 'Install'})[0]);
@@ -45,3 +66,18 @@ test('offers to install missing model packages and loads models in place', async
fetchSpy.mockRestore();
}
});
+
+test('does not offer package installation while Studio is detached', () => {
+ window.remotion_installedPackages = [];
+ window.remotion_isStudio = true;
+ window.remotion_isReadOnlyStudio = false;
+
+ const {getAllByText, queryAllByRole} = renderModelsSettings(false);
+
+ expect(queryAllByRole('button', {name: 'Install'})).toHaveLength(0);
+ expect(
+ getAllByText(
+ 'Reconnect the Studio server to install this package and manage its models.',
+ ),
+ ).toHaveLength(2);
+});
diff --git a/packages/studio/src/test/settings-tab-availability.test.ts b/packages/studio/src/test/settings-tab-availability.test.ts
new file mode 100644
index 0000000000..a6086c9d5f
--- /dev/null
+++ b/packages/studio/src/test/settings-tab-availability.test.ts
@@ -0,0 +1,89 @@
+import {expect, test} from 'bun:test';
+import {
+ canEditStudioConfig,
+ canInstallPackagesInStudio,
+ getAvailableSettingsTabs,
+ getSafeSettingsTab,
+} from '../helpers/settings-tab-availability';
+
+test('shows every applicable setting in connected interactive Studio', () => {
+ const studioMode = {
+ isBrowserStudio: false,
+ previewServerConnected: true,
+ readOnlyStudio: false,
+ };
+
+ expect(canEditStudioConfig(studioMode)).toBe(true);
+ expect(canInstallPackagesInStudio(studioMode)).toBe(true);
+ expect(
+ getAvailableSettingsTabs({
+ ...studioMode,
+ packageManagerAvailable: true,
+ showUpdates: true,
+ }),
+ ).toEqual([
+ 'studio',
+ 'rendering',
+ 'shortcuts',
+ 'packages',
+ 'skills',
+ 'models',
+ 'apps',
+ 'license',
+ 'updates',
+ ]);
+});
+
+test('keeps only read-only controls when the preview server is detached', () => {
+ const studioMode = {
+ isBrowserStudio: false,
+ previewServerConnected: false,
+ readOnlyStudio: false,
+ };
+
+ expect(canEditStudioConfig(studioMode)).toBe(false);
+ expect(canInstallPackagesInStudio(studioMode)).toBe(false);
+ expect(
+ getAvailableSettingsTabs({
+ ...studioMode,
+ packageManagerAvailable: true,
+ showUpdates: false,
+ }),
+ ).toEqual(['shortcuts', 'models']);
+});
+
+test('hides model and server-backed settings in deployed read-only Studio', () => {
+ const studioMode = {
+ isBrowserStudio: false,
+ previewServerConnected: false,
+ readOnlyStudio: true,
+ };
+ const availableTabs = getAvailableSettingsTabs({
+ ...studioMode,
+ packageManagerAvailable: true,
+ showUpdates: false,
+ });
+
+ expect(canEditStudioConfig(studioMode)).toBe(false);
+ expect(canInstallPackagesInStudio(studioMode)).toBe(false);
+ expect(availableTabs).toEqual(['shortcuts']);
+ expect(getSafeSettingsTab('license', availableTabs)).toBe('shortcuts');
+});
+
+test('keeps virtual filesystem actions in Browser Studio', () => {
+ const studioMode = {
+ isBrowserStudio: true,
+ previewServerConnected: true,
+ readOnlyStudio: true,
+ };
+
+ expect(canEditStudioConfig(studioMode)).toBe(false);
+ expect(canInstallPackagesInStudio(studioMode)).toBe(true);
+ expect(
+ getAvailableSettingsTabs({
+ ...studioMode,
+ packageManagerAvailable: false,
+ showUpdates: false,
+ }),
+ ).toEqual(['shortcuts', 'packages', 'models']);
+});