import Plugin from '../Plugin'; import Joplin from './Joplin'; /** * @ignore */ // const builtinModules = require('builtin-modules'); /** * @ignore */ export default class Global { private joplin_: Joplin; // 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_; } // private requireWhiteList(): string[] { // if (!this.requireWhiteList_) { // this.requireWhiteList_ = builtinModules.slice(); // this.requireWhiteList_.push('fs-extra'); // } // return this.requireWhiteList_; // } // get console(): any { // return this.consoleWrapper_; // } // 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); // } }