Skip to content

🎥 Make videos programmatically with React

@remotion/studio: Show restart action for config changes

Jonny Burgerae3d2b6488a2
diff --git a/packages/studio/src/components/SettingsModalFooter.tsx b/packages/studio/src/components/SettingsModalFooter.tsx
index bb0e4078e5..eec63abdcc 100644
--- a/packages/studio/src/components/SettingsModalFooter.tsx
+++ b/packages/studio/src/components/SettingsModalFooter.tsx
@@ -1,9 +1,12 @@
-import React, {useCallback, useMemo} from 'react';
+import React, {useCallback, useContext, useMemo, useState} from 'react';
+import {restartStudio} from '../api/restart-studio';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
import {BLUE, CURRENT_COLOR, LIGHT_TEXT} from '../helpers/colors';
import {InspectorOpenInEditor} from './InspectorOpenInEditor';
import {InspectorQuickAction} from './InspectorPanel/common';
import {Spacing} from './layout';
import {ModalFooterContainer} from './ModalFooter';
+import {showNotification} from './Notifications/NotificationCenter';
const footer: React.CSSProperties = {
flex: 'none',
@@ -44,6 +47,8 @@ const externalLinkIndicator: React.CSSProperties = {
export const SettingsModalFooter: React.FC<{
readonly showLicenseFaq: boolean;
}> = ({showLicenseFaq}) => {
+ const {restartRequired} = useContext(StudioServerConnectionCtx);
+ const [restarting, setRestarting] = useState(false);
const configFileLocation = useMemo(() => {
return {
source: 'remotion.config.ts',
@@ -58,6 +63,13 @@ export const SettingsModalFooter: React.FC<{
'noopener,noreferrer',
);
}, []);
+ const restart = useCallback(() => {
+ setRestarting(true);
+ restartStudio().catch((error: Error) => {
+ setRestarting(false);
+ showNotification(`Could not restart Studio: ${error.message}`, 4000);
+ });
+ }, []);
return (
<ModalFooterContainer style={footer}>
@@ -72,7 +84,16 @@ export const SettingsModalFooter: React.FC<{
showTooltips={false}
/>
</div>
- {showLicenseFaq ? (
+ {restartRequired ? (
+ <InspectorQuickAction
+ disabled={restarting}
+ onClick={restart}
+ style={{flex: 'none', width: 'fit-content'}}
+ title="Restart Studio to apply config file changes"
+ >
+ {restarting ? 'Restarting...' : 'Restart Studio'}
+ </InspectorQuickAction>
+ ) : showLicenseFaq ? (
<InspectorQuickAction
disabled={false}
onClick={openLicenseFaq}
diff --git a/packages/studio/src/helpers/client-id.tsx b/packages/studio/src/helpers/client-id.tsx
index dfac7b5f31..59a8697910 100644
--- a/packages/studio/src/helpers/client-id.tsx
+++ b/packages/studio/src/helpers/client-id.tsx
@@ -18,6 +18,7 @@ import {reloadUrl} from './url-state';
type Context = {
previewServerState: PreviewServerConnectionState;
configFileChangeRevision: number;
+ restartRequired: boolean;
subscribeToEvent: (
type: EventSourceEvent['type'],
listener: (event: EventSourceEvent) => void,
@@ -29,6 +30,7 @@ export const StudioServerConnectionCtx = React.createContext<Context>({
type: 'init',
},
configFileChangeRevision: 0,
+ restartRequired: false,
subscribeToEvent: () => {
throw new Error('Context not initalized');
},
@@ -71,6 +73,7 @@ export const PreviewServerConnection: React.FC<{
});
const [configFileChangeRevision, setConfigFileChangeRevision] =
React.useState(0);
+ const [restartRequired, setRestartRequired] = React.useState(false);
const clientId = useRef<string | null>(null);
useEffect(() => {
@@ -87,11 +90,16 @@ export const PreviewServerConnection: React.FC<{
window.remotion_studioConfig = newEvent.studioRuntimeConfig;
window.remotion_editorName = newEvent.editorName;
setConfigFileChangeRevision((revision) => revision + 1);
- const isOwnRuntimeConfigChange =
- newEvent.changeType === 'runtime' &&
+ const isOwnConfigChange =
newEvent.originatorClientId !== null &&
newEvent.originatorClientId === clientId.current;
- if (!isOwnRuntimeConfigChange) {
+ if (isOwnConfigChange) {
+ setRestartRequired(newEvent.changeType === 'restart');
+ }
+
+ const shouldShowNotification =
+ !isOwnConfigChange || newEvent.changeType === 'reload';
+ if (shouldShowNotification) {
showNotification(
getConfigFileChangeMessage(newEvent.changeType),
4000,
@@ -174,9 +182,10 @@ export const PreviewServerConnection: React.FC<{
return {
previewServerState: state,
configFileChangeRevision,
+ restartRequired,
subscribeToEvent,
};
- }, [configFileChangeRevision, state, subscribeToEvent]);
+ }, [configFileChangeRevision, restartRequired, state, subscribeToEvent]);
return (
<StudioServerConnectionCtx.Provider value={context}>