mirror of
https://github.com/laurent22/joplin.git
synced 2025-03-11 14:09:55 +02:00
Plugins: Fixed import API
Ref: https://discourse.joplinapp.org/t/prompt-when-the-plugin-is-running-typeerror-this-module-oninit-is-not-a-function/20009/14
This commit is contained in:
parent
973121addd
commit
736bbbd8ed
@ -64,7 +64,7 @@ packages/tools/PortableAppsLauncher
|
||||
packages/fork-*
|
||||
plugin_types/
|
||||
readme/
|
||||
commands/index.ts
|
||||
**/commands/index.ts
|
||||
|
||||
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
|
||||
packages/app-cli/app/LinkSelector.d.ts
|
||||
@ -886,6 +886,9 @@ packages/lib/JoplinServerApi.js.map
|
||||
packages/lib/Logger.d.ts
|
||||
packages/lib/Logger.js
|
||||
packages/lib/Logger.js.map
|
||||
packages/lib/ObjectUtils.d.ts
|
||||
packages/lib/ObjectUtils.js
|
||||
packages/lib/ObjectUtils.js.map
|
||||
packages/lib/PoorManIntervals.d.ts
|
||||
packages/lib/PoorManIntervals.js
|
||||
packages/lib/PoorManIntervals.js.map
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -871,6 +871,9 @@ packages/lib/JoplinServerApi.js.map
|
||||
packages/lib/Logger.d.ts
|
||||
packages/lib/Logger.js
|
||||
packages/lib/Logger.js.map
|
||||
packages/lib/ObjectUtils.d.ts
|
||||
packages/lib/ObjectUtils.js
|
||||
packages/lib/ObjectUtils.js.map
|
||||
packages/lib/PoorManIntervals.d.ts
|
||||
packages/lib/PoorManIntervals.js
|
||||
packages/lib/PoorManIntervals.js.map
|
||||
|
@ -1,6 +1,4 @@
|
||||
const ObjectUtils = {};
|
||||
|
||||
ObjectUtils.sortByValue = function(object) {
|
||||
export function sortByValue(object: any) {
|
||||
const temp = [];
|
||||
for (const k in object) {
|
||||
if (!object.hasOwnProperty(k)) continue;
|
||||
@ -19,16 +17,16 @@ ObjectUtils.sortByValue = function(object) {
|
||||
return v1 < v2 ? -1 : +1;
|
||||
});
|
||||
|
||||
const output = {};
|
||||
const output: any = {};
|
||||
for (let i = 0; i < temp.length; i++) {
|
||||
const item = temp[i];
|
||||
output[item.key] = item.value;
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
}
|
||||
|
||||
ObjectUtils.fieldsEqual = function(o1, o2) {
|
||||
export function fieldsEqual(o1: any, o2: any) {
|
||||
if ((!o1 || !o2) && o1 !== o2) return false;
|
||||
|
||||
for (const k in o1) {
|
||||
@ -42,10 +40,10 @@ ObjectUtils.fieldsEqual = function(o1, o2) {
|
||||
if (c1.length !== c2.length) return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
ObjectUtils.convertValuesToFunctions = function(o) {
|
||||
const output = {};
|
||||
export function convertValuesToFunctions(o: any) {
|
||||
const output: any = {};
|
||||
for (const n in o) {
|
||||
if (!o.hasOwnProperty(n)) continue;
|
||||
output[n] = () => {
|
||||
@ -53,11 +51,26 @@ ObjectUtils.convertValuesToFunctions = function(o) {
|
||||
};
|
||||
}
|
||||
return output;
|
||||
};
|
||||
}
|
||||
|
||||
ObjectUtils.isEmpty = function(o) {
|
||||
export function isEmpty(o: any) {
|
||||
if (!o) return true;
|
||||
return Object.keys(o).length === 0 && o.constructor === Object;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = ObjectUtils;
|
||||
// export function isStringifiable(o:any):boolean {
|
||||
// if (o === null || o === undefined) return true;
|
||||
|
||||
// if (Array.isArray(o)) {
|
||||
// for (const e of o) {
|
||||
// if (!isStringifiable(e)) return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// if (typeof o === 'object') {
|
||||
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// }
|
@ -5,27 +5,28 @@ import { ImportExportResult } from './types';
|
||||
import Setting from '../../models/Setting';
|
||||
|
||||
export default class InteropService_Importer_Base {
|
||||
|
||||
private metadata_: any = null;
|
||||
protected sourcePath_: string = '';
|
||||
protected options_: any = {};
|
||||
|
||||
setMetadata(md: any) {
|
||||
public setMetadata(md: any) {
|
||||
this.metadata_ = md;
|
||||
}
|
||||
|
||||
metadata() {
|
||||
public metadata() {
|
||||
return this.metadata_;
|
||||
}
|
||||
|
||||
async init(sourcePath: string, options: any) {
|
||||
public async init(sourcePath: string, options: any) {
|
||||
this.sourcePath_ = sourcePath;
|
||||
this.options_ = options;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
async exec(result: ImportExportResult): Promise<ImportExportResult> {}
|
||||
public async exec(result: ImportExportResult): Promise<ImportExportResult> {}
|
||||
|
||||
async temporaryDirectory_(createIt: boolean) {
|
||||
protected async temporaryDirectory_(createIt: boolean) {
|
||||
const md5 = require('md5');
|
||||
const tempDir = `${Setting.value('tempDir')}/${md5(Math.random() + Date.now())}`;
|
||||
if (createIt) await require('fs-extra').mkdirp(tempDir);
|
||||
|
@ -5,15 +5,27 @@ export default class InteropService_Importer_Custom extends InteropService_Impor
|
||||
|
||||
private module_: Module = null;
|
||||
|
||||
constructor(handler: Module) {
|
||||
public constructor(handler: Module) {
|
||||
super();
|
||||
this.module_ = handler;
|
||||
}
|
||||
|
||||
async exec(result: ImportExportResult): Promise<ImportExportResult> {
|
||||
public async exec(result: ImportExportResult): Promise<ImportExportResult> {
|
||||
// When passing the options to the plugin, we strip off any function
|
||||
// because they won't serialized over ipc.
|
||||
|
||||
const processedOptions: any = {};
|
||||
|
||||
if (this.options_) {
|
||||
for (const [k, v] of Object.entries(this.options_)) {
|
||||
if (typeof v === 'function') continue;
|
||||
processedOptions[k] = v;
|
||||
}
|
||||
}
|
||||
|
||||
return this.module_.onExec({
|
||||
sourcePath: this.sourcePath_,
|
||||
options: this.options_,
|
||||
options: processedOptions,
|
||||
warnings: result.warnings,
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user