Exemple #1
0
        private static electron.Electron.BrowserWindow CreateOptionsWindow()
        {
            var options = ObjectLiteral.Create <electron.Electron.BrowserWindowConstructorOptions>();

            options.width       = 440;
            options.height      = 565;
            options.title       = "Options";
            options.icon        = node.path.join(node.__dirname, "assets/app-icon/png/32.png");
            options.skipTaskbar = true;
            options.parent      = Win;
            options.modal       = true;
            options.show        = false;
            options.maximizable = false;
            options.minimizable = false;
            options.resizable   = false;

            // Create the browser window.
            var optionsWin = new electron.Electron.BrowserWindow(options);

            optionsWin.setMenu(null);
            SetContextMenu(optionsWin);

            App.LoadWindow(optionsWin, "forms/OptionsForm.html");

            return(optionsWin);
        }
Exemple #2
0
        private static void CreateMainWindow()
        {
            var options = ObjectLiteral.Create <electron.Electron.BrowserWindowConstructorOptions>();

            options.width  = 600;
            options.height = 800;
            options.icon   = node.path.join(node.__dirname, "assets/app-icon/png/32.png");
            options.title  = GetAppNameWithVersion(true);
            options.show   = false;

            // Create the browser window.
            Win = new electron.Electron.BrowserWindow(options);
            SetContextMenu(Win);

            App.SetMainMenu();

            App.LoadWindow(Win, "forms/MainForm.html");

            Win.on(lit.closed, () =>
            {
                // 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.
                Win = null;
            });

            Win.on(lit.minimize, () =>
            {
                Win.setSkipTaskbar(true);
            });
        }
Exemple #3
0
        private static void LoadWindow(electron.Electron.BrowserWindow win, string page)
        {
            var windowUrl = ObjectLiteral.Create <node.url.URL>();

            windowUrl.pathname = node.path.join(node.__dirname, page);
            windowUrl.protocol = "file:";

            var formattedUrl = node.url.format(windowUrl);

            // and load the index.html of the app.
            win.loadURL(formattedUrl);
        }
Exemple #4
0
        public static void InitGlobals()
        {
            node.require.Self("./bridge.js");
            node.require.Self("./UserSettings.js");
            node.require.Self("./newtonsoft.json.js");

            // The call below is required to initialize a global var 'Electron'.
            var Electron = (electron.Electron.AllElectron)node.require.Self("electron");

            // Keep a global reference of the window object, if you don't, the window will
            // be closed automatically when the JavaScript object is garbage collected.
            electron.Electron.BrowserWindow win = null;
        }
Exemple #5
0
        private static electron.Electron.BrowserWindow CreateSplashScreen()
        {
            var options = ObjectLiteral.Create <electron.Electron.BrowserWindowConstructorOptions>();

            options.width       = 600;
            options.height      = 400;
            options.icon        = node.path.join(node.__dirname, "assets/app-icon/png/32.png");
            options.title       = GetAppNameWithVersion(true);
            options.frame       = false;
            options.skipTaskbar = true;
            options.show        = false;

            // Create the browser window.
            var splash = new electron.Electron.BrowserWindow(options);

            App.LoadWindow(splash, "forms/SplashScreen.html");

            return(splash);
        }
Exemple #6
0
        private static void SetContextMenu(electron.Electron.BrowserWindow win)
        {
            var selectionMenuTemplate = new[]
            {
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "copy",
                    accelerator = CreateMenuAccelerator("Ctrl+C")
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    type = lit.separator
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "selectall",
                    accelerator = CreateMenuAccelerator("Ctrl+A")
                }
            };

            var inputMenuTemplate = new[]
            {
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "undo",
                    accelerator = CreateMenuAccelerator("Ctrl+Z")
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "redo",
                    accelerator = CreateMenuAccelerator("Ctrl+Y")
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    type = lit.separator
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "cut",
                    accelerator = CreateMenuAccelerator("Ctrl+X")
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "copy",
                    accelerator = CreateMenuAccelerator("Ctrl+C")
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "paste",
                    accelerator = CreateMenuAccelerator("Ctrl+V")
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    type = lit.separator
                },
                new electron.Electron.MenuItemConstructorOptions
                {
                    role        = "selectall",
                    accelerator = CreateMenuAccelerator("Ctrl+A")
                }
            };

            var selectionMenu = electron.Electron.Menu.buildFromTemplate(selectionMenuTemplate);
            var inputMenu     = electron.Electron.Menu.buildFromTemplate(inputMenuTemplate);

            win.webContents.on(lit.context_menu, (e, props) =>
            {
                if (props.isEditable)
                {
                    inputMenu.popup(win);
                }
                else if (props.selectionText != null && !string.IsNullOrEmpty(props.selectionText.Trim()))
                {
                    selectionMenu.popup(win);
                }
            });
        }
Exemple #7
0
        private static void SetMainMenuForOptions(electron.Electron.BrowserWindow win)
        {
            var fileMenu = new electron.Electron.MenuItemConstructorOptions
            {
                label   = "File",
                submenu = new[]
                {
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        label = "Close",
                        role  = "close"
                    }
                }
            };

            var editMenu = new electron.Electron.MenuItemConstructorOptions
            {
                label   = "Edit",
                submenu = new[]
                {
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        role        = "undo",
                        accelerator = CreateMenuAccelerator("Ctrl+Z")
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        role        = "redo",
                        accelerator = CreateMenuAccelerator("Ctrl+Y")
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        type = lit.separator
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        role        = "cut",
                        accelerator = CreateMenuAccelerator("Ctrl+X")
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        role        = "copy",
                        accelerator = CreateMenuAccelerator("Ctrl+C")
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        role        = "paste",
                        accelerator = CreateMenuAccelerator("Ctrl+V")
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        type = lit.separator
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        role        = "selectall",
                        accelerator = CreateMenuAccelerator("Ctrl+A")
                    }
                }
            };

            var viewMenu = new electron.Electron.MenuItemConstructorOptions
            {
                label   = "View",
                submenu = new[]
                {
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        label       = "Reload",
                        accelerator = CreateMenuAccelerator("Ctrl+R"),
                        click       = (i, w, e) =>
                        {
                            w?.webContents.reload();
                        }
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        label       = "Toggle DevTools",
                        accelerator = CreateMenuAccelerator("F12"),
                        click       = (i, w, e) =>
                        {
                            w?.webContents.toggleDevTools();
                        }
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        type = lit.separator
                    },
                    new electron.Electron.MenuItemConstructorOptions
                    {
                        label   = "Theme",
                        submenu = new []
                        {
                            new electron.Electron.MenuItemConstructorOptions
                            {
                                type     = lit.radio,
                                label    = "Light",
                                @checked = true,
                                click    = (i, w, e) =>
                                {
                                    Win.webContents.send(Constants.IPC.ToggleTheme);
                                }
                            },
                            new electron.Electron.MenuItemConstructorOptions
                            {
                                type  = lit.radio,
                                label = "Dark",
                                click = (i, w, e) =>
                                {
                                    Win.webContents.send(Constants.IPC.ToggleTheme);
                                }
                            }
                        }
                    }
                }
            };

            var optionsMenu = electron.Electron.Menu.buildFromTemplate(new[] { fileMenu, editMenu, viewMenu });

            win.setMenu(optionsMenu);
        }