コード例 #1
0
    async Task <int> CreateWindow(string __dirname)
    {
        // Create the browser window.
        mainWindow = await BrowserWindow.Create(
            new BrowserWindowOptions()
        {
            Width           = 1280,
            Height          = 720,
            BackgroundColor = "#000000",         // black
            Show            = false
        }
            );

        await mainWindow.Once("ready-to-show",
                              new ScriptObjectCallback(async(evt) =>
        {
            await mainWindow.Show();
        }

                                                       )
                              );

        // and load the external site playcode.io of the app.
        await mainWindow.LoadURL($"https://playcode.io");

        // Open the DevTools
        //await mainWindow.GetWebContents().ContinueWith(
        //        (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
        //);

        return(await mainWindow.GetId());
    }
コード例 #2
0
ファイル: MainWindow.cs プロジェクト: swipswaps/WebSharp
    async Task <int> CreateWindow(string __dirname)
    {
        // Create the browser window.
        mainWindow = await BrowserWindow.Create(
            new BrowserWindowOptions()
        {
            Width    = 800,
            Height   = 600,
            IconPath = $"{__dirname}/assets/icons/appicon.ico"
        }

            );

        // and load the index.html of the app.
        await mainWindow.LoadURL($"file://{__dirname}/index.html");

        // Open the DevTools
        //await mainWindow.GetWebContents().ContinueWith(
        //        (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
        //);

        // Did finish load
        await mainWindow.GetWebContents().ContinueWith(
            (t) =>
        {
            var webcontents = t.Result;
            webcontents.On("did-finish-load",
                           new ScriptObjectCallback(
                               async(ar) =>
            {
                try
                {
                    var ready = await InitializeEngine();
                    if (!ready)
                    {
                        var errDialog = await Dialog.Instance();
                        await errDialog.ShowErrorBox("FFMPeg engine failure", "FFMPeg could not be initialized");
                    }
                }
                catch (Exception initExc)
                {
                    var errDialog = await Dialog.Instance();
                    await errDialog.ShowErrorBox("FFMPeg engine failure", initExc.Message);
                }
            }
                               )
                           );
        }
            );

        return(await mainWindow.GetId());
    }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: swipswaps/WebSharp
    async Task <int> CreateWindow(string __dirname)
    {
        // Create the browser window.
        mainWindow = await BrowserWindow.Create(new BrowserWindowOptions { UseContentSize = true, IconPath = $"{__dirname}/assets/icons/appicon.ico" });

        // and load the index.html of the app.
        await mainWindow.LoadURL($"file://{__dirname}/index.html");

        // Open the DevTools
        //await mainWindow.GetWebContents().ContinueWith(
        //        (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
        //);

        return(await mainWindow.GetId());
    }
コード例 #4
0
ファイル: MainWindow.cs プロジェクト: AaYaAQc/WebSharp
        async Task<int> CreateWindow (string __dirname)
        {
            // Create the browser window.
            mainWindow = await BrowserWindow.Create(new BrowserWindowOptions() { Width = 600, Height = 400 });

            // and load the index.html of the app.
            await mainWindow.LoadURL($"file://{__dirname}/index.html");

            // Open the DevTools
            //await mainWindow.GetWebContents().ContinueWith(
            //        (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
            //);

            return await mainWindow.GetId();

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

        try
        {
            // Create the browser window.
            mainWindow = await BrowserWindow.Create(new BrowserWindowOptions()
            {
                Width = 600, Height = 400
            });

            // and load the index.html of the app.
            await mainWindow.LoadURL($"file://{__dirname}/index.html");

            // Open the DevTools
            await mainWindow.GetWebContents().ContinueWith(
                (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
                );

            // Emitted when the window is closed.
            await mainWindow.On("closed", async (evt) =>
            {
                await console.Log("Received closed event");
                System.Console.WriteLine("Received closed event");
                mainWindow = null;
                return(null);
            });

            await console.Log($"Loading: file://{__dirname}/index.html");
        }
        catch (Exception exc) { await console.Log($"extension exception:  {exc.Message}"); }

        return(await mainWindow.GetId());
    }
コード例 #6
0
    /// <summary>
    /// Default entry into managed code.
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task <object> Invoke(string __dirname)
    {
        if (console == null)
        {
            console = await WebSharpJs.NodeJS.Console.Instance();
        }

        try
        {
            // Create the browser window.
            mainWindow = await BrowserWindow.Create(new BrowserWindowOptions()
            {
                Width = 600, Height = 400
            });

            // and load the index.html of the app.
            await mainWindow.LoadURL($"file://{__dirname}/index.html");

            await mainWindow.GetWebContents().ContinueWith(
                (t) => {
                var webContents = t.Result;

                // Subscribe to the "context-menu" event on the WebContents
                webContents?.On("context-menu", async(cmevt) =>
                {
                    // if we have not created the menu then do it now
                    if (menu == null)
                    {
                        menu = await Menu.Create();
                        await menu.Append(await MenuItem.Create(new MenuItemOptions()
                        {
                            Label = "Hello", Click = MenuItemClicked
                        }));
                        await menu.Append(await MenuItem.Create(new MenuItemOptions()
                        {
                            Type = MenuItemType.Separator
                        }));
                        await menu.Append(await MenuItem.Create(
                                              new MenuItemOptions()
                        {
                            Label          = "View",
                            SubMenuOptions = new MenuItemOptions[]
                            {
                                new MenuItemOptions()
                                {
                                    Role = MenuItemRole.Reload
                                },
                                new MenuItemOptions()
                                {
                                    Role = MenuItemRole.ToggleDevTools
                                },
                                new MenuItemOptions()
                                {
                                    Type = MenuItemType.Separator
                                },
                                new MenuItemOptions()
                                {
                                    Role = MenuItemRole.ResetZoom
                                },
                                new MenuItemOptions()
                                {
                                    Role = MenuItemRole.ZoomIn
                                },
                                new MenuItemOptions()
                                {
                                    Role = MenuItemRole.ZoomOut
                                },
                                new MenuItemOptions()
                                {
                                    Type = MenuItemType.Separator
                                },
                                new MenuItemOptions()
                                {
                                    Role = MenuItemRole.ToggleFullScreen
                                },
                            }
                        }
                                              ));
                        await menu.Append(await MenuItem.Create(new MenuItemOptions()
                        {
                            Type = MenuItemType.Separator
                        }));
                        await menu.Append(await MenuItem.Create(new MenuItemOptions()
                        {
                            Label = "WebSharp", Type = MenuItemType.Checkbox, Checked = true, Click = MenuItemClicked
                        }));
                    }

                    // popup our menu here
                    menu.Popup();
                    return(null);
                });

                // Open the DevTools
                webContents?.OpenDevTools(DevToolsMode.Bottom);
            }
                );

            // Emitted when the window is closed.
            await mainWindow.On("closed", async (evt) =>
            {
                await console.Log("Received closed event");
                System.Console.WriteLine("Received closed event");
                mainWindow = null;
                return(null);
            });

            await console.Log($"Loading: file://{__dirname}/index.html");
        }
        catch (Exception exc) { await console.Log($"extension exception:  {exc.Message}"); }

        return(await mainWindow.GetId());
    }
コード例 #7
0
    async Task <int> CreateWindow(string __dirname)
    {
        // Create the browser window.
        mainWindow = await BrowserWindow.Create(
            new BrowserWindowOptions()
        {
            Width    = 600,
            Height   = 400,
            IconPath = $"{__dirname}/assets/icons/appicon.ico",
        }
            );

        // Listen for window minimize event so that we can hide
        // the main window.
        await mainWindow.On("minimize",
                            new ScriptObjectCallback <Event>(async(evt) =>
        {
            //console.Log("Minimize");
            await mainWindow.Hide();
        }
                                                             ));

        // Listen for window show event
        await mainWindow.On("show",
                            new ScriptObjectCallback <Event>(async(evt) =>
        {
            //console.Log("Show");
            await tray.SetHighlightMode(TrayHighlightMode.Always);

            // Mac specific
            // During development this will not work well.
            // The icon will revert back to the Electron icon.  Bug??
            var dock = await app.Dock();
            if (dock != null)
            {
                await dock.Show();
                await dock.SetIcon($"{__dirname}/assets/icons/appicon.png");
            }
        }
                                                             ));

        // Listen for window show event
        await mainWindow.On("hide",
                            new ScriptObjectCallback <Event>(async(evt) =>
        {
            //console.Log("Hide");
            await tray.SetHighlightMode(TrayHighlightMode.Never);

            // Mac specific
            var dock = await app.Dock();
            if (dock != null)
            {
                await dock.Hide();
            }
        }
                                                             ));

        // Emitted when the window is going to be closed.
        // It's emitted before the beforeunload and unload event of the DOM.
        await mainWindow.On("close",
                            new ScriptObjectCallback <Event>(async(ar) =>
        {
            // Check if we should quit
            if (IsShouldQuit)
            {
                // Dereference the window object, usually you would store windows
                // in an array if your app supports multi windows, this is the time
                // when you should delete the corresponding element.
                mainWindow = null;
            }
            else
            {
                // Retrieve our event
                var evt = ar.CallbackState as Event;

                // Calling event.PreventDefault() will cancel the close.
                evt.PreventDefault();
                // Then we hide the main window.
                await mainWindow.Hide();
            }
        }
                                                             ));

        // and load the index.html of the app.
        await mainWindow.LoadURL($"file://{__dirname}/index.html");

        // Open the DevTools
        //await mainWindow.GetWebContents().ContinueWith(
        //        (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
        //);

        return(await mainWindow.GetId());
    }
コード例 #8
0
ファイル: MainWindow.cs プロジェクト: swipswaps/WebSharp
    async Task <int> CreateWindow(string __dirname)
    {
        // Create the browser window.
        mainWindow = await BrowserWindow.Create();

        // Get our session
        try
        {
            session = await Session.FromPartition("partition:nameofpartition");
        }
        catch (Exception sexc)
        {
            await console.Log($"logging: {sexc.Message}");

            var web = await mainWindow.GetWebContents();

            //.ContinueWith(
            //    async (t) =>
            //    {
            //        session = await t.Result?.GetSession();

            //    }

            //    );

            session = await web.GetSession();
        }
        if (session != null)
        {
            await console.Log(session);

            await session.SetPermissionRequestHandler(
                new ScriptObjectCallback <WebContents, string, Func <object, Task <object> > >(

                    async(callbackResult) =>
            {
                var permissionResult = new PermissionRequestResult(callbackResult);
                var url = await permissionResult.WebContents.GetURL();
                await console.Log($"Received permission request from {url} for access to \"{permissionResult.Permission}\".");
                if (url == "https://html5demos.com/geo/" && permissionResult.Permission == "geolocation")
                {
                    permissionResult.Callback(await GrantAccess(url, permissionResult.Permission));
                }
                else
                {
                    permissionResult.Callback(true);
                }
            }
                    )
                );
        }

        // and load the index.html of the app.
        await mainWindow.LoadURL("https://html5demos.com/geo/");

        // Open the DevTools
        //await mainWindow.GetWebContents().ContinueWith(
        //        (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
        //);

        return(await mainWindow.GetId());
    }
コード例 #9
0
ファイル: MainWindow.cs プロジェクト: asears/WebSharp
    async Task <int> CreateWindow(string __dirname)
    {
        // Create the browser window.
        mainWindow = await BrowserWindow.Create(
            new BrowserWindowOptions()
        {
            Width    = 600,
            Height   = 400,
            IconPath = $"{__dirname}/assets/icons/appicon.ico",
        }
            );

        // Listen for window minimize event so that we can hide
        // the main window.
        await mainWindow.On("minimize",
                            new ScriptObjectCallback <Event>(async(evt) =>
        {
            //console.Log("Minimize");
            await mainWindow.Hide();
        }
                                                             ));

        // Listen for window show event
        await mainWindow.On("show",
                            new ScriptObjectCallback <Event>(async(evt) =>
        {
            //console.Log("Show");
            await tray.SetHighlightMode(TrayHighlightMode.Always);

            // Mac specific
            // During development this will not work well.
            // The icon will revert back to the Electron icon.  Bug??
            var dock = await app.Dock();
            if (dock != null)
            {
                await dock.Show();
                await dock.SetIcon($"{__dirname}/assets/icons/appicon.png");
            }
        }
                                                             ));

        // Listen for window show event
        await mainWindow.On("hide",
                            new ScriptObjectCallback <Event>(async(evt) =>
        {
            //console.Log("Hide");
            await tray.SetHighlightMode(TrayHighlightMode.Never);

            // Mac specific
            var dock = await app.Dock();
            if (dock != null)
            {
                await dock.Hide();
            }
        }
                                                             ));

        // and load the index.html of the app.
        await mainWindow.LoadURL($"file://{__dirname}/index.html");

        // Open the DevTools
        //await mainWindow.GetWebContents().ContinueWith(
        //        (t) => { t.Result?.OpenDevTools(DevToolsMode.Bottom); }
        //);

        return(await mainWindow.GetId());
    }