Skip to content

Commit

Permalink
Merge pull request #6181 from msftrncs/win32_LaunchEditor_UseShell
Browse files Browse the repository at this point in the history
Win32 LaunchEditor use Shell for .CMD files
  • Loading branch information
outofambit committed Nov 20, 2018
2 parents 1bab78c + 51ba531 commit c0ecd05
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/src/lib/editors/found-editor.ts
@@ -1,4 +1,5 @@
export interface IFoundEditor<T> {
readonly editor: T
readonly path: string
readonly usesShell?: boolean
}
7 changes: 5 additions & 2 deletions app/src/lib/editors/launch.ts
Expand Up @@ -23,6 +23,9 @@ export async function launchExternalEditor(
{ openPreferences: true }
)
}

spawn(editorPath, [fullPath])
if (editor.usesShell) {
spawn(`"${editorPath}"`, [`"${fullPath}"`], { shell: true })
} else {
spawn(editorPath, [fullPath])
}
}
4 changes: 4 additions & 0 deletions app/src/lib/editors/shared.ts
Expand Up @@ -33,6 +33,10 @@ export type FoundEditor = {
* The executable associated with the editor to launch
*/
path: string
/**
* the editor requires a shell spawn to launch
*/
usesShell?: boolean
}

interface IErrorMetadata {
Expand Down
12 changes: 9 additions & 3 deletions app/src/lib/editors/win32.ts
Expand Up @@ -247,11 +247,11 @@ function getExecutableShim(
): string {
switch (editor) {
case ExternalEditor.Atom:
return Path.join(installLocation, 'bin', 'atom.cmd')
return Path.join(installLocation, 'bin', 'atom.cmd') // remember, CMD must 'useShell'
case ExternalEditor.VisualStudioCode:
return Path.join(installLocation, 'bin', 'code.cmd')
return Path.join(installLocation, 'bin', 'code.cmd') // remember, CMD must 'useShell'
case ExternalEditor.VisualStudioCodeInsiders:
return Path.join(installLocation, 'bin', 'code-insiders.cmd')
return Path.join(installLocation, 'bin', 'code-insiders.cmd') // remember, CMD must 'useShell'
case ExternalEditor.SublimeText:
return Path.join(installLocation, 'subl.exe')
case ExternalEditor.CFBuilder:
Expand Down Expand Up @@ -470,41 +470,47 @@ export async function getAvailableEditors(): Promise<
results.push({
editor: ExternalEditor.Atom,
path: atomPath,
usesShell: true,
})
}

if (codePath) {
results.push({
editor: ExternalEditor.VisualStudioCode,
path: codePath,
usesShell: true,
})
}

if (codeInsidersPath) {
results.push({
editor: ExternalEditor.VisualStudioCodeInsiders,
path: codeInsidersPath,
usesShell: true,
})
}

if (sublimePath) {
results.push({
editor: ExternalEditor.SublimeText,
path: sublimePath,
usesShell: false,
})
}

if (cfBuilderPath) {
results.push({
editor: ExternalEditor.CFBuilder,
path: cfBuilderPath,
usesShell: false,
})
}

if (typoraPath) {
results.push({
editor: ExternalEditor.Typora,
path: typoraPath,
usesShell: false,
})
}

Expand Down
26 changes: 25 additions & 1 deletion docs/technical/editor-integration.md
Expand Up @@ -189,7 +189,7 @@ function isExpectedInstallation(
}
```

### Step 3: Launch the program
### Step 3: Determine the program to launch

Now that Desktop knows the program is the one it expects, it can use the
install location to then find the executable to launch. Many editors provide a
Expand All @@ -214,6 +214,30 @@ function getExecutableShim(
Desktop will confirm this file exists on disk before launching - if it's
missing or lost it won't let you launch the external editor.

If the external editor utilizes a CMD.EXE shell script to launch, Desktop
needs to know this in order to properly launch the CMD.EXE shell. This is
done by setting the property `usesShell: true` in `getAvailableEditors`.

```ts
export async function getAvailableEditors(): Promise<
ReadonlyArray<IFoundEditor<ExternalEditor>>
> {
...

if (codePath) {
results.push({
editor: ExternalEditor.VisualStudioCode,
path: codePath,
usesShell: true,
})
}

...

return results
}
```

## macOS

The source for the editor integration on macOS is found in
Expand Down

0 comments on commit c0ecd05

Please sign in to comment.