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 }));
            }
        }
Example #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() });
            }
        }
        public NKE_WebContents(NKE_BrowserWindow browserWindow)
        {
            this._browserWindow = browserWindow;
            this._id = browserWindow.id;

            // Event:  'did-fail-load'
            // Event:  'did-finish-load'

            browserWindow.events.on<int>("NKE.DidFinishLoad", (e, id) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new[] { "did-finish-load" });
            });

            browserWindow.events.on<Tuple<int, string>>("NKE.DidFailLoading", (e, item) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new[] { "did-fail-loading", item.Item2 });
            });
        }
Example #5
0
        public NKE_WebContents(NKE_BrowserWindow browserWindow)
        {
            this._browserWindow = browserWindow;
            this._id            = browserWindow.id;

            // Event:  'did-fail-load'
            // Event:  'did-finish-load'

            browserWindow.events.on <int>("NKE.DidFinishLoad", (e, id) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new[] { "did-finish-load" });
            });

            browserWindow.events.on <Tuple <int, string> >("NKE.DidFailLoading", (e, item) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new[] { "did-fail-loading", item.Item2 });
            });
        }
       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", "");

            MessageBoxIcon icon;
            switch (detail)
            {
                case "info":
                    icon = MessageBoxIcon.Information;
                    break;
                case "warning":
                    icon = MessageBoxIcon.Warning;
                    break;
                case "error":
                    icon = MessageBoxIcon.Error;
                    break;
                default:
                    icon = MessageBoxIcon.None;
                    break;
            }
            
            MessageBoxButtons buttons = buttons = MessageBoxButtons.OK;

            if ((Array.IndexOf(buttonArray, "OK") > -1) && (Array.IndexOf(buttonArray, "Cancel") > -1))
                buttons = MessageBoxButtons.OKCancel;
            else if (Array.IndexOf(buttonArray, "OK") > -1)
                   buttons = MessageBoxButtons.OK;
            else if ((Array.IndexOf(buttonArray, "Abort") > -1) && (Array.IndexOf(buttonArray, "Retry") > -1) && (Array.IndexOf(buttonArray, "Ignore") > -1))
                buttons = MessageBoxButtons.AbortRetryIgnore;
            else if ((Array.IndexOf(buttonArray, "Yes") > -1) && (Array.IndexOf(buttonArray, "No") > -1) && (Array.IndexOf(buttonArray, "Cancel") > -1))
                buttons = MessageBoxButtons.YesNoCancel;
            else if ((Array.IndexOf(buttonArray, "Yes") > -1) && (Array.IndexOf(buttonArray, "No") > -1))
                buttons = MessageBoxButtons.YesNo;
            else if ((Array.IndexOf(buttonArray, "Retry") > -1) && (Array.IndexOf(buttonArray, "Cancel") > -1))
                buttons = MessageBoxButtons.RetryCancel;

            DialogResult result = MessageBox.Show(message, caption, buttons, icon);
            if (callback != null)
                 callback.callWithArguments(new object[] { result.ToString() });
        }
Example #7
0
        public NKE_IpcRenderer(int id)
        {
            _id = id;
            // IPC Renderer runs in same process as NKE BrowserWindow so can get actual host object
            _window = NKE_BrowserWindow.fromId(id);

            string ids = id.ToString();

            // Renderer IPC messags coem in on WebContents object running in same process
            _window.events.on <NKEvent>("NKE.IPCtoRenderer", (e, item) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new object[] { "NKE.IPCtoRenderer", item.sender, item.channel, item.replyId, item.arg });
            });

            // Main process replies to renderer come in on global events queue which can run cross channel
            globalEvents.on <NKEvent>("NKE.IPCReplytoRenderer." + ids, (e, item) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new object[] { "NKE.IPCReplytoRenderer", item.sender, item.channel, item.replyId, item.arg });
            });
        }
        public NKE_IpcRenderer(int id)
        {
            _id = id;
            // IPC Renderer runs in same process as NKE BrowserWindow so can get actual host object
            _window = NKE_BrowserWindow.fromId(id);

            string ids = id.ToString();

            // Renderer IPC messags coem in on WebContents object running in same process
            _window.events.on<NKEvent>("NKE.IPCtoRenderer", (e, item) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new object[] { "NKE.IPCtoRenderer", item.sender, item.channel, item.replyId, item.arg });
            });

            // Main process replies to renderer come in on global events queue which can run cross channel
            globalEvents.on<NKEvent>("NKE.IPCReplytoRenderer." + ids, (e, item) =>
            {
                this.getNKScriptValue().invokeMethod("emit", new object[] { "NKE.IPCReplytoRenderer", item.sender, item.channel, item.replyId, item.arg });
            });
        }
        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 }));
        }
Example #10
0
        public async static Task addElectroRemoteProxy(NKScriptContext context, Dictionary <string, object> options)
        {
            var optionsDefault = new Dictionary <string, object>
            {
                ["NKS.PluginBridge"]        = NKScriptExportType.NKScriptExport,
                ["NKS.MainThread"]          = true,
                ["NKS.MainThreadId"]        = (int)options["NKS.MainThreadId"],
                ["NKS.MainThreadScheduler"] = (TaskScheduler)options["NKS.MainThreadScheduler"]
            };

            await NKE_BrowserWindow.attachToContext(context, optionsDefault);

            await NKE_WebContents.attachToContext(context, optionsDefault);

            // await context.NKloadPlugin(typeof(NKEDialog), "io.nodekit.electro.dialog", options);

            // NKE_BrowserWindow.attachTo(context);
            // NKE_WebContentsBase.attachTo(context);
            // NKE_Dialog.attachTo(context);
            // NKE_IpcMain.attachTo(context);
            // NKE_Menu.attachTo(context);
            // NKE_Protocol.attachTo(context);
        }
Example #11
0
 public void showSaveDialog(NKE_BrowserWindow browserWindow, Dictionary <string, object> options, NKScriptValue callback)
 {
     throw new NotImplementedException();
 }
 public void showSaveDialog(NKE_BrowserWindow browserWindow, Dictionary<string, object> options, NKScriptValue callback)
  {
      throw new NotImplementedException();
  }