Beispiel #1
0
        protected static void Run()
        {
            var icon = AppIcon.FromFile("icon", ".");

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddScoped <UiBridge>();
            Application.AddGlobalHandler <UiBridge>();
            using var serviceProvider = serviceCollection.BuildServiceProvider();
            _serviceProvider          = serviceProvider;

            using (var window = new Window(serviceProvider))
            {
                _mainWindow                  = window;
                window.Title                 = "SpiderEye Playground";
                window.UseBrowserTitle       = true;
                window.EnableScriptInterface = true;
                window.CanResize             = true;
                window.BackgroundColor       = "#303030";
                window.Size                  = new Size(800, 600);
                window.MinSize               = new Size(300, 200);
                window.MaxSize               = new Size(1200, 900);
                window.Icon                  = icon;
                window.Navigating           += (sender, uri) => Console.WriteLine("uri changed: " + uri);

                var windowMenu = new Menu();
                var appMenu    = windowMenu.MenuItems.AddLabelItem("App");
                appMenu.MenuItems.AddMacOsHide();
                appMenu.MenuItems.AddMacOsHideOtherApplications();
                appMenu.MenuItems.AddMacOsUnhideAllApplications();
                appMenu.MenuItems.AddMacOsSeparator();

                var quitMenu = appMenu.MenuItems.AddLabelItem("Quit");
                quitMenu.SetSystemShortcut(SystemShortcut.Close);
                quitMenu.Click += (s, e) => Application.Exit();

                windowMenu.MenuItems.AddMacOsEdit();
                windowMenu.MenuItems.AddMacOsView();

                var mainMenu = windowMenu.MenuItems.AddLabelItem("Main Menu");
                mainMenu.MenuItems.AddLabelItem("Entry 1");
                mainMenu.MenuItems.AddSeparatorItem();
                mainMenu.MenuItems.AddLabelItem("Entry 2");
                var showModalMenu = mainMenu.MenuItems.AddLabelItem("Show Modal");
                showModalMenu.Click += (s, e) => ShowModalMenu_Click(true);
                showModalMenu.SetShortcut(ModifierKey.Control | ModifierKey.Shift, Key.M);

                var showWindowMenu = mainMenu.MenuItems.AddLabelItem("Show Window");
                showWindowMenu.Click += (s, e) => ShowModalMenu_Click(false);
                showWindowMenu.SetShortcut(ModifierKey.Control | ModifierKey.Shift, Key.W);

                windowMenu.MenuItems.AddMacOsWindow();

                var helpMenu = windowMenu.MenuItems.AddLabelItem("Help");
                var helpItem = helpMenu.MenuItems.AddLabelItem("MyHelp");
                helpItem.SetSystemShortcut(SystemShortcut.Help);

                window.Menu = windowMenu;

                if (window.MacOsOptions != null)
                {
                    window.MacOsOptions.Appearance = MacOsAppearance.DarkAqua;
                }

                SetDevSettings(window);

                // the port number is defined in the angular.json file (under "architect"->"serve"->"options"->"port")
                // note that you have to run the angular dev server first (npm run watch)
                Application.UriWatcher      = new AngularDevUriWatcher("http://localhost:65400");
                Application.ContentProvider = new EmbeddedContentProvider("Angular/dist");
                Application.Run(window, "/index.html");
            }
        }
 /// <summary>
 /// Registers a ui bridge service via dependency injection as a singleton service.
 /// </summary>
 /// <param name="services">The service collection.</param>
 /// <typeparam name="T">The type of the service.</typeparam>
 /// <returns>The updated service collection.</returns>
 public static IServiceCollection AddSpidereyeBridgeSingleton <T>(this IServiceCollection services) where T : class
 {
     services.TryAddSingleton <T>();
     Application.AddGlobalHandler <T>();
     return(services);
 }
Beispiel #3
0
        protected static void Run()
        {
            var icon = AppIcon.FromFile("icon", ".");

            using (var statusIcon = new StatusIcon())
                using (var window = new Window())
                {
                    window.Title                 = "SpiderEye Playground";
                    window.UseBrowserTitle       = true;
                    window.EnableScriptInterface = true;
                    window.CanResize             = true;
                    window.BackgroundColor       = "#303030";
                    window.Size    = new Size(800, 600);
                    window.MinSize = new Size(300, 200);
                    window.MaxSize = new Size(1200, 900);
                    window.Icon    = icon;

                    statusIcon.Icon  = icon;
                    statusIcon.Title = window.Title;

                    SetDevSettings(window);

                    var menu     = new Menu();
                    var showItem = menu.MenuItems.AddLabelItem("Hello World");
                    showItem.SetShortcut(ModifierKey.Primary, Key.O);
                    showItem.Click += ShowItem_Click;

                    var eventItem = menu.MenuItems.AddLabelItem("Send Event to Webview");
                    eventItem.SetShortcut(ModifierKey.Primary, Key.E);
                    eventItem.Click += async(s, e) => await window.Bridge.InvokeAsync("dateUpdated", DateTime.Now);

                    var subMenuItem = menu.MenuItems.AddLabelItem("Open me!");
                    subMenuItem.MenuItems.AddLabelItem("Boo!");

                    var borderItem = menu.MenuItems.AddLabelItem("Window Border");
                    var def        = borderItem.MenuItems.AddLabelItem("Default");
                    def.Click += (s, e) => { window.BorderStyle = WindowBorderStyle.Default; };
                    var none = borderItem.MenuItems.AddLabelItem("None");
                    none.Click += (s, e) => { window.BorderStyle = WindowBorderStyle.None; };

                    var sizeItem = menu.MenuItems.AddLabelItem("Window Size");
                    var max      = sizeItem.MenuItems.AddLabelItem("Maximize");
                    max.Click += (s, e) => { window.Maximize(); };
                    var unmax = sizeItem.MenuItems.AddLabelItem("Unmaximize");
                    unmax.Click += (s, e) => { window.Unmaximize(); };
                    var min = sizeItem.MenuItems.AddLabelItem("Minimize");
                    min.Click += (s, e) => { window.Minimize(); };
                    var unmin = sizeItem.MenuItems.AddLabelItem("Unminimize");
                    unmin.Click += (s, e) => { window.Unminimize(); };
                    var full = sizeItem.MenuItems.AddLabelItem("Enter Fullscreen");
                    full.Click += (s, e) => { window.EnterFullscreen(); };
                    var unfull = sizeItem.MenuItems.AddLabelItem("Exit Fullscreen");
                    unfull.SetShortcut(ModifierKey.Primary, Key.F11);
                    unfull.Click += (s, e) => { window.ExitFullscreen(); };

                    menu.MenuItems.AddSeparatorItem();

                    var exitItem = menu.MenuItems.AddLabelItem("Exit");
                    exitItem.Click += (s, e) => Application.Exit();

                    statusIcon.Menu = menu;

                    var bridge = new UiBridge();
                    Application.AddGlobalHandler(bridge);

                    // the port number is defined in the angular.json file (under "architect"->"serve"->"options"->"port")
                    // note that you have to run the angular dev server first (npm run watch)
                    Application.UriWatcher      = new AngularDevUriWatcher("http://localhost:65400");
                    Application.ContentProvider = new EmbeddedContentProvider("Angular/dist");

                    Application.Run(window, "/index.html");
                }
        }