From 4541daa7c038cdb63c7fd771b49bf3cb33b25858 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 93cb10b9b6b..55d4b961499 100644 --- a/app/src/lib/editors/linux.ts +++ b/app/src/lib/editors/linux.ts @@ -44,6 +44,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: @@ -51,25 +63,21 @@ async function getEditorPath(editor: ExternalEditor): Promise { case ExternalEditor.VisualStudioCode: return getPathIfAvailable('/usr/bin/code') case ExternalEditor.VisualStudioCodeInsiders: - return getPathIfAvailable('/usr/bin/code-insiders') + return getFirstPathIfAvailable([ + '/snap/bin/code-insiders', + '/usr/bin/code-insiders', + ]) 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}`) }