Exemplo n.º 1
0
        public void OnLoad()
        {
            Task.Run(async() =>
            {
                _started = true;
                await CreateWindow();
                Electron.WindowManager.IsQuitOnWindowAllClosed = false;
                Electron.GlobalShortcut.Register(_config.Keybind, Show);
                _mainWindow.OnBlur += () =>
                {
                    if (_config.HideAfterLostFocus)
                    {
                        _mainWindow.Hide();
                    }
                };

                Electron.App.SetLoginItemSettings(new LoginSettings()
                {
                    OpenAtLogin = _config.RunOnStart
                });
            });
            Task.Run(() =>
            {
                NotifyIcon icon = new NotifyIcon();
                icon.Icon       = new Icon("icon.ico");
                icon.Text       = "Show EmojiPad";
                var strip       = new ContextMenuStrip();
                strip.SuspendLayout();
                strip.Size        = new Size(152, 44);
                icon.DoubleClick += (sender, args) =>
                {
                    Show();
                };
                var item1    = new ToolStripMenuItem("Show EmojiPad");
                item1.Size   = new Size(152, 22);
                item1.Click += (sender, args) =>
                {
                    Show();
                };
                var item2    = new ToolStripMenuItem("Exit EmojiPad");
                item2.Size   = new Size(152, 22);
                item2.Click += (sender, args) =>
                {
                    try
                    {
                        Electron.App.Exit();
                    }
                    catch
                    {
                    }
                };
                strip.Items.Add(item1);
                strip.Items.Add(item2);
                strip.ResumeLayout();
                icon.ContextMenuStrip = strip;
                icon.Visible          = true;

                Application.Run();
            });
        }
        public void Hide()
        {
            if (_browserWindow == null)
            {
                throw new InvalidOperationException("The window is not displayed");
            }

            _browserWindow.Hide();
        }
Exemplo n.º 3
0
 protected override Task OnCreatedAsync(BrowserWindow window, CancellationToken ct)
 {
     _logger.Verbose("Registering OnBlur event handler");
     window.OnBlur += () =>
     {
         _logger.Debug("Shell is blured, hiding it");
         window.Hide();
     };
     _logger.Verbose("Registering OnReadyToShow event handler");
     window.OnReadyToShow += () =>
     {
         _logger.Information("Shell is ready to be shown");
         window.Show();
     };
     return(Task.CompletedTask);
 }
        public async Task Display()
        {
            if (_browserWindow != null)
            {
                throw new InvalidOperationException("Already displayed");
            }

            _browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
            {
                Width  = 200,
                Height = 200,
                Show   = false
            });

            _browserWindow.SetClosable(false);
            _browserWindow.OnMinimize    += () => { _browserWindow.Hide(); };
            _browserWindow.OnReadyToShow += () => { _browserWindow.Show(); };
            var openMenuItem = new MenuItem
            {
                Label = "Ouvrir",
                Click = () =>
                {
                    _browserWindow.Show();
                }
            };
            var closeMenuItem = new MenuItem
            {
                Label = "Fermer",
                Click = () =>
                {
                    _browserWindow.Destroy();
                    Electron.Tray.Destroy();
                }
            };

            Electron.Tray.Show("/Assets/electron_32x32.png", new[] { openMenuItem, closeMenuItem });
        }
Exemplo n.º 5
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());
    }
Exemplo n.º 6
0
 public void Hide()
 {
     _mainWindow?.Hide();
 }
Exemplo n.º 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();
            }
        }
                                                             ));

        // 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());
    }