mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
auto enable/disable extensions -- part 3
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
7de278f8b5
commit
42cf0b0529
@ -50,15 +50,6 @@ export class ExtensionLoader extends BaseStore<ExtensionLoaderStoreModel> {
|
|||||||
return [...this.instances.values()].filter(ext => !ext.isBundled)
|
return [...this.instances.values()].filter(ext => !ext.isBundled)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected handleActivation(ext: LensExtension, addToRegistry: () => Function[]) {
|
|
||||||
if (ext.isEnabled) {
|
|
||||||
this.disposers.set(ext.id, addToRegistry())
|
|
||||||
} else {
|
|
||||||
this.disposers.get(ext.id)?.forEach(dispose => dispose())
|
|
||||||
this.disposers.delete(ext.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadOnMain() {
|
loadOnMain() {
|
||||||
logger.info('[EXTENSIONS-LOADER]: load on main')
|
logger.info('[EXTENSIONS-LOADER]: load on main')
|
||||||
this.autoInitExtensions();
|
this.autoInitExtensions();
|
||||||
@ -94,18 +85,27 @@ export class ExtensionLoader extends BaseStore<ExtensionLoaderStoreModel> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected isEnabledInStore(ext: LensExtension) {
|
||||||
|
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) {
|
protected autoEnableExtensions(callback: (ext: LensExtension) => void) {
|
||||||
return autorun(() => {
|
return autorun(() => {
|
||||||
this.instances.forEach(ext => {
|
this.instances.forEach(ext => {
|
||||||
const extensionState = this.state.get(ext.id);
|
const isEnabled = this.isEnabledInStore(ext);
|
||||||
const enabledInStore = !extensionState /*enabled by default*/ || extensionState.isEnabled;
|
ext.toggle(isEnabled);
|
||||||
if (!ext.isEnabled && enabledInStore) {
|
callback(ext);
|
||||||
ext.enable();
|
|
||||||
callback(ext);
|
|
||||||
} else if (ext.isEnabled && !enabledInStore) {
|
|
||||||
ext.disable();
|
|
||||||
callback(ext);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user