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
parent
bef5dae3fa
commit
e72872af64
|
@ -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')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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()
|
return openUI()
|
||||||
|
});
|
||||||
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
disposables.push(commands.registerCommand('openhab.searchDocs', () => openBrowser()))
|
disposables.push(commands.registerCommand('openhab.searchDocs', () => openBrowser()))
|
||||||
|
|
Loading…
Reference in New Issue