mirror of
https://github.com/desktop/desktop
synced 2024-10-30 06:03:10 +00:00
Merge pull request #6181 from msftrncs/win32_LaunchEditor_UseShell
Win32 LaunchEditor use Shell for .CMD files
This commit is contained in:
commit
c0ecd05bde
5 changed files with 44 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
|||
export interface IFoundEditor<T> {
|
||||
readonly editor: T
|
||||
readonly path: string
|
||||
readonly usesShell?: boolean
|
||||
}
|
||||
|
|
|
@ -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])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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:
|
||||
|
@ -470,6 +470,7 @@ export async function getAvailableEditors(): Promise<
|
|||
results.push({
|
||||
editor: ExternalEditor.Atom,
|
||||
path: atomPath,
|
||||
usesShell: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -477,6 +478,7 @@ export async function getAvailableEditors(): Promise<
|
|||
results.push({
|
||||
editor: ExternalEditor.VisualStudioCode,
|
||||
path: codePath,
|
||||
usesShell: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -484,6 +486,7 @@ export async function getAvailableEditors(): Promise<
|
|||
results.push({
|
||||
editor: ExternalEditor.VisualStudioCodeInsiders,
|
||||
path: codeInsidersPath,
|
||||
usesShell: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -491,6 +494,7 @@ export async function getAvailableEditors(): Promise<
|
|||
results.push({
|
||||
editor: ExternalEditor.SublimeText,
|
||||
path: sublimePath,
|
||||
usesShell: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -498,6 +502,7 @@ export async function getAvailableEditors(): Promise<
|
|||
results.push({
|
||||
editor: ExternalEditor.CFBuilder,
|
||||
path: cfBuilderPath,
|
||||
usesShell: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -505,6 +510,7 @@ export async function getAvailableEditors(): Promise<
|
|||
results.push({
|
||||
editor: ExternalEditor.Typora,
|
||||
path: typoraPath,
|
||||
usesShell: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue