2020-10-09 19:35:46 +02:00
|
|
|
import Plugin from '../Plugin';
|
|
|
|
import Joplin from './Joplin';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
2021-01-27 19:42:58 +02:00
|
|
|
// const builtinModules = require('builtin-modules');
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
export default class Global {
|
|
|
|
|
|
|
|
private joplin_: Joplin;
|
2021-01-27 19:42:58 +02:00
|
|
|
// private requireWhiteList_: string[] = null;
|
2020-10-09 19:35:46 +02:00
|
|
|
// private consoleWrapper_:any = null;
|
|
|
|
|
2020-11-19 17:25:02 +02:00
|
|
|
constructor(implementation: any, plugin: Plugin, store: any) {
|
|
|
|
this.joplin_ = new Joplin(implementation.joplin, plugin, store);
|
2020-10-09 19:35:46 +02:00
|
|
|
// this.consoleWrapper_ = this.createConsoleWrapper(plugin.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wraps console calls to allow prefixing them with "Plugin PLUGIN_ID:"
|
|
|
|
// private createConsoleWrapper(pluginId:string) {
|
|
|
|
// const wrapper:any = {};
|
|
|
|
|
|
|
|
// for (const n in console) {
|
|
|
|
// if (!console.hasOwnProperty(n)) continue;
|
|
|
|
// wrapper[n] = (...args:any[]) => {
|
|
|
|
// const newArgs = args.slice();
|
|
|
|
// newArgs.splice(0, 0, `Plugin "${pluginId}":`);
|
|
|
|
// return (console as any)[n](...newArgs);
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return wrapper;
|
|
|
|
// }
|
|
|
|
|
|
|
|
get joplin(): Joplin {
|
|
|
|
return this.joplin_;
|
|
|
|
}
|
|
|
|
|
2021-01-27 19:42:58 +02:00
|
|
|
// private requireWhiteList(): string[] {
|
|
|
|
// if (!this.requireWhiteList_) {
|
|
|
|
// this.requireWhiteList_ = builtinModules.slice();
|
|
|
|
// this.requireWhiteList_.push('fs-extra');
|
|
|
|
// }
|
|
|
|
// return this.requireWhiteList_;
|
|
|
|
// }
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
// get console(): any {
|
|
|
|
// return this.consoleWrapper_;
|
|
|
|
// }
|
|
|
|
|
2021-01-27 19:42:58 +02:00
|
|
|
// require(filePath: string): any {
|
|
|
|
// if (!this.requireWhiteList().includes(filePath)) throw new Error(`Path not allowed: ${filePath}`);
|
|
|
|
// return require(filePath);
|
|
|
|
// }
|
2020-10-09 19:35:46 +02:00
|
|
|
|
|
|
|
// To get webpack to work with Node module we need to set the parameter `target: "node"`, however
|
|
|
|
// when setting this, the code generated by webpack will try to access the `process` global variable,
|
|
|
|
// which won't be defined in the sandbox. So here we simply forward the variable, which makes it all work.
|
2020-11-12 21:13:28 +02:00
|
|
|
get process(): any {
|
2020-10-09 19:35:46 +02:00
|
|
|
return process;
|
|
|
|
}
|
|
|
|
|
|
|
|
// setTimeout(fn: Function, interval: number) {
|
|
|
|
// return shim.setTimeout(() => {
|
|
|
|
// fn();
|
|
|
|
// }, interval);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// setInterval(fn: Function, interval: number) {
|
|
|
|
// return shim.setInterval(() => {
|
|
|
|
// fn();
|
|
|
|
// }, interval);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// alert(message:string) {
|
|
|
|
// return alert(message);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// confirm(message:string) {
|
|
|
|
// return confirm(message);
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|