Ejemplo n.º 1
0
        protected void InitializePlatform()
        {
            switch (DesktopInterop.CurrentPlatform)
            {
            case PluginPlatform.MacOS:
                this.Padding = 10;
                break;
            }

            bool enableDaemonWatchdog = DesktopInterop.CurrentPlatform switch
            {
                PluginPlatform.Windows => true,
                PluginPlatform.MacOS => true,
                _ => false,
            };

            if (App.EnableTrayIcon)
            {
                trayIcon = new TrayIcon(this);
                if (WindowState == WindowState.Minimized)
                {
                    this.Visible       = false;
                    this.ShowInTaskbar = false;
                }
                this.WindowStateChanged += (sender, e) =>
                {
                    switch (this.WindowState)
                    {
                    case WindowState.Normal:
                    case WindowState.Maximized:
                        this.Visible       = true;
                        this.ShowInTaskbar = true;
                        break;

                    case WindowState.Minimized:
                        this.Visible       = false;
                        this.ShowInTaskbar = false;
                        break;
                    }
                };
                Application.Instance.Terminating += (sender, e) => trayIcon.Dispose();
            }

            if (App.EnableDaemonWatchdog)
            {
                // Check if daemon is already active, if not then start it as a subprocess if it exists in the local path.
                if (!Instance.Exists("OpenTabletDriver.Daemon") && DaemonWatchdog.CanExecute)
                {
                    var watchdog = new DaemonWatchdog();
                    watchdog.Start();
                    watchdog.DaemonExited += (sender, e) =>
                    {
                        Application.Instance.AsyncInvoke(() =>
                        {
                            var dialogResult = MessageBox.Show(
                                this,
                                "Fatal: The OpenTabletDriver Daemon has exited. Do you want to restart it?",
                                "OpenTabletDriver Fatal Error",
                                MessageBoxButtons.YesNo,
                                MessageBoxType.Error
                                );
                            switch (dialogResult)
                            {
                            case DialogResult.Yes:
                                watchdog.Dispose();
                                watchdog.Start();
                                break;

                            case DialogResult.No:
                            default:
                                Environment.Exit(0);
                                break;
                            }
                        });
                    };
                    this.Closing += (sender, e) =>
                    {
                        watchdog.Dispose();
                    };
                }
            }
        }
Ejemplo n.º 2
0
        private void ApplyPlatformQuirks()
        {
            this.Padding = SystemInfo.CurrentPlatform switch
            {
                RuntimePlatform.MacOS => new Padding(10),
                _ => new Padding(0)
            };

            this.ClientSize = SystemInfo.CurrentPlatform switch
            {
                RuntimePlatform.MacOS => new Size(970, 770),
                _ => new Size(960, 760)
            };

            bool enableTrayIcon = SystemInfo.CurrentPlatform switch
            {
                RuntimePlatform.Windows => true,
                RuntimePlatform.MacOS => true,
                _ => false
            };

            bool enableDaemonWatchdog = SystemInfo.CurrentPlatform switch
            {
                RuntimePlatform.Windows => true,
                RuntimePlatform.MacOS => true,
                _ => false,
            };

            if (enableTrayIcon)
            {
                var trayIcon = new TrayIcon(this);
                this.WindowStateChanged += (sender, e) =>
                {
                    switch (this.WindowState)
                    {
                    case WindowState.Normal:
                    case WindowState.Maximized:
                        this.ShowInTaskbar = true;
                        break;

                    case WindowState.Minimized:
                        this.ShowInTaskbar = false;
                        this.Visible       = false;
                        break;
                    }
                };
                Application.Instance.Terminating += (sender, e) => trayIcon.Dispose();
            }

            if (enableDaemonWatchdog)
            {
                // Check if daemon is already active, if not then start it as a subprocess if it exists in the local path.
                if (!Instance.Exists("OpenTabletDriver.Daemon") && DaemonWatchdog.CanExecute)
                {
                    var watchdog = new DaemonWatchdog();
                    watchdog.Start();
                    watchdog.DaemonExited += (sender, e) =>
                    {
                        var dialogResult = MessageBox.Show(
                            this,
                            "Fatal: The OpenTabletDriver Daemon has exited. Do you want to restart OpenTabletDriver?",
                            "OpenTabletDriver Fatal Error",
                            MessageBoxButtons.YesNo
                            );
                        switch (dialogResult)
                        {
                        case DialogResult.Yes:
                            Application.Instance.Restart();
                            break;

                        case DialogResult.No:
                        default:
                            Application.Instance.Quit();
                            break;
                        }
                    };
                    this.Closing += (sender, e) =>
                    {
                        watchdog.Dispose();
                    };
                }
            }
        }
Ejemplo n.º 3
0
        protected override void OnInitializePlatform(EventArgs e)
        {
            base.OnInitializePlatform(e);

            switch (DesktopInterop.CurrentPlatform)
            {
            case PluginPlatform.MacOS:
                this.Padding = 10;
                break;
            }

            if (DesktopInterop.CurrentPlatform == PluginPlatform.MacOS)
            {
                var bounds    = Screen.PrimaryScreen.Bounds;
                var minWidth  = Math.Min(970, bounds.Width * 0.9);
                var minHeight = Math.Min(770, bounds.Height * 0.9);
                this.ClientSize = new Size((int)minWidth, (int)minHeight);
            }

            if (App.EnableTrayIcon)
            {
                var trayIcon = new TrayIcon(this);
                if (WindowState == WindowState.Minimized)
                {
                    this.Visible       = false;
                    this.ShowInTaskbar = false;
                }
                this.WindowStateChanged += (sender, e) =>
                {
                    switch (this.WindowState)
                    {
                    case WindowState.Normal:
                    case WindowState.Maximized:
                        this.Visible       = true;
                        this.ShowInTaskbar = true;
                        break;

                    case WindowState.Minimized:
                        this.Visible       = false;
                        this.ShowInTaskbar = false;
                        break;
                    }
                };
                Application.Instance.Terminating += (sender, e) => trayIcon.Dispose();
            }

            if (App.EnableDaemonWatchdog)
            {
                // Check if daemon is already active, if not then start it as a subprocess if it exists in the local path.
                if (!Instance.Exists("OpenTabletDriver.Daemon") && DaemonWatchdog.CanExecute)
                {
                    var watchdog = new DaemonWatchdog();
                    watchdog.Start();
                    watchdog.DaemonExited += (sender, e) =>
                    {
                        Application.Instance.AsyncInvoke(() =>
                        {
                            var dialogResult = MessageBox.Show(
                                this,
                                "Fatal: The OpenTabletDriver Daemon has exited. Do you want to restart it?",
                                "OpenTabletDriver Fatal Error",
                                MessageBoxButtons.YesNo,
                                MessageBoxType.Error
                                );
                            switch (dialogResult)
                            {
                            case DialogResult.Yes:
                                watchdog.Dispose();
                                watchdog.Start();
                                break;

                            case DialogResult.No:
                            default:
                                Environment.Exit(0);
                                break;
                            }
                        });
                    };
                    this.Closing += (sender, e) =>
                    {
                        watchdog.Dispose();
                    };
                }
            }
        }