async override protected Task PrepareEnvironment() { if (!_isFirstLoaded) { // var source = await NKStorage.getResourceAsync(typeof(NKScriptContext), "promise.js", "lib"); // var script = new NKScriptSource(source, "io.nodekit.scripting/NKScripting/promise.js", "Promise", null); // this.NKinjectScript(script); var source2 = await NKStorage.getResourceAsync(typeof(NKScriptContext), "init_edge.js", "lib"); var script2 = new NKScriptSource(source2, "io.nodekit.scripting/NKScripting/init_edge.js"); await this.NKinjectScript(script2); } _isLoaded = true; foreach (var item in _injectedScripts) { await this.NKevaluateJavaScript(item.source, item.filename); } if (!_isFirstLoaded) { _isFirstLoaded = true; this.tcs.SetResult(this); } }
public async static Task bootCore(NKScriptContext context, Dictionary <string, object> options) { // FINALLY LOAD BOOTSTRAP CODE AFTER ALL PLATFORM PLUGINS var appjs = await NKStorage.getResourceAsync(typeof(Main), "_nodekit_bootstrapper.js", "lib"); var script = "function loadbootstrap(){\n" + appjs + "\n}\n" + "loadbootstrap();" + "\n"; var scriptsource = new NKScriptSource(script, "io.nodekit.core/lib-core/_nodekit_bootstrapper.js", "io.nodekit.core.bootstrapper"); await context.NKinjectScript(scriptsource); }
public async static Task addElectro(NKScriptContext context, Dictionary <string, object> options) { var appjs = await NKStorage.getResourceAsync(typeof(Main), "_nke_main.js", "lib_electro"); var script = "function loadbootstrap(){\n" + appjs + "\n}\n" + "loadbootstrap();" + "\n"; var scriptsource = new NKScriptSource(script, "io.nodekit.electro/lib-electro/_nke_main.js", "io.nodekit.electro.main"); await context.NKinjectScript(scriptsource); bool multiProcess = NKOptions.itemOrDefault <bool>(options, "NKS.RemoteProcess", false); var optionsDefault = new Dictionary <string, object> { ["NKS.PluginBridge"] = NKScriptExportType.NKScriptExport }; var optionsMulti = new Dictionary <string, object> { ["NKS.PluginBridge"] = NKScriptExportType.NKScriptExport, ["NKS.RemoteProcess"] = true }; var optionsMain = new Dictionary <string, object> { ["NKS.PluginBridge"] = NKScriptExportType.NKScriptExport, ["NKS.MainThread"] = true, ["NKS.MainThreadId"] = (int)options["NKS.MainThreadId"], ["NKS.MainThreadScheduler"] = (TaskScheduler)options["NKS.MainThreadScheduler"] }; await context.NKloadPlugin(typeof(NKE_App), null, optionsDefault); if (!multiProcess) { await NKE_BrowserWindow.attachToContext(context, optionsMain); } else { await NKE_BrowserWindow.attachToContext(context, optionsMulti); } if (!multiProcess) { await NKE_WebContents.attachToContext(context, optionsMain); } else { await NKE_WebContents.attachToContext(context, optionsMulti); } await NKE_Dialog.attachToContext(context, optionsMain); await NKE_IpcMain.attachToContext(context, optionsDefault); // NKE_Menu.attachTo(context); // NKE_Protocol.attachTo(context); }
private static string rewriteGeneratedStub(string stub, string forKey) { switch (forKey) { case ".global": var appjs = NKStorage.getResource(typeof(NKE_IpcMain), "ipcmain.js", "lib_electro"); return("function loadplugin(){\n" + appjs + "\n}\n" + stub + "\n" + "loadplugin();" + "\n"); default: return(stub); } }
private static string rewriteGeneratedStub(string stub, string forKey) { switch (forKey) { case ".global": var appjs = NKStorage.getResource(typeof(NKC_Console), "console.js", "lib/platform"); return("function loadplugin(){\n" + appjs + "\n}\n" + stub + "\n" + "loadplugin();" + "\n"); default: return(stub); } }
public async static Task addElectro(NKScriptContext context, Dictionary <string, object> options) { var appjs = await NKStorage.getResourceAsync(typeof(Renderer), "_nke_renderer.js", "lib_electro"); var script = "function loadbootstrap(){\n" + appjs + "\n}\n" + "loadbootstrap();" + "\n"; var scriptsource = new NKScriptSource(script, "io.nodekit.electro/lib-electro/_nke_renderer.js", "io.nodekit.electro.renderer"); await context.NKinjectScript(scriptsource); var optionsDefault = new Dictionary <string, object> { ["NKS.PluginBridge"] = NKScriptExportType.NKScriptExport }; await NKE_IpcRenderer.attachToContext(context, optionsDefault); }
private static string rewriteGeneratedStub(string stub, string forKey) { switch (forKey) { case ".global": var appjs = NKStorage.getResource(typeof(NKC_Process), "process.js", "lib/platform"); // UNIQUE SCRIPT FOR PROCESS return("function loadplugin(){\n" + "this.process = this.process || Object.create(null);\n" + NKC_Process.syncProcessDictionary() + "\n" + appjs + "\n}\n" + stub + "\n" + "loadplugin();" + "\n"); // return "function loadplugin(){\n" + appjs + "\n}\n" + stub + "\n" + "loadplugin();" + "\n"; default: return(stub); } }
async override protected Task PrepareEnvironment() { switchContextifNeeded(); var global = JavaScriptValue.GlobalObject; var NKScripting = global.GetProperty(JavaScriptPropertyId.FromString("NKScripting")); // var source = await NKStorage.getResourceAsync(typeof(NKScriptContext), "promise.js", "lib"); // var script = new NKScriptSource(source, "io.nodekit.scripting/NKScripting/promise.js", "Promise", null); // await script.inject(this); _webViewScriptDelegate = new NKSChakraScriptDelegate(this); await _webViewScriptDelegate.createBridge(); var source2 = await NKStorage.getResourceAsync(typeof(NKScriptContext), "init_chakra.js", "lib"); var script2 = new NKScriptSource(source2, "io.nodekit.scripting/NKScripting/init_chakra.js"); await this.NKinjectScript(script2); }
async public Task <NKScriptContext> completeInitialization() { if (preparationComplete) { return(this); } try { var source = await NKStorage.getResourceAsync(typeof(NKScriptContext), "nkscripting.js", "lib"); if (source == null) { throw new FileNotFoundException("Could not find file nkscripting.js"); } var script = new NKScriptSource(source, "io.nodekit.scripting/NKScripting/nkscripting.js", "NKScripting", null); await this.NKinjectScript(script); await ensureOnEngineThread(async() => { await PrepareEnvironment(); preparationComplete = true; }).Unwrap(); } catch { preparationComplete = false; } if (preparationComplete) { NKLogging.log(String.Format("+E{0} JavaScript Engine is ready for loading plugins", this.NKid)); } else { NKLogging.log(String.Format("+E{0} JavaScript Engine could not load NKScripting.js", this.NKid)); } return(this); }