Пример #1
0
 /// <summary>
 ///     Click event for the network cards.
 /// </summary>
 /// <param name="localNetworkInterface">The clicked network card.</param>
 public void NetworkCardClicked(LocalNetworkInterface localNetworkInterface)
 {
     if (localNetworkInterface == null)
     {
         return;
     }
     if (localNetworkInterface.UseDnsCrypt)
     {
         var status = LocalNetworkInterfaceManager.SetNameservers(localNetworkInterface, new List <string>(),
                                                                  NetworkInterfaceComponent.IPv4);
         LocalNetworkInterfaceManager.SetNameservers(localNetworkInterface, new List <string>(),
                                                     NetworkInterfaceComponent.IPv6);
         localNetworkInterface.UseDnsCrypt = !status;
     }
     else
     {
         var dns4 = new List <string>();
         var dns6 = new List <string>();
         if (PrimaryResolver != null)
         {
             if (!string.IsNullOrEmpty(PrimaryResolver.ProviderPublicKey))
             {
                 // only add the local address if the proxy is running
                 if (PrimaryDnsCryptProxyManager.DnsCryptProxy.IsReady && PrimaryDnsCryptProxyManager.IsDnsCryptProxyRunning())
                 {
                     dns4.Add(Global.PrimaryResolverAddress);
                     if (_userData.UseIpv6)
                     {
                         dns6.Add(Global.PrimaryResolverAddress6);
                     }
                 }
             }
         }
         if (SecondaryResolver != null)
         {
             if (!string.IsNullOrEmpty(SecondaryResolver.ProviderPublicKey))
             {
                 // only add the local address if the proxy is running
                 if (SecondaryDnsCryptProxyManager.DnsCryptProxy.IsReady && SecondaryDnsCryptProxyManager.IsDnsCryptProxyRunning())
                 {
                     dns4.Add(Global.SecondaryResolverAddress);
                     if (_userData.UseIpv6)
                     {
                         dns6.Add(Global.SecondaryResolverAddress6);
                     }
                 }
             }
         }
         var status = LocalNetworkInterfaceManager.SetNameservers(localNetworkInterface, dns4, NetworkInterfaceComponent.IPv4);
         if (_userData.UseIpv6)
         {
             LocalNetworkInterfaceManager.SetNameservers(localNetworkInterface, dns6, NetworkInterfaceComponent.IPv6);
         }
         localNetworkInterface.UseDnsCrypt = status;
     }
     LoadNetworkCards();
 }
Пример #2
0
        /// <summary>
        ///     Load the local network cards.
        /// </summary>
        private void LoadNetworkCards()
        {
            var localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(ShowHiddenCards, false);

            _localNetworkInterfaces.Clear();
            if (localNetworkInterfaces.Count != 0)
            {
                foreach (var localNetworkInterface in localNetworkInterfaces)
                {
                    _localNetworkInterfaces.Add(localNetworkInterface);
                }
            }
        }
Пример #3
0
        /// <summary>
        ///     Uninstall all installed dnscrypt-proxy services.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="NetworkInformationException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public async void UninstallServices()
        {
            var result = _windowManager.ShowMetroMessageBox(
                LocalizationEx.GetUiString("dialog_message_uninstall", Thread.CurrentThread.CurrentCulture),
                LocalizationEx.GetUiString("dialog_uninstall_title", Thread.CurrentThread.CurrentCulture),
                MessageBoxButton.YesNo, BoxType.Default);

            if (result == MessageBoxResult.Yes)
            {
                IsUninstallingServices = true;
                await Task.Run(() =>
                {
                    PrimaryDnsCryptProxyManager.Uninstall();
                    SecondaryDnsCryptProxyManager.Uninstall();
                }).ConfigureAwait(false);

                Thread.Sleep(Global.ServiceUninstallTime);
                IsUninstallingServices = false;
            }

            _isPrimaryResolverRunning = PrimaryDnsCryptProxyManager.IsDnsCryptProxyRunning();
            NotifyOfPropertyChange(() => IsPrimaryResolverRunning);
            _isSecondaryResolverRunning = SecondaryDnsCryptProxyManager.IsDnsCryptProxyRunning();
            NotifyOfPropertyChange(() => IsSecondaryResolverRunning);

            // recover the network interfaces (also the hidden and down cards)
            foreach (var nic in LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(true, false))
            {
                if (!nic.UseDnsCrypt)
                {
                    continue;
                }
                var status = LocalNetworkInterfaceManager.SetNameservers(nic, new List <string>(), NetworkInterfaceComponent.IPv4);
                var card   = _localNetworkInterfaces.SingleOrDefault(n => n.Description.Equals(nic.Description));
                if (card != null)
                {
                    card.UseDnsCrypt = !status;
                }
            }
        }
Пример #4
0
        private async void InitializeApplication()
        {
            try
            {
                if (IsAdministrator())
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_missing", Thread.CurrentThread.CurrentCulture);
                    await Task.Delay(3000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_check", Thread.CurrentThread.CurrentCulture);
                if (PrerequisiteHelper.IsRedistributablePackageInstalled())
                {
                    ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_already_installed", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_installing", Thread.CurrentThread.CurrentCulture);
                    //minisign needs this (to verify the installer with libsodium)
                    await PrerequisiteHelper.DownloadAndInstallRedistributablePackage();

                    if (PrerequisiteHelper.IsRedistributablePackageInstalled())
                    {
                        ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_ready", Thread.CurrentThread.CurrentCulture);
                        await Task.Delay(1000).ConfigureAwait(false);
                    }
                }

                if (Properties.Settings.Default.AutoUpdate)
                {
                    ProgressText = LocalizationEx.GetUiString("loader_checking_version", Thread.CurrentThread.CurrentCulture);
                    //TODO: remove in future version (for now we only have one channel)
                    Properties.Settings.Default.MinUpdateType = 2;
                    Properties.Settings.Default.Save();
                    var minUpdateType = (UpdateType)Properties.Settings.Default.MinUpdateType;
                    var update        = await ApplicationUpdater.CheckForRemoteUpdateAsync(minUpdateType).ConfigureAwait(false);

                    if (update.CanUpdate)
                    {
                        ProgressText =
                            string.Format(LocalizationEx.GetUiString("loader_new_version_found", Thread.CurrentThread.CurrentCulture),
                                          update.Update.Version);
                        await Task.Delay(200).ConfigureAwait(false);

                        var installer = await StartRemoteUpdateDownload(update).ConfigureAwait(false);

                        if (!string.IsNullOrEmpty(installer) && File.Exists(installer))
                        {
                            ProgressText = LocalizationEx.GetUiString("loader_starting_update", Thread.CurrentThread.CurrentCulture);
                            await Task.Delay(200).ConfigureAwait(false);

                            Process.Start(installer);
                            Process.GetCurrentProcess().Kill();
                        }
                        else
                        {
                            await Task.Delay(500).ConfigureAwait(false);

                            ProgressText = LocalizationEx.GetUiString("loader_update_failed", Thread.CurrentThread.CurrentCulture);
                        }
                    }
                    else
                    {
                        ProgressText = LocalizationEx.GetUiString("loader_latest_version", Thread.CurrentThread.CurrentCulture);
                    }
                }
                else
                {
                    await Task.Delay(500).ConfigureAwait(false);
                }

                ProgressText =
                    string.Format(LocalizationEx.GetUiString("loader_validate_folder", Thread.CurrentThread.CurrentCulture),
                                  Global.DnsCryptProxyFolder);
                var validatedFolder = ValidateDnsCryptProxyFolder();
                if (validatedFolder.Count == 0)
                {
                    ProgressText = LocalizationEx.GetUiString("loader_all_files_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    var fileErrors = "";
                    foreach (var pair in validatedFolder)
                    {
                        fileErrors += $"{pair.Key}: {pair.Value}\n";
                    }

                    ProgressText =
                        string.Format(
                            LocalizationEx.GetUiString("loader_missing_files", Thread.CurrentThread.CurrentCulture).Replace("\\n", "\n"),
                            Global.DnsCryptProxyFolder, fileErrors, Global.ApplicationName);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = string.Format(LocalizationEx.GetUiString("loader_loading", Thread.CurrentThread.CurrentCulture),
                                             Global.DnsCryptConfigurationFile);
                if (DnscryptProxyConfigurationManager.LoadConfiguration())
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_successfully_loaded", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    _mainViewModel.DnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration;
                }
                else
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_failed_loading", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_loading_network_cards", Thread.CurrentThread.CurrentCulture);

                List <LocalNetworkInterface> localNetworkInterfaces;
                if (DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.Contains(Global.GlobalResolver))
                {
                    var dnsServer = new List <string>
                    {
                        Global.DefaultResolverIpv4,
                        Global.DefaultResolverIpv6
                    };
                    localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(dnsServer);
                }
                else
                {
                    localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(
                        DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.ToList());
                }
                _mainViewModel.LocalNetworkInterfaces = new BindableCollection <LocalNetworkInterface>();
                _mainViewModel.LocalNetworkInterfaces.AddRange(localNetworkInterfaces);
                _mainViewModel.Initialize();
                ProgressText = LocalizationEx.GetUiString("loader_starting", Thread.CurrentThread.CurrentCulture);

                if (Properties.Settings.Default.TrayMode)
                {
                    Execute.OnUIThread(() => _windowManager.ShowWindow(_systemTrayViewModel));
                    Execute.OnUIThread(() => _systemTrayViewModel.ShowWindow());
                }
                else
                {
                    Execute.OnUIThread(() => _windowManager.ShowWindow(_mainViewModel));
                }

                TryClose(true);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
Пример #5
0
        private async void InitializeApplication()
        {
            try
            {
                if (IsAdministrator())
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_missing", Thread.CurrentThread.CurrentCulture);
                    await Task.Delay(3000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_checking_version", Thread.CurrentThread.CurrentCulture);
                var update = await ApplicationUpdater.CheckForRemoteUpdateAsync().ConfigureAwait(false);

                if (update.CanUpdate)
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_new_version_found", Thread.CurrentThread.CurrentCulture),
                                      update.Update.Version);
                    await Task.Delay(200).ConfigureAwait(false);

                    var installer = await StartRemoteUpdateDownload(update).ConfigureAwait(false);

                    if (!string.IsNullOrEmpty(installer) && File.Exists(installer))
                    {
                        ProgressText = LocalizationEx.GetUiString("loader_starting_update", Thread.CurrentThread.CurrentCulture);
                        await Task.Delay(200).ConfigureAwait(false);

                        Process.Start(installer);
                        Process.GetCurrentProcess().Kill();
                    }
                    else
                    {
                        await Task.Delay(500).ConfigureAwait(false);

                        ProgressText = LocalizationEx.GetUiString("loader_update_failed", Thread.CurrentThread.CurrentCulture);
                    }
                }
                else
                {
                    ProgressText = LocalizationEx.GetUiString("loader_latest_version", Thread.CurrentThread.CurrentCulture);
                }

                ProgressText =
                    string.Format(LocalizationEx.GetUiString("loader_validate_folder", Thread.CurrentThread.CurrentCulture),
                                  Global.DnsCryptProxyFolder);
                var validatedFolder = ValidateDnsCryptProxyFolder();
                if (validatedFolder.Count == 0)
                {
                    ProgressText = LocalizationEx.GetUiString("loader_all_files_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    var fileErrors = "";
                    foreach (var pair in validatedFolder)
                    {
                        fileErrors += $"{pair.Key}: {pair.Value}\n";
                    }

                    ProgressText =
                        string.Format(
                            LocalizationEx.GetUiString("loader_missing_files", Thread.CurrentThread.CurrentCulture).Replace("\\n", "\n"),
                            Global.DnsCryptProxyFolder, fileErrors, Global.ApplicationName);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = string.Format(LocalizationEx.GetUiString("loader_loading", Thread.CurrentThread.CurrentCulture),
                                             Global.DnsCryptConfigurationFile);
                if (DnscryptProxyConfigurationManager.LoadConfiguration())
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_successfully_loaded", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    _mainViewModel.DnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration;
                }
                else
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_failed_loading", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_loading_network_cards", Thread.CurrentThread.CurrentCulture);
                var localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(
                    DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.ToList());
                _mainViewModel.LocalNetworkInterfaces = new BindableCollection <LocalNetworkInterface>();
                _mainViewModel.LocalNetworkInterfaces.AddRange(localNetworkInterfaces);
                _mainViewModel.Initialize();
                ProgressText = LocalizationEx.GetUiString("loader_starting", Thread.CurrentThread.CurrentCulture);
                Execute.OnUIThread(() => _windowManager.ShowWindow(_mainViewModel));
                TryClose(true);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }
        private bool HandleNetworkInterfaces(bool enable = true)
        {
            var succedded = true;

            try
            {
                var listenAddresses = new List <string>(_dnscryptProxyConfiguration.listen_addresses);
                if (listenAddresses.Count > 0)
                {
                    var localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(listenAddresses);
                    if (localNetworkInterfaces.Count > 0)
                    {
                        foreach (var localNetworkInterface in localNetworkInterfaces)
                        {
                            if (enable)
                            {
                                if (!localNetworkInterface.UseDnsCrypt)
                                {
                                    if (LocalNetworkInterfaceManager.SetNameservers(localNetworkInterface, LocalNetworkInterfaceManager.ConvertToDnsList(listenAddresses)))
                                    {
                                        _logger.Log($"set DNS for {localNetworkInterface.Name} succedded", Category.Info, Priority.Medium);
                                    }
                                    else
                                    {
                                        _logger.Log($"failed to unset DNS for {localNetworkInterface.Name}", Category.Warn, Priority.High);
                                        succedded = false;
                                    }
                                }
                            }
                            else
                            {
                                if (localNetworkInterface.UseDnsCrypt)
                                {
                                    if (LocalNetworkInterfaceManager.UnsetNameservers(localNetworkInterface))
                                    {
                                        _logger.Log($"unset DNS for {localNetworkInterface.Name} succedded", Category.Info, Priority.Medium);
                                    }
                                    else
                                    {
                                        _logger.Log($"failed to unset DNS for {localNetworkInterface.Name}", Category.Warn, Priority.High);
                                        succedded = false;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        _logger.Log($"there are no network interfaces for configuration", Category.Warn, Priority.High);
                        succedded = false;
                    }
                }
                else
                {
                    _logger.Log($"missing listen_addresses in dnscrypt-proxy configuration", Category.Warn, Priority.High);
                    succedded = false;
                }
            }
            catch (Exception exception)
            {
                _logger.Log($"HandleNetworkInterfaces {exception.Message}", Category.Exception, Priority.High);
                succedded = false;
            }
            return(succedded);
        }
Пример #7
0
        private async void InitializeApplication()
        {
            try
            {
                if (IsAdministrator())
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_available", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    ProgressText =
                        LocalizationEx.GetUiString("loader_administrative_rights_missing", Thread.CurrentThread.CurrentCulture);
                    await Task.Delay(3000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_check", Thread.CurrentThread.CurrentCulture);
                if (PrerequisiteHelper.IsRedistributablePackageInstalled())
                {
                    ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_already_installed", Thread.CurrentThread.CurrentCulture);
                }
                else
                {
                    //Note: if this is disabled, the auto update may not work
                    if (Properties.Settings.Default.InstallRedistributablePackage)
                    {
                        ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_installing",
                                                                  Thread.CurrentThread.CurrentCulture);
                        //minisign needs this (to verify the installer with libsodium)
                        await PrerequisiteHelper.DownloadAndInstallRedistributablePackage();

                        if (PrerequisiteHelper.IsRedistributablePackageInstalled())
                        {
                            ProgressText = LocalizationEx.GetUiString("loader_redistributable_package_ready",
                                                                      Thread.CurrentThread.CurrentCulture);
                            await Task.Delay(1000).ConfigureAwait(false);
                        }
                    }
                }

                ProgressText =
                    string.Format(LocalizationEx.GetUiString("loader_validate_folder", Thread.CurrentThread.CurrentCulture),
                                  Global.DnsCryptProxyFolder);
                var validatedFolder = ValidateDnsCryptProxyFolder();
                if (validatedFolder.Count == 0)
                {
                    ProgressText = LocalizationEx.GetUiString("loader_all_files_available", Thread.CurrentThread.CurrentCulture);
                }
                else if (validatedFolder.Count == 1 && validatedFolder.Single().Key == Global.DnsCryptConfigurationFile)
                {
                    File.Copy(
                        Path.Combine(Directory.GetCurrentDirectory(), Global.DnsCryptProxyFolder, Global.DnsCryptExampleConfigurationFile),
                        Path.Combine(Directory.GetCurrentDirectory(), Global.DnsCryptProxyFolder, Global.DnsCryptConfigurationFile),
                        false);
                }
                else
                {
                    var fileErrors = "";
                    foreach (var pair in validatedFolder)
                    {
                        fileErrors += $"{pair.Key}: {pair.Value}\n";
                    }

                    ProgressText =
                        string.Format(
                            LocalizationEx.GetUiString("loader_missing_files", Thread.CurrentThread.CurrentCulture).Replace("\\n", "\n"),
                            Global.DnsCryptProxyFolder, fileErrors, Global.ApplicationName);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                if (Properties.Settings.Default.BackupAndRestoreConfigOnUpdate)
                {
                    var tmpConfigPath = Path.Combine(Path.GetTempPath(), Global.DnsCryptConfigurationFile + ".bak");
                    if (File.Exists(tmpConfigPath))
                    {
                        ProgressText = string.Format(LocalizationEx.GetUiString("loader_restore_config", Thread.CurrentThread.CurrentCulture),
                                                     Global.DnsCryptConfigurationFile);
                        var configFile = Path.Combine(Directory.GetCurrentDirectory(), Global.DnsCryptProxyFolder, Global.DnsCryptConfigurationFile);
                        if (File.Exists(configFile))
                        {
                            if (File.Exists(configFile + ".bak"))
                            {
                                File.Delete(configFile + ".bak");
                            }
                            File.Move(configFile, configFile + ".bak");
                        }
                        File.Move(tmpConfigPath, configFile);
                        // update the configuration file
                        if (PatchHelper.Patch())
                        {
                            await Task.Delay(500).ConfigureAwait(false);
                        }
                    }
                }

                ProgressText = string.Format(LocalizationEx.GetUiString("loader_loading", Thread.CurrentThread.CurrentCulture),
                                             Global.DnsCryptConfigurationFile);
                if (DnscryptProxyConfigurationManager.LoadConfiguration())
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_successfully_loaded", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    _mainViewModel.DnscryptProxyConfiguration = DnscryptProxyConfigurationManager.DnscryptProxyConfiguration;
                }
                else
                {
                    ProgressText =
                        string.Format(LocalizationEx.GetUiString("loader_failed_loading", Thread.CurrentThread.CurrentCulture),
                                      Global.DnsCryptConfigurationFile);
                    await Task.Delay(5000).ConfigureAwait(false);

                    Process.GetCurrentProcess().Kill();
                }

                ProgressText = LocalizationEx.GetUiString("loader_loading_network_cards", Thread.CurrentThread.CurrentCulture);

                List <LocalNetworkInterface> localNetworkInterfaces;
                if (DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.Contains(Global.GlobalResolver))
                {
                    var dnsServer = new List <string>
                    {
                        Global.DefaultResolverIpv4,
                        Global.DefaultResolverIpv6
                    };
                    localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(dnsServer);
                }
                else
                {
                    localNetworkInterfaces = LocalNetworkInterfaceManager.GetLocalNetworkInterfaces(
                        DnscryptProxyConfigurationManager.DnscryptProxyConfiguration.listen_addresses.ToList());
                }
                _mainViewModel.LocalNetworkInterfaces = new BindableCollection <LocalNetworkInterface>();
                _mainViewModel.LocalNetworkInterfaces.AddRange(localNetworkInterfaces);
                _mainViewModel.Initialize();
                ProgressText = LocalizationEx.GetUiString("loader_starting", Thread.CurrentThread.CurrentCulture);

                if (Properties.Settings.Default.TrayMode)
                {
                    await Execute.OnUIThreadAsync(() => _windowManager.ShowWindowAsync(_systemTrayViewModel));

                    if (Properties.Settings.Default.StartInTray)
                    {
                        Execute.OnUIThread(() => _systemTrayViewModel.HideWindow());
                    }
                    else
                    {
                        await Execute.OnUIThreadAsync(() => _windowManager.ShowWindowAsync(_mainViewModel));
                    }
                }
                else
                {
                    await Execute.OnUIThreadAsync(() => _windowManager.ShowWindowAsync(_mainViewModel));
                }

                await TryCloseAsync(true);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
                throw;
            }
        }