mirror of https://github.com/laurent22/joplin.git
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/14pull/5419/head
parent
973121addd
commit
736bbbd8ed
|
@ -64,7 +64,7 @@ packages/tools/PortableAppsLauncher
|
||||||
packages/fork-*
|
packages/fork-*
|
||||||
plugin_types/
|
plugin_types/
|
||||||
readme/
|
readme/
|
||||||
commands/index.ts
|
**/commands/index.ts
|
||||||
|
|
||||||
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
|
# AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD
|
||||||
packages/app-cli/app/LinkSelector.d.ts
|
packages/app-cli/app/LinkSelector.d.ts
|
||||||
|
@ -886,6 +886,9 @@ packages/lib/JoplinServerApi.js.map
|
||||||
packages/lib/Logger.d.ts
|
packages/lib/Logger.d.ts
|
||||||
packages/lib/Logger.js
|
packages/lib/Logger.js
|
||||||
packages/lib/Logger.js.map
|
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.d.ts
|
||||||
packages/lib/PoorManIntervals.js
|
packages/lib/PoorManIntervals.js
|
||||||
packages/lib/PoorManIntervals.js.map
|
packages/lib/PoorManIntervals.js.map
|
||||||
|
|
|
@ -871,6 +871,9 @@ packages/lib/JoplinServerApi.js.map
|
||||||
packages/lib/Logger.d.ts
|
packages/lib/Logger.d.ts
|
||||||
packages/lib/Logger.js
|
packages/lib/Logger.js
|
||||||
packages/lib/Logger.js.map
|
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.d.ts
|
||||||
packages/lib/PoorManIntervals.js
|
packages/lib/PoorManIntervals.js
|
||||||
packages/lib/PoorManIntervals.js.map
|
packages/lib/PoorManIntervals.js.map
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
const ObjectUtils = {};
|
export function sortByValue(object: any) {
|
||||||
|
|
||||||
ObjectUtils.sortByValue = function(object) {
|
|
||||||
const temp = [];
|
const temp = [];
|
||||||
for (const k in object) {
|
for (const k in object) {
|
||||||
if (!object.hasOwnProperty(k)) continue;
|
if (!object.hasOwnProperty(k)) continue;
|
||||||
|
@ -19,16 +17,16 @@ ObjectUtils.sortByValue = function(object) {
|
||||||
return v1 < v2 ? -1 : +1;
|
return v1 < v2 ? -1 : +1;
|
||||||
});
|
});
|
||||||
|
|
||||||
const output = {};
|
const output: any = {};
|
||||||
for (let i = 0; i < temp.length; i++) {
|
for (let i = 0; i < temp.length; i++) {
|
||||||
const item = temp[i];
|
const item = temp[i];
|
||||||
output[item.key] = item.value;
|
output[item.key] = item.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
};
|
}
|
||||||
|
|
||||||
ObjectUtils.fieldsEqual = function(o1, o2) {
|
export function fieldsEqual(o1: any, o2: any) {
|
||||||
if ((!o1 || !o2) && o1 !== o2) return false;
|
if ((!o1 || !o2) && o1 !== o2) return false;
|
||||||
|
|
||||||
for (const k in o1) {
|
for (const k in o1) {
|
||||||
|
@ -42,10 +40,10 @@ ObjectUtils.fieldsEqual = function(o1, o2) {
|
||||||
if (c1.length !== c2.length) return false;
|
if (c1.length !== c2.length) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
|
|
||||||
ObjectUtils.convertValuesToFunctions = function(o) {
|
export function convertValuesToFunctions(o: any) {
|
||||||
const output = {};
|
const output: any = {};
|
||||||
for (const n in o) {
|
for (const n in o) {
|
||||||
if (!o.hasOwnProperty(n)) continue;
|
if (!o.hasOwnProperty(n)) continue;
|
||||||
output[n] = () => {
|
output[n] = () => {
|
||||||
|
@ -53,11 +51,26 @@ ObjectUtils.convertValuesToFunctions = function(o) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
};
|
}
|
||||||
|
|
||||||
ObjectUtils.isEmpty = function(o) {
|
export function isEmpty(o: any) {
|
||||||
if (!o) return true;
|
if (!o) return true;
|
||||||
return Object.keys(o).length === 0 && o.constructor === Object;
|
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';
|
import Setting from '../../models/Setting';
|
||||||
|
|
||||||
export default class InteropService_Importer_Base {
|
export default class InteropService_Importer_Base {
|
||||||
|
|
||||||
private metadata_: any = null;
|
private metadata_: any = null;
|
||||||
protected sourcePath_: string = '';
|
protected sourcePath_: string = '';
|
||||||
protected options_: any = {};
|
protected options_: any = {};
|
||||||
|
|
||||||
setMetadata(md: any) {
|
public setMetadata(md: any) {
|
||||||
this.metadata_ = md;
|
this.metadata_ = md;
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata() {
|
public metadata() {
|
||||||
return this.metadata_;
|
return this.metadata_;
|
||||||
}
|
}
|
||||||
|
|
||||||
async init(sourcePath: string, options: any) {
|
public async init(sourcePath: string, options: any) {
|
||||||
this.sourcePath_ = sourcePath;
|
this.sourcePath_ = sourcePath;
|
||||||
this.options_ = options;
|
this.options_ = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @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 md5 = require('md5');
|
||||||
const tempDir = `${Setting.value('tempDir')}/${md5(Math.random() + Date.now())}`;
|
const tempDir = `${Setting.value('tempDir')}/${md5(Math.random() + Date.now())}`;
|
||||||
if (createIt) await require('fs-extra').mkdirp(tempDir);
|
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;
|
private module_: Module = null;
|
||||||
|
|
||||||
constructor(handler: Module) {
|
public constructor(handler: Module) {
|
||||||
super();
|
super();
|
||||||
this.module_ = handler;
|
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({
|
return this.module_.onExec({
|
||||||
sourcePath: this.sourcePath_,
|
sourcePath: this.sourcePath_,
|
||||||
options: this.options_,
|
options: processedOptions,
|
||||||
warnings: result.warnings,
|
warnings: result.warnings,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue