public PinWrapper(JSCallback jsCallback)
        {
            m_jsCallback = jsCallback;

            if (m_MbnInterfaceManager == null)
            {
                // Get MbnInterfaceManager
                m_MbnInterfaceManager = (IMbnInterfaceManager)new MbnInterfaceManager();
            }

            // Get the mbn interface
            m_MbnInterface = GetFirstInterface();

            if (m_PinManagerEventsSink == null)
            {
                // Advise for pin manager events
                m_PinManagerEventsSink = new PinManagerEventsSink(this.OnGetPinStateCompleteHandler, GetMbnPinManagerEventsConnectionPoint());
            }

            if (m_PinEventsSink == null)
            {
                // Advise for pin events
                m_PinEventsSink = new PinEventsSink(this.OnPinEnterComplete, GetMbnPinEventsConnectionPoint());
            }
        }
        public PinWrapper(JSCallback jsCallback)
        {
            m_jsCallback = jsCallback;

            if (m_MbnInterfaceManager == null)
            {
                // Get MbnInterfaceManager
                m_MbnInterfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager();
            }

            // Get the mbn interface
            m_MbnInterface = GetFirstInterface();

            if (m_PinManagerEventsSink == null)
            {
                // Advise for pin manager events
                m_PinManagerEventsSink = new PinManagerEventsSink(this.OnGetPinStateCompleteHandler, GetMbnPinManagerEventsConnectionPoint());
            }

            if (m_PinEventsSink == null)
            {
                // Advise for pin events
                m_PinEventsSink = new PinEventsSink(this.OnPinEnterComplete, GetMbnPinEventsConnectionPoint());
            }
        }
Esempio n. 3
0
        public Promise then(JSCallback onFulfilled)
        {
            string       eventName       = "_then";
            CallbackItem onFulfilledItem = API.CreateCallbackItem(eventName, onFulfilled);

            return(API.ApplyAndGetObject <Promise>("then", onFulfilledItem));
        }
Esempio n. 4
0
 // Set a callback of a JS Object, accessible from any web-page
 public void BindJSObjectCallback(string objectName, string callbackName, JSCallback callback)
 {
     if (WebCore.IsRunning)
     {
         webView.SetObjectCallback(objectName, callbackName, callback);
     }
 }
Esempio n. 5
0
        public Promise @finally(JSCallback onFinally)
        {
            string       eventName     = "_finally";
            CallbackItem onFinallyItem = API.CreateCallbackItem(eventName, onFinally);

            return(API.ApplyAndGetObject <Promise>("finally", onFinallyItem));
        }
Esempio n. 6
0
        public Promise @catch(JSCallback onRejected)
        {
            string       eventName      = "_catch";
            CallbackItem onRejectedItem = API.CreateCallbackItem(eventName, onRejected);

            return(API.ApplyAndGetObject <Promise>("catch", onRejectedItem));
        }
Esempio n. 7
0
 public CallbackItem GetCallbackItem(string eventName, JSCallback callback)
 {
     if (callback == null)
     {
         return(null);
     }
     return(client.Callbacks.GetItem(id, eventName, callback));
 }
Esempio n. 8
0
            public void RemoveCallbackItem(string eventName, JSCallback callback)
            {
                if (callback == null)
                {
                    return;
                }
                CallbackItem item = GetCallbackItem(eventName, callback);

                RemoveCallbackItem(eventName, item);
            }
Esempio n. 9
0
        /// <summary>
        /// Listens to channel, when a new message arrives listener
        /// would be called with listener(event, args...).
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public EventEmitter on(string eventName, JSCallback listener)
        {
            if (listener == null)
            {
                return(this);
            }
            CallbackItem item = API.CreateCallbackItem(eventName, listener);

            return(API.ApplyAndGetObject <EventEmitter>("on", eventName, item));
        }
Esempio n. 10
0
        /**
         * Registers a JavaScript function in the Browser. When called, the given Mono {callback} will be executed.
         *
         * If IsLoaded is false, the in-page registration will be deferred until IsLoaded is true.
         *
         * The callback will be executed with one argument: a JSONNode array representing the arguments to the function
         * given in the browser. (Access the first argument with args[0], second with args[1], etc.)
         *
         * The arguments sent back-and forth must be JSON-able.
         *
         * The JavaScript process runs asynchronously. Callbacks triggered will be collected and fired during the next Update().
         *
         * {name} is evaluate-assigned JavaScript. You can use values like "myCallback", "MySystem.myCallback" (only if MySystem
         * already exists), or "GetThing().bobFunc" (if GetThing() returns an object you can use later).
         *
         */
        public void RegisterFunction(string name, JSCallback callback)
        {
            var id = registeredCallbacks.Count;

            registeredCallbacks.Add(callback);

            var js = name + " = function() { _zfb_event(" + id + ", JSON.stringify(Array.prototype.slice.call(arguments))); };";

            EvalJS(js);
        }
Esempio n. 11
0
 public void RegisterJSCallback(JSCallback cb)
 {
     if (browser != null && !browser.IsBrowserInitialized)
     {
         browser.RegisterJsObject(cb.Name, cb.Instance);
     }
     else
     {
         _registerCallbacks.Add(cb);
     }
 }
Esempio n. 12
0
        // Make a call to a Javascript function that has been exposed as an interface to Unity.
        // If mAllowedCalls has not yet been populated, the call will be deferred until it is.
        // Throws ArgumentException if we attempt to call a function that Javascript hasn't
        // told us is in our interface.
        private IReceipt MakeJSCall(string func, List <object> argList, Action <string> callbackFunc)
        {
            // If in the editor, we to a basic emulation of what's gonna happen in browser.  Provide a dummy receipt.
            if (Application.isEditor)
            {
                if (callbackFunc != null)
                {
                    IScheduler scheduler = GameFacade.Instance.RetrieveMediator <SchedulerMediator>().Scheduler;
                    scheduler.StartCoroutine(DoCallbackInSeconds(1.0f, callbackFunc));
                }
                return(new JSReceipt(null));
            }

            if (mAllowedCalls.Count == 0)
            {
                JSReceipt earlyJSR = new JSReceipt(null);
                mPendingCalls.Enqueue(delegate()
                {
                    // Fire off the call, but only if the early receipt didn't get killed
                    if (!earlyJSR.hasExited())
                    {
                        JSReceipt realJSR = (JSReceipt)MakeJSCall(func, argList, callbackFunc);
                        earlyJSR.UpdateGO(realJSR.GetGO());
                    }
                });
                return(earlyJSR);
            }

            if (!mAllowedCalls.ContainsKey(func))
            {
                throw new ArgumentException("Non-allowed function call to Javascript: " +
                                            func +
                                            ".  Check JSDispatcher.mAllowedCalls!");
            }

            if (argList == null)
            {
                argList = new List <object>();
            }

            // Null callbackFunc is okay, we just won't do anything on callback.

            string     cbId = "JSCallback" + mCallbackCounter++;
            GameObject go   = new GameObject(cbId);
            JSCallback cb   = (JSCallback)go.AddComponent(typeof(JSCallback));

            cb.Register(callbackFunc);

            argList.Insert(0, cbId);
            argList.Insert(1, "Callback");
            Application.ExternalCall("Hangout.unityDispatcher.unityToJSCalls." + func, argList.ToArray());

            return(new JSReceipt(go));
        }
Esempio n. 13
0
        /// <summary>
        /// Removes the specified listener from the listener array for the specified channel.
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="listener"></param>
        public EventEmitter removeListener(string eventName, JSCallback listener)
        {
            if (listener == null)
            {
                return(this);
            }
            CallbackItem item = API.GetCallbackItem(eventName, listener);

            API.RemoveCallbackItem(eventName, item);
            return(API.ApplyAndGetObject <EventEmitter>(
                       "removeListener", eventName, item
                       ));
        }
Esempio n. 14
0
        /**
         * Registers a JavaScript function in the Browser. When called, the given Mono {callback} will be executed.
         *
         * If IsLoaded is false, the in-page registration will be deferred until IsLoaded is true.
         *
         * The callback will be executed with one argument: a JSONNode array representing the arguments to the function
         * given in the browser. (Access the first argument with args[0], second with args[1], etc.)
         *
         * The arguments sent back-and forth must be JSON-able.
         *
         * The JavaScript process runs asynchronously. Callbacks triggered will be collected and fired during the next Update().
         *
         * {name} is evaluate-assigned JavaScript. You can use values like "myCallback", "MySystem.myCallback" (only if MySystem
         * already exists), or "GetThing().bobFunc" (if GetThing() returns an object you can use later).
         *
         */
        public void RegisterFunction(string name, JSCallback callback)
        {
            var id = nextCallbackId++;

            registeredCallbacks.Add(id, (value, error) => {
                //(we shouldn't be able to get an error here)
                callback(value);
            });

            var js = name + " = function() { _zfb_event(" + id + ", JSON.stringify(Array.prototype.slice.call(arguments))); };";

            EvalJS(js);
        }
Esempio n. 15
0
        public void addEventListener(string eventName, JSCallback listener)
        {
            if (listener == null)
            {
                return;
            }
            CallbackItem item = null;

            item = API.CreateCallbackItem(eventName, (object[] args) => {
                listener?.Invoke(args);
            });
            API.Apply("addEventListener", eventName, item);
        }
Esempio n. 16
0
        private string RunJS(string command, JSCallback cb = null)
        {
            if (!loaded)
            {
                Log("Page is not loaded yet");
                return("");
            }

            var task1 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(command);

            task1.Wait();
            var result = Convert.ToString(task1.Result?.Result ?? string.Empty);

            cb?.Invoke(result);
            return(result);
        }
Esempio n. 17
0
            public CallbackItem CreateCallbackItem(string eventName, JSCallback callback)
            {
                if (callback == null)
                {
                    return(null);
                }
                CallbackItem item   = client.Callbacks.Add(id, eventName, callback);
                string       script = ScriptBuilder.Build(
                    ScriptBuilder.Script(
                        "var callback = (...args) => {{",
                        "var params = [];",
                        "for (var arg of args) {{",
                        "if (arg == null) {{",
                        "params.push(null);",
                        "continue;",
                        "}}",
                        "var type = typeof(arg);",
                        "switch (type) {{",
                        "case 'number':",
                        "case 'boolean':",
                        "case 'string':",
                        "params.push(arg);",
                        "break;",
                        "default:",
                        "params.push({3});",
                        "break;",
                        "}}",
                        "}}",
                        "params = ['__event',{0},{1},{2}].concat(params);",
                        "this.emit.apply(this, params);",
                        "}};",
                        "return {4};"
                        ),
                    id,
                    eventName.Escape(),
                    item.CallbackId,
                    Script.AddObject("arg"),
                    Script.AddObject("callback")
                    );
                int objectId = _ExecuteBlocking <int>(script);

                item.ObjectId = objectId;
                return(item);
            }
Esempio n. 18
0
        public int setImmediate(JSCallback callback)
        {
            if (callback == null)
            {
                return(-1);
            }
            string       eventName = "setImmediate";
            CallbackItem item      = null;

            item = API.client.Callbacks.Add(API.id, eventName, callback);
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var callback = () => {{",
                    "{0};",
                    "this.emit('__event',{1},{2},{3});",
                    "}};",
                    "var id = {4};",
                    "return id;"
                    ),
                Script.RemoveObject("id"),
                API.id,
                eventName.Escape(),
                item.CallbackId,
                Script.AddObject("callback")
                );
            int objectId = API._ExecuteBlocking <int>(script);

            item.ObjectId = objectId;

            script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var timer = setImmediate({0});",
                    "return {1};"
                    ),
                Script.GetObject(objectId),
                Script.AddObject("timer")
                );
            return(API._ExecuteBlocking <int>(script));
        }
Esempio n. 19
0
    public void AsyncTimedEval(Script code, int milliTimeout, JSCallback callback, JSErrorCallback errorCallback)
    {
        var thread = new Thread(() => {
            try
            {
                code.Evaluate(ctx);
                callback.Invoke();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    errorCallback.Invoke(ex);
                }
            }
        });
        var timeThread = new Thread(() =>
        {
            try
            {
                Thread.Sleep(Configurations.ScriptTimeout);
                if (thread.IsAlive)
                {
                    thread.Abort();
                    thread.Join();
                    errorCallback(new Exception("max time exceeded"));
                }
            }
            catch (Exception ex)
            {
                Debug.LogWarning("This is impossible!");
                Debug.LogError(ex);
            }
        });

        thread.Start();
        timeThread.Start();
    }
Esempio n. 20
0
        public int setInterval(JSCallback callback, int delay)
        {
            if (callback == null)
            {
                return(-1);
            }
            string       eventName = "setInterval";
            CallbackItem item      = null;

            item = API.client.Callbacks.Add(API.id, eventName, callback);
            string script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var callback = () => {{",
                    "this.emit('__event',{0},{1},{2});",
                    "}};",
                    "return {3};"
                    ),
                API.id,
                eventName.Escape(),
                item.CallbackId,
                Script.AddObject("callback")
                );
            int objectId = API._ExecuteBlocking <int>(script);

            item.ObjectId = objectId;

            script = ScriptBuilder.Build(
                ScriptBuilder.Script(
                    "var timer = setInterval({0},{1});",
                    "return {2};"
                    ),
                Script.GetObject(objectId),
                delay,
                Script.AddObject("timer")
                );
            return(API._ExecuteBlocking <int>(script));
        }
Esempio n. 21
0
        void Test()
        {
            console.log("test", 123, true, null);
            console.log(process.cpuUsage(), process.getVersionsChrome());
            console.API.Apply("log", "test", 123, true, null);

            Console.WriteLine("IsRegistered: " + electron.globalShortcut.isRegistered(Accelerator.CmdOrCtrl + "+A"));
            //electron.globalShortcut.register(Accelerator.CmdOrCtrl + "+A", () => {
            //	Console.WriteLine("Ctrl + A pressed");
            //});

            /*
             * var b11 = Socketron.Buffer.alloc(1);
             * var b2 = Socketron.Buffer.alloc(1);
             * var b3 = Socketron.Buffer.alloc(1);
             * var b4 = Socketron.Buffer.alloc(1);
             * b2.Dispose();
             * var b5 = Socketron.Buffer.alloc(1);
             * var b6 = Socketron.Buffer.alloc(1);
             * b3.Dispose();
             * b11.Dispose();
             * var b7 = Socketron.Buffer.alloc(1);
             * var b8 = Socketron.Buffer.alloc(1);
             * var b9 = Socketron.Buffer.alloc(1);
             * return;
             * //*/

            /*
             * var os = require<NodeModules.OS>("os");
             * Console.WriteLine(os.cpus().Stringify());
             *
             * electron.protocol.uninterceptProtocol("a", (er) => {
             *      Console.WriteLine("uninterceptProtocol: {0}", er.toString());
             * });
             *
             * electron.contentTracing.getCategories((str) => {
             *      Console.WriteLine("getCategories: {0}", str.Stringify());
             * });
             * electron.contentTracing.getTraceBufferUsage((a, b) => {
             *      Console.WriteLine("getTraceBufferUsage: {0}, {1}", a, b);
             * });
             *
             *      //electron.app.on(App.Events.Ready, (args) => {
             *      var image4 = NativeImage.createFromPath("a");
             *      var appIcon = new Tray(image4);
             *      var contextMenu = Menu.buildFromTemplate("[" +
             *              "{label: 'Item1', type: 'radio'}," +
             *              "{label: 'Item2', type: 'radio'}" +
             *      "]");
             *      contextMenu.items[0].@checked = false;
             *      contextMenu.items[1].@checked = false;
             *      contextMenu.items[0].click = (_) => {
             *              Console.WriteLine("on click 0");
             *              contextMenu.items[0].@checked = true;
             *      };
             *      contextMenu.items[1].click = (_) => {
             *              Console.WriteLine("on click 1");
             *              contextMenu.items[1].@checked = true;
             *      };
             *      appIcon.setContextMenu(contextMenu);
             * //});
             *
             * return;
             * //*/

            /*
             * SocketronData data = new SocketronData();
             * data.Type = ProcessType.Browser;
             * data.Function = "dialog.showOpenDialog";
             * data.Data = "";
             * Buffer buffer = Packet.CreateTextData(data);
             * socketron.Write(buffer);
             */

            //string script = "console.log('Test: ' + process.type);";
            //socketron.Main.ExecuteJavaScript(script);

            /*
             * var paths = electron.dialog.showOpenDialog(new Dialog.OpenDialogOptions {
             *      properties = new[] {
             *              Dialog.Properties.multiSelections
             *      }
             * }, (a, b) => {
             *      Console.WriteLine("showOpenDialog: {0}, {1}", JSON.Stringify(a), JSON.Stringify(b));
             * });
             * //*/
            return;

            //foreach (var path in paths) {
            //	Console.WriteLine("OpenDialog: {0}", path);
            //}
            //*/

            /*
             * socketron.Main.ExecuteJavaScript(new[] {
             *      "var browserWindow = new electron.BrowserWindow({",
             *              "title: 'aaa',",
             *              "useContentSize: true,",
             *              "show: true",
             *      "});",
             *      "return browserWindow.id;"
             * }, (result) => {
             *      int? id = result as int?;
             *      Console.WriteLine("Window id: {0}", id);
             *
             *      socketron.Main.ExecuteJavaScript(new[] {
             *              "var browserWindow = electron.BrowserWindow.fromId(" + id + ");",
             *              "browserWindow.on('close', () => {",
             *                      "emit('window-close', " + id + ");",
             *              "});",
             *              "browserWindow.maximize();"
             *      });
             * });
             */
            //electron.App.Quit();

            /*
             * fs.require();
             * Console.WriteLine("fs.existsSync: " + fs.existsSync(""));
             *
             * os.require();
             * Console.WriteLine("os.EOL: " + os.EOL);
             *
             * electron.app.getFileIcon(
             *      null,
             *      (error, image2) => {
             *              LocalBuffer buffer = image2.toPNG();
             *              buffer.Save("image2.png");
             *      }
             * );
             * return;
             * //*/

            /*
             * path.require();
             * Console.WriteLine("path.delimiter: " + path.delimiter);
             * Console.WriteLine("path.join: " + path.join("a", "b", "ddd"));
             * console.clear();
             * console.count();
             * console.time();
             * console.log();
             * console.log("test");
             * console.log("test", 1, 1.2345, true, false, null);
             * console.timeEnd();
             * console.trace("test");
             * var t = setTimeout((args) => {
             *      Console.WriteLine("Timeout test *****");
             *      //process.abort();
             * }, 1000);
             * Console.WriteLine(JSON.Stringify(process.isDefaultApp()));
             * //Test2();
             * clearTimeout(t);
             * var t3 = setImmediate((args) => {
             *      Console.WriteLine("setImmediate test");
             * });
             * clearImmediate(t3);
             * return;
             * var t2 = setInterval((args) => {
             *      Console.WriteLine("Timeout test *****");
             * }, 12000);
             * return;
             * //*/

            //var aa = new BrowserWindow.Options();
            //aa.type = BrowserWindow.Types.
            //electron.Dialog.ShowErrorBox("title", "content");
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            BrowserWindowConstructorOptions options = new BrowserWindowConstructorOptions();

            options.show = false;
            //options.width = 400;
            //options.height = 300;
            //options.backgroundColor = "#aaa";
            //options.opacity = 0.5;
            BrowserWindow window = electron.BrowserWindow.Create(options);

            stopwatch.Stop();
            Log?.Invoke(string.Format("ElapsedMilliseconds: {0}", stopwatch.ElapsedMilliseconds));

            window.loadURL("file:///src/html/index.html");

            JSCallback callback1 = (args) => {
                Console.WriteLine("ready-to-show:");
                window.show();

                /*
                 * window.webContents.printToPDF(new WebContents.PrintToPDFOptions(), (er, buf) => {
                 *      console.log("printToPDF", er, buf.length);
                 *      var buf2 = LocalBuffer.From(buf);
                 *      buf2.Save("image3.pdf");
                 * });
                 * //*/

                setTimeout(() => {
                    Console.WriteLine("setTimeout");
                    window.capturePage(new Rectangle(100, 80), (image3) => {
                        var buf  = image3.toPNG();
                        var buf2 = LocalBuffer.From(buf);
                        buf2.Save("image3.png");
                    });
                }, 500);
            };

            window.once("ready-to-show", callback1);
            //window.removeListener("ready-to-show", callback1);

            /*
             * window.Execute(ScriptBuilder.Script(
             *      "self.on('close', (e) => {",
             *              "console.log('**************** close');",
             *              "e.preventDefault();",
             *      "});"
             * ));
             * //*/

            window.on("close", (args) => {
                Console.WriteLine("close:");
            });
            window.webContents.on("did-navigate", (args) => {
                object[] list = args as object[];
                Console.WriteLine("did-navigate");
                if (list != null)
                {
                    foreach (object item in list)
                    {
                        Console.WriteLine("\tParams: {0}", item);
                    }
                }
            });
            return;

            /*
             * MenuItem.Options[] template = new MenuItem.Options[] {
             *      new MenuItem.Options() {
             *              label = "Edit",
             *              submenu = new MenuItem.Options[] {
             *                      new MenuItem.Options() {
             *                              role = "undo"
             *                      },
             *                      new MenuItem.Options() {
             *                              role = "redo"
             *                      }
             *              }
             *      }
             * };
             * Menu menu = Menu.BuildFromTemplate(socketron, template);
             * //*/
            string[] template = new[] {
                "[",
                "{",
                "label: 'Edit',",
                "submenu: [",
                "{type: 'checkbox', label: 'Test'},",
                "{role: 'undo'},",
                "{type: 'separator'},",
                "{role: 'redo'}",
                "]",
                "}",
                "]"
            };
            var menuItemOptions = MenuItemConstructorOptions.ParseArray(string.Join("", template));

            menuItemOptions[0].submenu[0].@checked = true;
            //Console.WriteLine(JSON.Stringify(menuItemOptions, true));
            Menu menu = electron.Menu.buildFromTemplate(menuItemOptions);

            return;

            /*
             * string[] template = new[] {
             *      "[",
             *              "{",
             *                      "label: 'Edit',",
             *                      "submenu: [",
             *                              "{role: 'undo'},",
             *                              "{type: 'separator'},",
             *                              "{role: 'redo'},",
             *                      "]",
             *              "}",
             *      "]"
             * };
             * Menu menu = Menu.BuildFromTemplate(socketron, string.Join("", template));
             * //*/
            electron.Menu.setApplicationMenu(menu);

            int timer = setTimeout(() => {
                Console.WriteLine("setTimeout test");
            }, 3000);

            //Node.ClearTimeout(socketron, timer);


            return;

            var windows = electron.BrowserWindow.getAllWindows();

            foreach (var w in windows)
            {
                Console.WriteLine("window.id: {0}", w.id);
                Console.WriteLine("window.getTitle: {0}", w.getTitle());
            }

            electron.clipboard.writeText("aaa test");
            Console.WriteLine("Clipboard.ReadText: {0}", electron.clipboard.readText());


            /*
             * GlobalShortcut.Register(socketron, Accelerator.CmdOrCtrl + "+A", (args) => {
             *      Console.WriteLine("Ctrl + A pressed");
             *      GlobalShortcut.Unregister(socketron, Accelerator.CmdOrCtrl + "+A");
             * });
             * //*/
            Console.WriteLine("GetCursorScreenPoint: {0}", electron.screen.getCursorScreenPoint().Stringify());
            //Console.WriteLine("GetMenuBarHeight: {0}", Screen.GetMenuBarHeight(socketron));
            Console.WriteLine("GetPrimaryDisplay: {0}", electron.screen.getPrimaryDisplay().Stringify());

            var displayList = electron.screen.getAllDisplays();

            foreach (var display in displayList)
            {
                Console.WriteLine("GetAllDisplays: {0}", display.Stringify());
            }
            Console.WriteLine("GetDisplayNearestPoint: {0}", electron.screen.getDisplayNearestPoint(new Point()
            {
                x = -10, y = 0
            }).Stringify());
            Console.WriteLine("GetDisplayMatching: {0}", electron.screen.getDisplayMatching(new Rectangle()
            {
                x = -10, y = 0
            }).Stringify());

            //Shell.ShowItemInFolder(socketron, "c:/");
            //Shell.OpenExternal(socketron, "http://google.com");
            //Shell.Beep(socketron);

            return;

            Console.WriteLine("Notification.IsSupported: " + electron.Notification.isSupported());
            var notification = electron.Notification.Create(new NotificationConstructorOptions {
                title = "Title",
                body  = "Body"
            });

            notification.on("show", (args) => {
                Console.WriteLine("Notification show event");
            });
            notification.show();

            var image = electron.nativeImage.createEmpty();

            Console.WriteLine("image.IsEmpty: {0}", image.isEmpty());
            Console.WriteLine("image.GetSize: {0}", image.getSize());
            Console.WriteLine("image.GetAspectRatio: {0}", image.getAspectRatio());
            Console.WriteLine("image.ToDataURL: {0}", image.toDataURL());
            image.toPNG();

            return;

            //window.SetFullScreen(true);
            stopwatch.Reset();
            stopwatch.Start();
            string title = window.getTitle();

            stopwatch.Stop();
            Log(string.Format("ElapsedMilliseconds: {0}", stopwatch.ElapsedMilliseconds));
            Console.WriteLine("test 1: " + title);

            //window.LoadURL("http://google.com");

            Console.WriteLine("GetOSProcessId: " + window.webContents.getOSProcessId());

            window.loadURL("file:///src/html/index.html");
            window.show();
            window.webContents.openDevTools();

            window.webContents.setIgnoreMenuShortcuts(true);

            //Thread.Sleep(1000);
            window.webContents.executeJavaScript("document.write('test')");
            Console.WriteLine("Test");

            return;

            stopwatch.Reset();
            stopwatch.Start();
            title = window.getTitle();
            stopwatch.Stop();
            Log(string.Format("ElapsedMilliseconds: {0}", stopwatch.ElapsedMilliseconds));

            window.webContents.openDevTools();
            Console.WriteLine("IsDevToolsOpened: {0}", window.webContents.isDevToolsOpened());

            API.client.On("BrowserWindow.close", (result) => {
                Console.WriteLine("Test close");
            });

            ulong handle1 = window.getNativeWindowHandle();

            Console.WriteLine("GetNativeWindowHandle: " + handle1);

            window.setOpacity(0.755);
            double opacity = window.getOpacity();

            Console.WriteLine("GetOpacity: " + opacity);

            bool b1 = window.isFocused();

            Console.WriteLine("test 1: " + b1);

            Rectangle rect1 = window.getContentBounds();
            string    text  = rect1.Stringify();

            Console.WriteLine("test 1: " + text);
            Rectangle rect2 = Rectangle.Parse(text);

            Console.WriteLine("test 1: {0}, {1}, {2}, {3}", rect2.x, rect2.y, rect2.width, rect2.height);

            //window.SetEnabled(false);
            window.setSize(200, 150);
            Rectangle rect = window.getContentBounds();

            Console.WriteLine("GetContentBounds: {0}, {1}", rect.x, rect.y);
            ulong handle = window.getNativeWindowHandle();

            Console.WriteLine("GetNativeWindowHandle: {0}", handle);
        }
 // Set a callback of a JS Object, accessible from any web-page
 public void BindJSObjectCallback(string objectName, string callbackName, JSCallback callback)
 {
     if (WebCore.IsRunning)
         webView.SetObjectCallback(objectName, callbackName, callback);
 }
Esempio n. 23
0
        /// <summary>
        /// Binds a callback function to a Javascript object previously created with <see cref="WebControl.CreateObject"/>.
        /// This is very useful for passing events from Javascript to your application.
        /// </summary>
        /// <example>
        /// An example of usage:
        /// <code>
        /// public void OnSelectItem(object sender, JSCallbackEventArgs e)
        /// {
        ///     System.Console.WriteLine( "Player selected item: " + e.args[0].ToString() );
        /// }
        /// 
        /// public void initWebControl()
        /// {
        ///     webView.CreateObject("MyObject");
        ///     webView.SetObjectCallback("MyObject", "SelectItem", OnSelectItem);
        /// }
        /// 
        /// // You can now call the function "OnSelectItem" from Javascript:
        /// MyObject.SelectItem("shotgun");
        /// </code>
        /// </example>
        /// <param name="objectName">
        /// The name of the Javascript object.
        /// </param>
        /// <param name="callbackName">
        /// The name of the Javascript function that will call the callback.
        /// </param>
        /// <param name="callback">
        /// Reference to a <see cref="JSCallback"/> implementation.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// The member is called on an invalid <see cref="WebControl"/> instance
        /// (see <see cref="UIElement.IsEnabled"/>).
        /// </exception>
        public void SetObjectCallback( string objectName, string callbackName, JSCallback callback )
        {
            VerifyLive();

            StringHelper objectNameStr = new StringHelper( objectName );
            StringHelper callbackNameStr = new StringHelper( callbackName );

            awe_webview_set_object_callback( Instance, objectNameStr.Value, callbackNameStr.Value );

            string key = String.Format( "{0}.{1}", objectName, callbackName );

            if ( jsObjectCallbackMap.ContainsKey( key ) )
                jsObjectCallbackMap.Remove( key );

            if ( callback != null )
                jsObjectCallbackMap.Add( key, callback );
        }
Esempio n. 24
0
        /// <summary>
        /// Binds a callback function to a Javascript object previously created by WebView.CreateObject.
        /// An example of usage:
        /// <pre>
        /// public void OnSelectItem(object sender, JSCallbackEventArgs e)
        /// {
        ///     System.Console.WriteLine("Player selected item: " + e.args[0].ToString());
        /// }
        /// 
        /// public void initWebView()
        /// {
        ///     webView.CreateObject("MyObject");
        ///     webView.SetObjectCallback("MyObject", "selectItem", OnSelectItem);
        /// }
        /// 
        /// // You can now call the function "OnSelectItem" from Javascript:
        /// MyObject.selectItem("shotgun");
        /// </pre>
        /// </summary>
        /// <param name="objectName"></param>
        /// <param name="callbackName"></param>
        /// <param name="callback"></param>
        public void SetObjectCallback(string objectName,
                                      string callbackName,
                                      JSCallback callback)
        {
            StringHelper objectNameStr = new StringHelper(objectName);
            StringHelper callbackNameStr = new StringHelper(callbackName);

            awe_webview_set_object_callback(instance, objectNameStr.value(), callbackNameStr.value());

            string key = objectName + "." + callbackName;

            if (jsObjectCallbackMap.ContainsKey(key))
                jsObjectCallbackMap.Remove(key);

            if(callback != null)
                jsObjectCallbackMap.Add(key, callback);
        }
Esempio n. 25
0
 public static extern JSFunction CreateCallback(JSContext context, IntPtr data, [MarshalAs(UnmanagedType.FunctionPtr)] JSCallback callback, out JSScriptException error);
Esempio n. 26
0
        public EventEmitter removeListener(string eventName, JSCallback listener)
        {
            EventEmitter emitter = API.ConvertTypeTemporary <EventEmitter>();

            return(emitter.removeListener(eventName, listener));
        }