コード例 #1
0
        async private Task prepareForPlugin()
        {
            if (preparationComplete) return;
            try
            {
                context.setNKScriptChannel(this);
                var source = await getResource("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 script.inject(context);
                          
                preparationComplete = true;
            }
            catch 
            {
                 preparationComplete = false;
            }

            var source2 = await getResource("promise.js", "lib");
            var script2 = new NKScriptSource(source2, "io.nodekit.scripting/NKScripting/promise.js", "Promise", null);
            await script2.inject(context);

            if (preparationComplete)
              NKLogging.log(String.Format("+E{0} JavaScript Engine is ready for loading plugins", context.NKid));
            else
                NKLogging.log(String.Format("+E{0} JavaScript Engine could not load NKScripting.js", context.NKid));

        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);

        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: codeplayer14/nodekit-windows
        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);
        }
コード例 #6
0
        protected override Task InjectScript(NKScriptSource script)
        {
            if (_isLoaded)
            {
                return(this.NKevaluateJavaScript(script.source, script.filename));
            }

            // otherwise will be injected in completeInitialization;
            return(Task.FromResult <object>(null));
        }
コード例 #7
0
        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);

        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public async Task<NKScriptValue> bindPlugin(object obj, string ns)
        {
            await this.prepareForPlugin();
            if ((this.id != null) || (context == null) ) return null;
            if (this.userContentController == null) return null;

            this.id = (this.sequenceNumber++).ToString();
         
            this.userContentController.NKaddScriptMessageHandler(this, id);

            if (obj.GetType() == typeof(Type))
            {
                // Class, not instance, passed to bindPlugin -- to be used in Factory constructor/instance pattern in js
                isFactory = true;
                typeInfo = new NKScriptTypeInfo((Type)obj);
                // Need to store the channel on the class itself so it can be found when native construct requests come in from other plugins
                obj.setNKScriptChannel(this);
            }
            else {
                // Instance of Princpal passed to bindPlugin -- to be used in singleton/static pattern in js
                isFactory = false;
                typeInfo = new NKScriptTypeInfo(obj.GetType());
            }

            _principal = new NKScriptValueNative(ns, this, obj);
            this.instances[0] = _principal;

            var script = new NKScriptSource(_generateStubs(typeInfo.Name), ns + "/plugin/" + typeInfo.Name + ".js");
            NKLogging.log(script.source);
            await script.inject(context);

            return _principal;
        }
コード例 #11
0
        protected override async Task LoadPlugin <T>(T plugin, string ns, Dictionary <string, object> options)
        {
            bool mainThread           = (bool)options["NKS.MainThread"];
            NKScriptExportType bridge = (NKScriptExportType)options["NKS.PluginBridge"];

            switch (bridge)
            {
            case NKScriptExportType.JSExport:
                throw new NotSupportedException("JSExport option is for darwin platforms only");

            case NKScriptExportType.WinRT:

                if (plugin == null)
                {
                    switchContextifNeeded();
                    if (!_projectedNamespaces.Contains(ns))
                    {
                        Native.ThrowIfError(Native.JsProjectWinRTNamespace(ns));
                        _projectedNamespaces.Add(ns);
                        NKLogging.log("+Windows Unversal Component namespace loaded at " + ns);
                    }
                }
                else if (typeof(T) != typeof(Type))
                {
                    throw new ArgumentException("Windows Universal Components can only be provided as a type");
                }
                else
                {
                    var t = (plugin as Type);
                    var projectionNamespace = t.Namespace;
                    var projectionName      = t.Name;
                    var projectionFullName  = projectionNamespace + "." + projectionName;
                    var targetNamespace     = ns;

                    switchContextifNeeded();
                    if (!_projectedNamespaces.Contains(projectionNamespace))
                    {
                        Native.ThrowIfError(Native.JsProjectWinRTNamespace(projectionNamespace));
                        _projectedNamespaces.Add(projectionNamespace);
                    }

                    var cs            = new NKScriptExportProxy <T>(plugin);
                    var localstub     = cs.rewriteGeneratedStub("", ".local");
                    var globalstubber = "(function(exports) {\n" + localstub + "})(NKScripting.createProjection('" + targetNamespace + "', " + projectionFullName + "));\n";
                    var globalstub    = cs.rewriteGeneratedStub(globalstubber, ".global");

                    var script = new NKScriptSource(globalstub, targetNamespace + "/plugin/" + projectionName + ".js");
                    await this.NKinjectScript(script);

                    await cs.initializeForContext(this);

                    plugin.setNKScriptValue(this.NKgetScriptValue(targetNamespace));

                    NKLogging.log("+Windows Unversal Component Plugin with script loaded at " + targetNamespace);
                }
                break;

            default:
                throw new NotImplementedException("Unknown Scripting Plugin Bridge Option");
            }
        }
コード例 #12
0
 protected override Task InjectScript(NKScriptSource script)
 {
     return(this.NKevaluateJavaScript(script.source, script.filename));
 }
コード例 #13
0
 protected override Task InjectScript(NKScriptSource script)
 {
     // silently ignore:  script injections also handled in main process.
     return(Task.FromResult <object>(null));
 }