Exemple #1
0
        private static void OnExit(object sender, EventArgs e)
        {
            // Clear tray icon on close
            if (TrayIcon != null)
            {
                TrayIcon.Visible = false;
            }

            // On send clear priority
            if (_protoClient != null)
            {
                _captureEnabled = false;
                ProtoClient.ClearPriority(Settings.HyperionMessagePriority);
                Thread.Sleep(50);
                ProtoClient.ClearPriority(Settings.HyperionMessagePriority);
                ProtoClient.Disconnect();
            }

            if (Settings.ApiEnabled)
            {
                _apiServer.StopServer();
            }

            Environment.Exit(0);
        }
Exemple #2
0
        public void Init(bool reInit = false, bool forceOn = false)
        {
            LOG.Info($"Initialization requested with parameters reInit={reInit}, forceOn={forceOn}");
            if (_initLock)
            {
                LOG.Info("Initialization already in progress. Ignoring request.");
                return;
            }
            _initLock = true;
            LOG.Info("Initialization lock set");

            // Stop current capture first on reinit
            if (reInit)
            {
                ToggleCapture(CaptureCommand.OFF, false, false);
            }

            if (SettingsManager.CaptureOnStartup || forceOn)
            {
                ToggleCapture(CaptureCommand.ON);
            }

            _apiServer?.StopServer(); // Always stop current server before starting again
            if (SettingsManager.ApiEnabled)
            {
                _apiServer = new ApiServer(this);
                _apiServer.StartServer("+", SettingsManager.ApiPort.ToString());
            }

            _initLock = false;
            LOG.Info("Initialization lock unset");
        }
        private static void OnExit(object sender, EventArgs e)
        {
            LOG.Info("Exiting Application");
            // Clear tray icon on close
            if (TrayIcon != null)
            {
                TrayIcon.Visible = false;
            }

            // Send clear priority
            if (ProtoClient.Initialized)
            {
                TerminateScreenCapture();
                ProtoClient.TryClearPriority(SettingsManager.HyperionMessagePriority);
                DisconnectProtoClient();
            }

            if (SettingsManager.ApiEnabled)
            {
                _apiServer.StopServer();
            }

            // Unregister various event handlers
            SystemEvents.PowerModeChanged -= PowerModeChanged;
            SystemEvents.SessionSwitch    -= SessionSwitched;
            LOG.Info("Exit cleanup complete");
            Environment.Exit(0);
        }
        private static void ExecuteInitialization(bool reInit, bool forceOn)
        {
            LOG.Info($"Initialization requested with parameters reInit={reInit}, forceOn={forceOn}");
            // Stop current capture first on reinit
            if (reInit)
            {
                TerminateScreenCapture();
                DisconnectProtoClient();
            }

            if (SettingsManager.CaptureOnStartup || forceOn)
            {
                ToggleCapture(CaptureCommand.ON);
            }

            if (SettingsManager.ApiEnabled)
            {
                _apiServer = new ApiServer();
                _apiServer.StartServer("localhost", SettingsManager.ApiPort.ToString());
            }
            else
            {
                _apiServer?.StopServer();
            }
            _initLock = false;
            LOG.Info("Initialization lock unset");
        }
Exemple #5
0
        public static void Init(bool reInit = false, bool forceOn = false)
        {
            if (!_initLock)
            {
                _initLock = true;

                // Stop current capture first on reinit
                if (reInit)
                {
                    _captureEnabled = false;
                    Thread.Sleep(500 + Settings.CaptureInterval);

                    if (_protoClient != null)
                    {
                        ProtoClient.Disconnect();
                        Thread.Sleep(500);
                    }
                }

                _protoClient = new ProtoClient();
                ProtoClient.Init(Settings.HyperionServerIp, Settings.HyperionServerPort,
                                 Settings.HyperionMessagePriority);

                if (Settings.CaptureOnStartup || forceOn)
                {
                    if (ProtoClient.IsConnected())
                    {
                        Notifications.Info($"Connected to Hyperion server on {Settings.HyperionServerIp}!");
                        ToggleCapture("ON");
                    }
                }

                if (Settings.ApiEnabled)
                {
                    _apiServer = new ApiServer();
                    _apiServer.StartServer("localhost", Settings.ApiPort.ToString());
                }
                else
                {
                    _apiServer?.StopServer();
                }

                _initLock = false;
            }
        }
Exemple #6
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     LOG.Info("Initiating cleanup");
     // Unregister various event handlers
     SystemEvents.PowerModeChanged -= PowerModeChanged;
     SystemEvents.SessionSwitch    -= SessionSwitched;
     // Clear tray icon on close
     if (_trayIcon != null)
     {
         _trayIcon.Visible = false;
     }
     if (SettingsManager.ApiEnabled)
     {
         _apiServer.StopServer();
     }
     ToggleCapture(CaptureCommand.OFF, false, false);
     LOG.Info("**********************************************************");
     LOG.Info("Exit cleanup complete. Application normal shutdown.");
     LOG.Info("**********************************************************");
 }