1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/lib/services/plugins/api/Global.ts

88 lines
2.2 KiB
TypeScript
Raw Normal View History

import Plugin from '../Plugin';
import Joplin from './Joplin';
/**
* @ignore
*/
2021-01-27 19:42:58 +02:00
// const builtinModules = require('builtin-modules');
/**
* @ignore
*/
export default class Global {
private joplin_: Joplin;
2021-01-27 19:42:58 +02:00
// private requireWhiteList_: string[] = null;
// private consoleWrapper_:any = null;
constructor(implementation: any, plugin: Plugin, store: any) {
this.joplin_ = new Joplin(implementation.joplin, plugin, store);
// 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_;
// }
// 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);
// }
// 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.
get process(): any {
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);
// }
}