Open Sitemap directly (#104)

* Open Sitemap directly if its the only one that has been created by a user.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* 104 Added minor code cleanup
Signed-off-by: Kuba Wolanin <hi@kubawolanin.com> (github: kubawolanin)
pull/106/head^2
Jerome Luckenbach 2018-07-15 21:44:41 +02:00 committed by Kuba Wolanin
parent bef5dae3fa
commit e72872af64
1 changed files with 22 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import {
import { import {
openBrowser, openBrowser,
openHtml, openHtml,
getSitemaps,
openUI openUI
} from './Utils' } from './Utils'
@ -67,7 +68,27 @@ async function init(context: ExtensionContext, disposables: Disposable[], config
}, 'Classic UI') }, '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())) disposables.push(commands.registerCommand('openhab.searchDocs', () => openBrowser()))