From 559fe40ce46504d82baf8a1c76c1c70e53bc82c3 Mon Sep 17 00:00:00 2001 From: Andrea Pivetta Date: Tue, 2 Jul 2019 22:57:43 +0200 Subject: [PATCH] Detect snap installation of Visual Studio Code on Linux (#156) --- app/src/lib/editors/linux.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/lib/editors/linux.ts b/app/src/lib/editors/linux.ts index 66a516c6cc3..fdba2f17294 100644 --- a/app/src/lib/editors/linux.ts +++ b/app/src/lib/editors/linux.ts @@ -22,6 +22,18 @@ async function getPathIfAvailable(path: string): Promise { return (await pathExists(path)) ? path : null } +async function getFirstPathIfAvailable( + possiblePaths: string[] +): Promise { + for (const possiblePath of possiblePaths) { + const path = await getPathIfAvailable(possiblePath) + if (path) { + return path + } + } + return null +} + async function getEditorPath(editor: ExternalEditor): Promise { switch (editor) { case ExternalEditor.Atom: @@ -29,7 +41,10 @@ async function getEditorPath(editor: ExternalEditor): Promise { 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: @@ -37,19 +52,12 @@ async function getEditorPath(editor: ExternalEditor): Promise { 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}`) }