Skip to content

Commit

Permalink
Detect snap installation of Visual Studio Code on Linux (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggy42 authored and shiftkey committed Dec 17, 2020
1 parent 26778ee commit b2cb253
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions app/src/lib/editors/linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,42 @@ async function getPathIfAvailable(path: string): Promise<string | null> {
return (await pathExists(path)) ? path : null
}

async function getFirstPathIfAvailable(
possiblePaths: string[]
): Promise<string | null> {
for (const possiblePath of possiblePaths) {
const path = await getPathIfAvailable(possiblePath)
if (path) {
return path
}
}
return null
}

async function getEditorPath(editor: ExternalEditor): Promise<string | null> {
switch (editor) {
case ExternalEditor.Atom:
return getPathIfAvailable('/usr/bin/atom')
case ExternalEditor.VSCode:
return getPathIfAvailable('/usr/bin/code')
case ExternalEditor.VSCodeInsiders:
return getPathIfAvailable('/usr/bin/code-insiders')
return getFirstPathIfAvailable([
'/snap/bin/code-insiders',
'/usr/bin/code-insiders',
])
case ExternalEditor.VSCodium:
return getPathIfAvailable('/usr/bin/codium')
case ExternalEditor.SublimeText:
return getPathIfAvailable('/usr/bin/subl')
case ExternalEditor.Typora:
return getPathIfAvailable('/usr/bin/typora')
case ExternalEditor.SlickEdit:
const possiblePaths = [
return getFirstPathIfAvailable([
'/opt/slickedit-pro2018/bin/vs',
'/opt/slickedit-pro2017/bin/vs',
'/opt/slickedit-pro2016/bin/vs',
'/opt/slickedit-pro2015/bin/vs',
]
for (const possiblePath of possiblePaths) {
const slickeditPath = await getPathIfAvailable(possiblePath)
if (slickeditPath) {
return slickeditPath
}
}
return null
])
default:
return assertNever(editor, `Unknown editor: ${editor}`)
}
Expand Down

0 comments on commit b2cb253

Please sign in to comment.