From e72872af64407a9b2a6c3b239aa2f2ff395a6bce Mon Sep 17 00:00:00 2001 From: Jerome Luckenbach Date: Sun, 15 Jul 2018 21:44:41 +0200 Subject: [PATCH] Open Sitemap directly (#104) * Open Sitemap directly if its the only one that has been created by a user. Signed-off-by: Jerome Luckenbach * 104 Added minor code cleanup Signed-off-by: Kuba Wolanin (github: kubawolanin) --- src/extension.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index cb775e9..13a2e35 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,6 +21,7 @@ import { import { openBrowser, openHtml, + getSitemaps, openUI } from './Utils' @@ -67,7 +68,27 @@ async function init(context: ExtensionContext, disposables: Disposable[], config }, 'Classic UI') } - return openUI() + // If there is only one user created sitemap open it directly + getSitemaps().then(sitemaps => { + const defaultName = sitemap => sitemap.name === '_default' + const defaultSitemap = sitemaps.find(defaultName) + + if (sitemaps.length === 1) { + return openUI({ + route: `/${ui}/app?sitemap=${sitemaps[0].name}`, + }, sitemaps[0].name) + } + + if (sitemaps.length === 2 && typeof defaultSitemap !== 'undefined') { + const index = sitemaps.indexOf(defaultName) === 0 ? 1 : 0 + return openUI({ + route: `/${ui}/app?sitemap=${sitemaps[index].name}`, + }, sitemaps[index].name) + } + + return openUI() + }); + })) disposables.push(commands.registerCommand('openhab.searchDocs', () => openBrowser()))