Skip to content

Visualize Your Ideas With Code

feat: button for opening the output directory (#663)

Jacob79f320c07c42
diff --git a/packages/ui/src/components/sidebar/VideoSettings.tsx b/packages/ui/src/components/sidebar/VideoSettings.tsx
index e8efa187..4a60fd99 100644
--- a/packages/ui/src/components/sidebar/VideoSettings.tsx
+++ b/packages/ui/src/components/sidebar/VideoSettings.tsx
@@ -5,9 +5,11 @@ import {useApplication} from '../../contexts';
import {Expandable} from '../fields';
import {RendererState} from '@motion-canvas/core';
import {MetaFieldView} from '../meta';
+import {openOutputPath} from '../../utils';
export function VideoSettings() {
const {meta} = useApplication();
+ const [processId, setProcess] = useStorage('main-action', 0);
return (
<Pane title="Video Settings" id="settings-pane">
@@ -22,14 +24,29 @@ export function VideoSettings() {
</Expandable>
<Group>
<Label />
- <ProcessButton />
+ <ProcessButton processId={processId} setProcess={setProcess} />
</Group>
+ {processId === 0 && (
+ <Group>
+ <Label />
+ <Button
+ title="Reveal the output directory in file explorer"
+ onClick={openOutputPath}
+ >
+ OUTPUT DIRECTORY
+ </Button>
+ </Group>
+ )}
</Pane>
);
}
-function ProcessButton() {
- const [processId, setProcess] = useStorage('main-action', 0);
+interface ProcessButtonProps {
+ processId: number;
+ setProcess: (id: number) => void;
+}
+
+function ProcessButton({processId, setProcess}: ProcessButtonProps) {
const {renderer, presenter, meta, project} = useApplication();
const rendererState = useRendererState();
diff --git a/packages/ui/src/utils/index.ts b/packages/ui/src/utils/index.ts
index a0cc00a2..b69c26b4 100644
--- a/packages/ui/src/utils/index.ts
+++ b/packages/ui/src/utils/index.ts
@@ -1,5 +1,6 @@
export * from './clamp';
export * from './localStorage';
+export * from './openOutputPath';
export * from './sourceMaps';
export * from './withLoader';
export * from './compareVersions';
diff --git a/packages/ui/src/utils/openOutputPath.ts b/packages/ui/src/utils/openOutputPath.ts
new file mode 100644
index 00000000..f1280860
--- /dev/null
+++ b/packages/ui/src/utils/openOutputPath.ts
@@ -0,0 +1,7 @@
+import {withLoader} from './withLoader';
+
+export function openOutputPath() {
+ return withLoader(async () => {
+ await fetch('/__open-output-path');
+ });
+}
diff --git a/packages/vite-plugin/src/main.ts b/packages/vite-plugin/src/main.ts
index 97e8053b..d7a7aa49 100644
--- a/packages/vite-plugin/src/main.ts
+++ b/packages/vite-plugin/src/main.ts
@@ -10,6 +10,7 @@ import {
} from './proxy-middleware';
import {getVersions} from './versions';
import {PluginOptions, isPlugin, PLUGIN_OPTIONS, ProjectData} from './plugins';
+import {openInExplorer} from './openInExplorer';
export interface MotionCanvasPluginConfig {
/**
@@ -361,6 +362,12 @@ export default ({
return;
}
+ if (name === '__open-output-path') {
+ openInExplorer(outputPath);
+ res.end();
+ return;
+ }
+
next();
});
diff --git a/packages/vite-plugin/src/openInExplorer.ts b/packages/vite-plugin/src/openInExplorer.ts
new file mode 100644
index 00000000..b0bf9896
--- /dev/null
+++ b/packages/vite-plugin/src/openInExplorer.ts
@@ -0,0 +1,24 @@
+import {spawn} from 'child_process';
+import {platform} from 'os';
+
+export function openInExplorer(file: string) {
+ let explorer: string | null = null;
+ const os = platform();
+ switch (os) {
+ case 'win32':
+ explorer = 'explorer';
+ break;
+ case 'linux':
+ explorer = 'xdg-open';
+ break;
+ case 'darwin':
+ explorer = 'open';
+ break;
+ }
+
+ if (explorer) {
+ spawn(explorer, [file], {detached: true}).unref();
+ } else {
+ console.warn(`Unsupported OS: ${os}`);
+ }
+}