Skip to content

Fix OUTPUT DIRECTORY button on WSL - #787

Merged
aarthificial merged 3 commits into
motion-canvas:mainfrom
przemeksulecki:fix-output-directory-on-wsl
Oct 18, 2023
Merged

aarthificial merged 3 commits into
motion-canvas:mainfrom
przemeksulecki:fix-output-directory-on-wsl

Conversation

@przemeksulecki

Copy link
Copy Markdown
Contributor

This is a PR regarding the OUTPUT DIRECTORY button located in the player's video settings.

When we run npm on WSL (Windows Subsystem for Linux) then Motion Canvas tries to execute:
xdg-open <absolute-path-to-output-dir>

In the case of WSL it won't work, so we can do something like this:
bash -c cd <absolute-path-to-output-dir> && explorer.exe .

@aarthificial aarthificial left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the explorer variable no longer makes sense with WSL, I recommend we rewrite this function a bit to avoid this confusing explorer === 'bash' check at the end:

export function openInExplorer(file: string) {
  let command: string | null = null;
  let args = [file];
  const os = platform();

  switch (os) {
    case 'win32':
      command = 'explorer';
      break;
    case 'linux':
      if (isRunningOnWSL()) {
        command = 'bash';
        args = ['-c', `cd ${file} && explorer.exe .`];
      } else {
        command = 'xdg-open';
      }
      break;
    case 'darwin':
      command = 'open';
      break;
  }

  if (command) {
    spawn(command, args, {detached: true}).unref();
  } else {
    console.warn(`Unsupported OS: ${os}`);
  }
}

Comment thread packages/vite-plugin/src/openInExplorer.ts Outdated
@przemeksulecki
przemeksulecki force-pushed the fix-output-directory-on-wsl branch from 0dc2538 to 5e18892 Compare August 27, 2023 11:49
@przemeksulecki

Copy link
Copy Markdown
Contributor Author

I did force-push because I initially forgot to add --fixup flag during committing.

@aarthificial
aarthificial merged commit 20cceef into motion-canvas:main Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants