protected override void OnClosed(EventArgs e) { if (ProfileRepositiory.SelectedProfile != null) { ProfileRepositiory.SaveProfile(ProfileRepositiory.SelectedProfile); } if (notifyIcon != null) { notifyIcon.Dispose(); notifyIcon = null; } _console.Dispose(); Application.Current.Shutdown(); }
private async void OnLaunchButtonClicked(object sender, RoutedEventArgs e) { ProfileRepositiory.SaveProfiles(launcherViewModel.Profiles); ProfileRepositiory.SelectedProfile = launcherViewModel.SelectedProfile; ProfileRepositiory.SaveSelectedProfileId(launcherViewModel.SelectedProfile.Id); var launcherOptions = launcherViewModel.SelectedProfile.LauncherOptions; string validationMessage; if (!launcherOptions.Validate(out validationMessage)) { ShowError(validationMessage); return; } IsEnabled = false; string originalTitle = Title; string message = $"Connecting to {launcherOptions.ServerEndpoint}";; Title = message; Program.Console.Info(message); try { await Launcher.Launch(launcherOptions); } catch (AggregateException ex) { HandleException(ex, originalTitle); return; } catch (Exception ex) { HandleException(ex, originalTitle); return; } launchCallback(launcherViewModel.SelectedProfile); Close(); }
internal LauncherWindow(Action <Profile> launchCallback) { this.launchCallback = launchCallback; InitializeComponent(); launcherViewModel = new LauncherViewModel(pwd => passwordBox.Password = pwd); var profiles = ProfileRepositiory.LoadProfiles(); if (profiles != null) { launcherViewModel.Profiles = new ObservableCollection <Profile>(profiles); } string selectedProfileId = ProfileRepositiory.LoadSelectedProfileId(); if (profiles != null && !string.IsNullOrEmpty(selectedProfileId)) { launcherViewModel.SelectedProfile = launcherViewModel.Profiles.FirstOrDefault(p => p.Id == selectedProfileId) ?? launcherViewModel.Profiles.FirstOrDefault(); } DataContext = launcherViewModel; }