public void showMessageBox(NKE_BrowserWindow browserWindow, Dictionary <string, object> options, NKScriptValue callback)
        {
            string title   = NKOptions.itemOrDefault(options, "title", "");
            string message = NKOptions.itemOrDefault(options, "message", "");

            string[] buttonArray = NKOptions.itemOrDefault(options, "buttons", new string[] { "OK" });
            string   detail      = NKOptions.itemOrDefault(options, "detail", "");

            MessageDialog msgbox = new MessageDialog(message, title);

            msgbox.Commands.Clear();
            int count = 0;

            foreach (var item in buttonArray)
            {
                msgbox.Commands.Add(new UICommand {
                    Label = item, Id = count++
                });
            }

            var t = msgbox.ShowAsync();

            if (callback != null)
            {
                t.AsTask().ContinueWith((u) => callback.callWithArguments(new object[] { u.Result.Label }));
            }
        }
Esempio n. 2
0
        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);
        }
        public void showMessageBox(NKE_BrowserWindow browserWindow, Dictionary <string, object> options, NKScriptValue callback)
        {
            string caption = NKOptions.itemOrDefault(options, "title", "");
            string message = NKOptions.itemOrDefault(options, "message", "");

            string [] buttonArray = NKOptions.itemOrDefault(options, "buttons", new string[] { "OK" });
            string    detail      = NKOptions.itemOrDefault(options, "detail", "");

            MessageBoxImage icon;

            switch (detail)
            {
            case "info":
                icon = MessageBoxImage.Information;
                break;

            case "warning":
                icon = MessageBoxImage.Warning;
                break;

            case "error":
                icon = MessageBoxImage.Error;
                break;

            default:
                icon = MessageBoxImage.None;
                break;
            }

            MessageBoxButton buttons = buttons = MessageBoxButton.OK;

            if ((Array.IndexOf(buttonArray, "OK") > -1) && (Array.IndexOf(buttonArray, "Cancel") > -1))
            {
                buttons = MessageBoxButton.OKCancel;
            }
            else if (Array.IndexOf(buttonArray, "OK") > -1)
            {
                buttons = MessageBoxButton.OK;
            }
            else if ((Array.IndexOf(buttonArray, "Yes") > -1) && (Array.IndexOf(buttonArray, "No") > -1) && (Array.IndexOf(buttonArray, "Cancel") > -1))
            {
                buttons = MessageBoxButton.YesNoCancel;
            }
            else if ((Array.IndexOf(buttonArray, "Yes") > -1) && (Array.IndexOf(buttonArray, "No") > -1))
            {
                buttons = MessageBoxButton.YesNo;
            }

            MessageBoxResult result = MessageBox.Show(message, caption, buttons, icon);

            if (callback != null)
            {
                callback.callWithArguments(new object[] { result.ToString() });
            }
        }
Esempio n. 4
0
        protected async Task LoadPluginBase <T>(T plugin, string ns, Dictionary <string, object> options) where T : class
        {
            bool mainThread    = (bool)options["NKS.MainThread"];
            bool remoteProcess = NKOptions.itemOrDefault(options, "NKS.RemoteProcess", false);

            NKScriptExportType      bridge = (NKScriptExportType)options["NKS.PluginBridge"];
            NKScriptChannelProtocol channel;

            switch (bridge)
            {
            case NKScriptExportType.NKScriptExport:
                if (remoteProcess)
                {
                    channel = new NKScriptChannelRemote((NKScriptContext)this);
                }
                else if (mainThread)
                {
                    channel = new NKScriptChannel((NKScriptContext)this, (TaskScheduler)options["NKS.MainThreadScheduler"]);
                }
                else
                {
                    channel = new NKScriptChannel((NKScriptContext)this);
                }
                var scriptValue = await channel.bindPlugin <T>(plugin, ns);

                _injectedPlugins.Add(scriptValue);

                NKLogging.log("+NKScripting Plugin loaded at " + ns);
                break;

            case NKScriptExportType.NKScriptExportRemote:
                if (mainThread)
                {
                    channel = new NKScriptChannelRemote((NKScriptContext)this, (TaskScheduler)options["NKS.MainThreadScheduler"]);
                }
                else
                {
                    channel = new NKScriptChannelRemote((NKScriptContext)this);
                }
                var scriptValueRemote = await channel.bindPlugin <T>(plugin, ns);

                _injectedPlugins.Add(scriptValueRemote);

                NKLogging.log("+NKScripting Remote Plugin loaded at " + ns);
                break;

            default:
                throw new InvalidOperationException("Load Plugin Base called for non-handled bridge type");
            }
        }