Skip to content

🎥 Make videos programmatically with React

add os-level progress bar

Igor Samokhovetsd6ec3c807642
diff --git a/packages/template-electron/README.md b/packages/template-electron/README.md
index 99b2107e15..b0bf1bd31a 100644
--- a/packages/template-electron/README.md
+++ b/packages/template-electron/README.md
@@ -27,7 +27,7 @@ npm install
npm run dev
```
-Type a title, then click the export button in the app window. The app will ask where to save the video before rendering.
+Type a title, then click the export button in the app window. The app will ask where to save the video before rendering, and the app icon shows render progress at the OS level while work is ongoing.
In development, the Remotion project is bundled on each render so composition changes are always picked up. The first render may also download Chrome Headless Shell if no compatible local browser is installed yet.
diff --git a/packages/template-electron/src/main.ts b/packages/template-electron/src/main.ts
index aaaf4dd14a..af5d7c3d1c 100644
--- a/packages/template-electron/src/main.ts
+++ b/packages/template-electron/src/main.ts
@@ -24,6 +24,7 @@ import {renderVideo} from "./render-video";
let mainWindow: BrowserWindow | null = null;
let activeRender: Promise<RenderResult> | null = null;
const integrationRenderOutputPath = getIntegrationRenderOutputPath();
+let currentWindowProgressBarValue = -1;
if (app.isPackaged) {
process.chdir(app.getPath("userData"));
@@ -31,6 +32,20 @@ if (app.isPackaged) {
const sendRenderUpdate = (update: RenderUpdate) => {
mainWindow?.webContents.send(RENDER_PROGRESS_CHANNEL, update);
+
+ if (update.type === "progress") {
+ const normalizedProgress = Math.max(
+ 0,
+ Math.min(1, update.progress / 100 || 0),
+ );
+ currentWindowProgressBarValue = normalizedProgress;
+ mainWindow?.setProgressBar(currentWindowProgressBarValue);
+ }
+};
+
+const setWindowProgressBar = (progress: number) => {
+ currentWindowProgressBarValue = progress;
+ mainWindow?.setProgressBar(currentWindowProgressBarValue);
};
const assertTrustedSender = (event: IpcMainInvokeEvent) => {
@@ -52,6 +67,7 @@ const createWindow = () => {
mainWindow.webContents.setWindowOpenHandler(() => {
return {action: "deny"};
});
+ mainWindow.setProgressBar(currentWindowProgressBarValue);
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
@@ -106,6 +122,7 @@ ipcMain.handle(RENDER_VIDEO_CHANNEL, async (event, input: RenderRequest) => {
throw new Error("Output path must be absolute.");
}
+ setWindowProgressBar(2);
activeRender = renderVideo({
isPackaged: app.isPackaged,
outputPath: input.outputPath,
@@ -130,6 +147,7 @@ ipcMain.handle(RENDER_VIDEO_CHANNEL, async (event, input: RenderRequest) => {
});
throw error;
} finally {
+ setWindowProgressBar(-1);
activeRender = null;
}
});