mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
auto enable/disable extensions -- part 4
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
4a44001897
commit
462386a206
@ -53,59 +53,45 @@ export class ExtensionLoader extends BaseStore<ExtensionLoaderStoreModel> {
|
|||||||
loadOnMain() {
|
loadOnMain() {
|
||||||
logger.info('[EXTENSIONS-LOADER]: load on main')
|
logger.info('[EXTENSIONS-LOADER]: load on main')
|
||||||
this.autoInitExtensions();
|
this.autoInitExtensions();
|
||||||
this.autoEnableExtensions((extension: LensMainExtension) => {
|
this.autoEnableExtensions((extension: LensMainExtension) => [
|
||||||
this.handleActivation(extension, () => [
|
registries.menuRegistry.add(...extension.appMenus)
|
||||||
registries.menuRegistry.add(...extension.appMenus)
|
])
|
||||||
])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOnClusterManagerRenderer() {
|
loadOnClusterManagerRenderer() {
|
||||||
logger.info('[EXTENSIONS-LOADER]: load on main renderer (cluster manager)')
|
logger.info('[EXTENSIONS-LOADER]: load on main renderer (cluster manager)')
|
||||||
this.autoInitExtensions();
|
this.autoInitExtensions();
|
||||||
this.autoEnableExtensions((extension: LensRendererExtension) => {
|
this.autoEnableExtensions((extension: LensRendererExtension) => [
|
||||||
this.handleActivation(extension, () => [
|
registries.globalPageRegistry.add(...extension.globalPages),
|
||||||
registries.globalPageRegistry.add(...extension.globalPages),
|
registries.appPreferenceRegistry.add(...extension.appPreferences),
|
||||||
registries.appPreferenceRegistry.add(...extension.appPreferences),
|
registries.clusterFeatureRegistry.add(...extension.clusterFeatures),
|
||||||
registries.clusterFeatureRegistry.add(...extension.clusterFeatures),
|
registries.statusBarRegistry.add(...extension.statusBarItems),
|
||||||
registries.statusBarRegistry.add(...extension.statusBarItems),
|
])
|
||||||
])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadOnClusterRenderer() {
|
loadOnClusterRenderer() {
|
||||||
logger.info('[EXTENSIONS-LOADER]: load on cluster renderer (dashboard)')
|
logger.info('[EXTENSIONS-LOADER]: load on cluster renderer (dashboard)')
|
||||||
this.autoInitExtensions();
|
this.autoInitExtensions();
|
||||||
this.autoEnableExtensions((extension: LensRendererExtension) => {
|
this.autoEnableExtensions((extension: LensRendererExtension) => [
|
||||||
this.handleActivation(extension, () => [
|
registries.clusterPageRegistry.add(...extension.clusterPages),
|
||||||
registries.clusterPageRegistry.add(...extension.clusterPages),
|
registries.kubeObjectMenuRegistry.add(...extension.kubeObjectMenuItems),
|
||||||
registries.kubeObjectMenuRegistry.add(...extension.kubeObjectMenuItems),
|
registries.kubeObjectDetailRegistry.add(...extension.kubeObjectDetailItems),
|
||||||
registries.kubeObjectDetailRegistry.add(...extension.kubeObjectDetailItems),
|
])
|
||||||
])
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isEnabledInStore(ext: LensExtension) {
|
protected autoEnableExtensions(register: (ext: LensExtension) => Function[]) {
|
||||||
const extensionState = this.state.get(ext.id);
|
|
||||||
return !extensionState /*enabled by default*/ || extensionState.isEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected handleActivation(ext: LensExtension, addToRegistry: () => Function[]) {
|
|
||||||
const enabledInStore = this.isEnabledInStore(ext);
|
|
||||||
if (enabledInStore) {
|
|
||||||
this.disposers.set(ext.id, addToRegistry())
|
|
||||||
} else {
|
|
||||||
this.disposers.get(ext.id)?.forEach(dispose => dispose())
|
|
||||||
this.disposers.delete(ext.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected autoEnableExtensions(callback: (ext: LensExtension) => void) {
|
|
||||||
return autorun(() => {
|
return autorun(() => {
|
||||||
this.instances.forEach(ext => {
|
this.instances.forEach(ext => {
|
||||||
const isEnabled = this.isEnabledInStore(ext);
|
const extensionState = this.state.get(ext.id);
|
||||||
|
const isEnabled = !extensionState /*enabled by default*/ || extensionState.isEnabled;
|
||||||
|
const isRegistered = this.disposers.has(ext.id);
|
||||||
|
if (isEnabled && !isRegistered) {
|
||||||
|
this.disposers.set(ext.id, register(ext))
|
||||||
|
} else if (!isEnabled && isRegistered) {
|
||||||
|
this.disposers.get(ext.id).forEach(dispose => dispose())
|
||||||
|
this.disposers.delete(ext.id)
|
||||||
|
}
|
||||||
ext.toggle(isEnabled);
|
ext.toggle(isEnabled);
|
||||||
callback(ext);
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user