Add designated folder for extensions (#1245)

* add store for mapping extension names to filesystem paths

- add extension mechinism for getting a folder to save files to

- add test to make sure that extensions are being loaded

- skip extension loading test

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2020-11-24 10:28:08 -05:00
1 parent b94e523ad5
commit 4e6b8ee10e
9 files changed
+119 -32

No files matched your search

+12 -8
View File
@@ -131,21 +131,25 @@ export class ExtensionLoader {
protected autoInitExtensions(register: (ext: LensExtension) => Promise<Function[]>) {
return reaction(() => this.toJSON(), installedExtensions => {
for (const [extId, ext] of installedExtensions) {
let instance = this.instances.get(extId);
if (ext.isEnabled && !instance) {
const alreadyInit = this.instances.has(extId);
if (ext.isEnabled && !alreadyInit) {
try {
const LensExtensionClass: LensExtensionConstructor = this.requireExtension(ext);
if (!LensExtensionClass) continue;
instance = new LensExtensionClass(ext);
const LensExtensionClass = this.requireExtension(ext);
if (!LensExtensionClass) {
continue;
}
const instance = new LensExtensionClass(ext);
instance.whenEnabled(() => register(instance));
instance.enable();
this.instances.set(extId, instance);
} catch (err) {
logger.error(`${logModule}: activation extension error`, { ext, err });
}
} else if (!ext.isEnabled && instance) {
logger.info(`${logModule} deleting extension ${extId}`);
} else if (!ext.isEnabled && alreadyInit) {
try {
const instance = this.instances.get(extId);
instance.disable();
this.instances.delete(extId);
} catch (err) {
@@ -158,7 +162,7 @@ export class ExtensionLoader {
});
}
protected requireExtension(extension: InstalledExtension) {
protected requireExtension(extension: InstalledExtension): LensExtensionConstructor {
let extEntrypoint = "";
try {
if (ipcRenderer && extension.manifest.renderer) {
+12
View File
@@ -1,5 +1,6 @@
import type { InstalledExtension } from "./extension-discovery";
import { action, observable, reaction } from "mobx";
import { filesystemProvisionerStore } from "../main/extension-filesystem";
import logger from "../main/logger";
export type LensExtensionId = string; // path to manifest (package.json)
@@ -39,6 +40,17 @@ export class LensExtension {
return this.manifest.version;
}
/**
* getExtensionFileFolder returns the path to an already created folder. This
* folder is for the sole use of this extension.
*
* Note: there is no security done on this folder, only obfiscation of the
* folder name.
*/
async getExtensionFileFolder(): Promise<string> {
return filesystemProvisionerStore.requestDirectory(this.id);
}
get description() {
return this.manifest.description;
}