예제 #1
0
    /// <summary>
    /// Default entry into managed code.
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task <object> Invoke(object input)
    {
        if (console == null)
        {
            console = await WebSharpJs.NodeJS.Console.Instance();
        }

        try
        {
            IpcRenderer ipcRenderer = await IpcRenderer.Create();

            await console.Log(await ipcRenderer.SendSync("synchronous-message", "synchronous ping"));     // prints "pong"

            ipcRenderer.On("asynchronous-reply", (async(args) =>
            {
                var argsArray = args as object[];
                await console.Log(argsArray[1]);     // prints "pong"
                return(null);
            }));
            await ipcRenderer.Send("asynchronous-message", "asynchronous ping");

            await console.Log($"Hello:  {input}");
        }
        catch (Exception exc) { await console.Log($"extension exception:  {exc.Message}"); }

        return(null);
    }
예제 #2
0
    private async void onMouseClick(object sender, HtmlEventArgs args)
    {
        // Prevent the default click handler `will-download` from firing.
        args.PreventDefault();
        //args.StopPropagation();

        // Using the sender object we will obtain the `href`
        // information from the `<a>` anchor element.
        var target = sender as HtmlElement;
        var href   = await target.GetProperty <string>("href");

        await console.Log($"clicked {await target?.GetId()} for {href}");

        // Notifiy the Main process that it should handle the download
        var ipcRenderer = await IpcRenderer.Create();

        ipcRenderer.Send("download-file", href);
    }
예제 #3
0
    /// <summary>
    /// Default entry into managed code.
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task <object> Invoke(object input)
    {
        if (console == null)
        {
            console = await WebSharpJs.NodeJS.Console.Instance();
        }

        try
        {
            var document = await HtmlPage.GetDocument();

            var printPDFBtn = await document.GetElementById("print-pdf");

            var ipcRenderer = await IpcRenderer.Create();

            await printPDFBtn?.AttachEvent("click",
                                           new EventHandler(async(sender, evt) =>
            {
                await console.Log("clicked");
                ipcRenderer.Send("print-to-pdf");
            })
                                           );

            ipcRenderer.On("wrote-pdf",
                           new IpcRendererEventListener(async(result) =>
            {
                var state = result.CallbackState as object[];
                var parms = state[1] as object[];
                foreach (var parm in parms)
                {
                    await console.Log(parm);
                }
                var pathLabel = await document.GetElementById("file-path");
                await pathLabel.SetProperty("innerHTML", $"Wrote PDF to: {parms[0]}");
            }));
        }
        catch (Exception exc) { await console.Log($"extension exception:  {exc.Message}"); }

        return(null);
    }
예제 #4
0
파일: Ping.cs 프로젝트: swipswaps/WebSharp
    /// <summary>
    /// Default entry into managed code.
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task <object> Invoke(object input)
    {
        if (console == null)
        {
            console = await WebSharpJs.NodeJS.Console.Instance();
        }

        try
        {
            IpcRenderer ipcRenderer = await IpcRenderer.Create();

            // Note: Sending a synchronous message from the render process will block
            // the whole renderer process, unless you know what you are doing you should never use it.
            //
            // View notes in MainWindow.cs
            await console.Log(await ipcRenderer.SendSync("synchronous-message", "synchronous ping")); // prints "pong"

            ipcRenderer.On("asynchronous-reply",
                           new IpcRendererEventListener(async(result) =>
            {
                var state = result.CallbackState as object[];
                var parms = state[1] as object[];
                foreach (var parm in parms)
                {
                    await console.Log(parm); // prints "pong"
                }
            }));

            await ipcRenderer.Send("asynchronous-message", "asynchronous ping");

            await console.Log($"Hello:  {input}");
        }
        catch (Exception exc) { await console.Log($"extension exception:  {exc.Message}"); }

        return(null);
    }
예제 #5
0
    /// <summary>
    /// Default entry into managed code.
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task <object> Invoke(object input)
    {
        if (console == null)
        {
            console = await WebSharpJs.NodeJS.Console.Instance();
        }

        try
        {
            ipcRenderer = await IpcRenderer.Create();

            document = await HtmlPage.GetDocument();

            var form = await document.QuerySelector("form");

            // Input fields
            source = await form.QuerySelector("input[name=\"source\"]");

            destination = await form.QuerySelector("input[name=\"destination\"]");

            name = await form.QuerySelector("input[name=\"name\"]");

            // Buttons
            btnSource = await document.GetElementById("chooseSource");

            btnDestination = await document.GetElementById("chooseDestination");

            btnSubmit = await form.QuerySelector("button[type=\"submit\"]");

            // Handle input fields
            await source.AttachEvent(HtmlEventNames.Input, updateUI);

            await source.AttachEvent(HtmlEventNames.Change, updateUI);

            await destination.AttachEvent(HtmlEventNames.Input, updateUI);

            await destination.AttachEvent(HtmlEventNames.Change, updateUI);

            await name.AttachEvent(HtmlEventNames.Input, updateUI);

            // Handle buttons
            await btnSource.AttachEvent(HtmlEventNames.Click, handleSource);

            await btnDestination.AttachEvent(HtmlEventNames.Click, handleDestination);

            // Handle form Submit
            await form.AttachEvent(HtmlEventNames.Submit,
                                   async (s, e) => {
                e.PreventDefault();

                await ToggleUI(true);

                // Send off the convert request
                await ipcRenderer.Send("submitform",
                                       await source.GetProperty <string>("value"),
                                       await destination.GetProperty <string>("value"),
                                       await name.GetProperty <string>("value")
                                       );
            }
                                   );

            await ipcRenderer.AddListener("gotMetaData",
                                          new IpcRendererEventListener(
                                              async(result) =>
            {
                var state = result.CallbackState as object[];
                var ipcMainEvent = (IpcRendererEvent)state[0];
                var parms = state[1] as object[];

                var audio = ScriptObjectHelper.AnonymousObjectToScriptableType <Audio>(parms[0]);
                var video = ScriptObjectHelper.AnonymousObjectToScriptableType <Video>(parms[1]);
                var duration = TimeSpan.Parse(parms[2].ToString());

                await updateInfo(audio, video, duration);
            }

                                              )

                                          );

            await ipcRenderer.AddListener("completed",
                                          new IpcRendererEventListener(
                                              async(result) =>
            {
                await ToggleUI(false);
            }

                                              )

                                          );

            await console.Log($"Hello:  {input}");
        }
        catch (Exception exc) { await console.Log($"extension exception:  {exc.Message}"); }

        return(null);
    }