1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-24 23:26:50 +02:00

Plugins: Add support for plugins.dataDir function, to provide a path for plugin to store its own data

This commit is contained in:
Laurent Cozic
2021-01-24 15:51:35 +00:00
parent 257cde4383
commit cbd842c268
7 changed files with 55 additions and 15 deletions

View File

@ -33,12 +33,15 @@ export default class Plugin {
private devMode_: boolean = false;
private messageListener_: Function = null;
private contentScriptMessageListeners_: Record<string, Function> = {};
private dataDir_: string;
private dataDirCreated_: boolean = false;
constructor(baseDir: string, manifest: PluginManifest, scriptText: string, dispatch: Function) {
constructor(baseDir: string, manifest: PluginManifest, scriptText: string, dispatch: Function, dataDir: string) {
this.baseDir_ = shim.fsDriver().resolve(baseDir);
this.manifest_ = manifest;
this.scriptText_ = scriptText;
this.dispatch_ = dispatch;
this.dataDir_ = dataDir;
this.eventEmitter_ = new EventEmitter();
}
@ -66,6 +69,17 @@ export default class Plugin {
return this.baseDir_;
}
public async dataDir(): Promise<string> {
if (this.dataDirCreated_) return this.dataDir_;
if (!(await shim.fsDriver().exists(this.dataDir_))) {
await shim.fsDriver().mkdir(this.dataDir_);
this.dataDirCreated_ = true;
}
return this.dataDir_;
}
public get viewCount(): number {
return Object.keys(this.viewControllers_).length;
}
@ -157,5 +171,4 @@ export default class Plugin {
return this.contentScriptMessageListeners_[id](message);
}
}