From be4d1d5cab016ce383f08f94824133a215f84fec Mon Sep 17 00:00:00 2001 From: Aleksandar Pesic Date: Thu, 12 Dec 2019 13:17:39 +0100 Subject: [PATCH] Reviewed async pattern throughout FluentTerminal.App project (#624) * Reviewed async pattern in App.xaml.cs. * Reviewed async pattern throughout FluentTerminal.App project. --- .../DialogServiceTests.cs | 10 +- .../Dialogs/IShellProfileSelectionDialog.cs | 2 +- FluentTerminal.App.Services/IDialogService.cs | 3 +- .../IImageFileSystemService.cs | 10 +- .../Implementation/DialogService.cs | 4 +- FluentTerminal.App.Services/Terminal.cs | 11 +- .../MainViewModel.cs | 2 +- .../ProfileViewModelBase.cs | 10 +- .../Settings/GeneralPageViewModel.cs | 8 +- .../Settings/KeyBindingViewModel.cs | 2 +- .../Settings/KeyBindingsPageViewModel.cs | 2 +- .../Settings/MousePageViewModel.cs | 2 +- .../Settings/TerminalPageViewModel.cs | 2 +- .../Settings/ThemesPageViewModel.cs | 6 +- .../ShellProfileViewModel.cs | 2 +- .../TerminalViewModel.cs | 2 +- .../ThemeViewModel.cs | 18 +-- .../Adapters/AppServiceConnectionAdapter.cs | 4 +- .../Adapters/ApplicationViewAdapter.cs | 18 +-- .../Dialogs/CreateKeyBindingDialog.xaml.cs | 28 ++--- .../Dialogs/CustomCommandDialog.xaml.cs | 10 +- .../Dialogs/InputDialog.xaml.cs | 17 ++- .../ShellProfileSelectionDialog.xaml.cs | 6 +- FluentTerminal.App/FluentTerminal.App.csproj | 1 - .../Services/FileSystemService.cs | 21 ++-- .../Services/ImageFileSystemService.cs | 117 +++++++++--------- .../Services/StartupTaskService.cs | 39 +++--- .../Utilities/StorageFileExtensions.cs | 25 ---- .../CommandProfileProviderViewModel.cs | 16 +-- FluentTerminal.App/Views/MainPage.xaml.cs | 4 +- FluentTerminal.App/Views/TerminalView.xaml.cs | 2 +- .../Views/XtermTerminalView.xaml.cs | 30 +++-- .../Enums/StartupTaskStatus.cs | 16 ++- 33 files changed, 203 insertions(+), 247 deletions(-) delete mode 100644 FluentTerminal.App/Utilities/StorageFileExtensions.cs diff --git a/FluentTerminal.App.Services.Test/DialogServiceTests.cs b/FluentTerminal.App.Services.Test/DialogServiceTests.cs index 0010774..bd47930 100644 --- a/FluentTerminal.App.Services.Test/DialogServiceTests.cs +++ b/FluentTerminal.App.Services.Test/DialogServiceTests.cs @@ -38,7 +38,7 @@ namespace FluentTerminal.App.Services.Test var buttons = _fixture.CreateMany(2); var dialogService = new DialogService(Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); - Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsnyc(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); + Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); showMessageDialogAsnyc.Should().Throw().And.ParamName.Should().Be("title"); } @@ -51,7 +51,7 @@ namespace FluentTerminal.App.Services.Test var buttons = _fixture.CreateMany(2); var dialogService = new DialogService(Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); - Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsnyc(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); + Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); showMessageDialogAsnyc.Should().Throw().And.ParamName.Should().Be("content"); } @@ -63,7 +63,7 @@ namespace FluentTerminal.App.Services.Test var content = _fixture.Create(); var dialogService = new DialogService(Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); - Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsnyc(title, content); + Func> showMessageDialogAsnyc = () => dialogService.ShowMessageDialogAsync(title, content); showMessageDialogAsnyc.Should().Throw().And.ParamName.Should().Be("buttons"); } @@ -77,7 +77,7 @@ namespace FluentTerminal.App.Services.Test var messageDialog = new Mock(); var dialogService = new DialogService(Mock.Of, () => messageDialog.Object, Mock.Of, Mock.Of, Mock.Of, Mock.Of, Mock.Of); - dialogService.ShowMessageDialogAsnyc(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); + dialogService.ShowMessageDialogAsync(title, content, buttons.ElementAt(0), buttons.ElementAt(1)); messageDialog.Verify(x => x.ShowAsync(), Times.Once); } @@ -90,7 +90,7 @@ namespace FluentTerminal.App.Services.Test dialogService.ShowProfileSelectionDialogAsync(); - shellProfileSelectionDialog.Verify(x => x.SelectProfile(), Times.Once); + shellProfileSelectionDialog.Verify(x => x.SelectProfileAsync(), Times.Once); } [Fact] diff --git a/FluentTerminal.App.Services/Dialogs/IShellProfileSelectionDialog.cs b/FluentTerminal.App.Services/Dialogs/IShellProfileSelectionDialog.cs index 46e7e4a..8219ab3 100644 --- a/FluentTerminal.App.Services/Dialogs/IShellProfileSelectionDialog.cs +++ b/FluentTerminal.App.Services/Dialogs/IShellProfileSelectionDialog.cs @@ -7,6 +7,6 @@ namespace FluentTerminal.App.Services.Dialogs { ShellProfile SelectedProfile { get; } - Task SelectProfile(); + Task SelectProfileAsync(); } } \ No newline at end of file diff --git a/FluentTerminal.App.Services/IDialogService.cs b/FluentTerminal.App.Services/IDialogService.cs index 3a40d01..78433a8 100644 --- a/FluentTerminal.App.Services/IDialogService.cs +++ b/FluentTerminal.App.Services/IDialogService.cs @@ -5,13 +5,14 @@ namespace FluentTerminal.App.Services { public enum DialogButton { + // ReSharper disable once InconsistentNaming OK, Cancel } public interface IDialogService { - Task ShowMessageDialogAsnyc(string title, string content, params DialogButton[] buttons); + Task ShowMessageDialogAsync(string title, string content, params DialogButton[] buttons); Task ShowProfileSelectionDialogAsync(); diff --git a/FluentTerminal.App.Services/IImageFileSystemService.cs b/FluentTerminal.App.Services/IImageFileSystemService.cs index 56e206b..29bd205 100644 --- a/FluentTerminal.App.Services/IImageFileSystemService.cs +++ b/FluentTerminal.App.Services/IImageFileSystemService.cs @@ -1,21 +1,19 @@ using FluentTerminal.Models; -using System; using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace FluentTerminal.App.Services { public interface IImageFileSystemService { - Task ImportTemporaryImageFile(IEnumerable fileTypes); + Task ImportTemporaryImageFileAsync(IEnumerable fileTypes); - Task RemoveTemporaryBackgroundThemeImage(); + Task RemoveTemporaryBackgroundThemeImageAsync(); - Task RemoveImportedImage(string fileName); + Task RemoveImportedImageAsync(string fileName); string EncodeImage(ImageFile imageFile); - Task ImportThemeImage(ImageFile backgroundImage, string encodedImage); + Task ImportThemeImageAsync(ImageFile backgroundImage, string encodedImage); } } diff --git a/FluentTerminal.App.Services/Implementation/DialogService.cs b/FluentTerminal.App.Services/Implementation/DialogService.cs index db06605..c84887d 100644 --- a/FluentTerminal.App.Services/Implementation/DialogService.cs +++ b/FluentTerminal.App.Services/Implementation/DialogService.cs @@ -37,7 +37,7 @@ namespace FluentTerminal.App.Services.Implementation return dialog.CreateKeyBinding(); } - public Task ShowMessageDialogAsnyc(string title, string content, params DialogButton[] buttons) + public Task ShowMessageDialogAsync(string title, string content, params DialogButton[] buttons) { if (string.IsNullOrWhiteSpace(title)) { @@ -78,7 +78,7 @@ namespace FluentTerminal.App.Services.Implementation { var dialog = _shellProfileSelectionDialogFactory(); - return dialog.SelectProfile(); + return dialog.SelectProfileAsync(); } public Task ShowSshConnectionInfoDialogAsync(SshProfile input = null) => diff --git a/FluentTerminal.App.Services/Terminal.cs b/FluentTerminal.App.Services/Terminal.cs index 35e2ffc..7ab3bbe 100644 --- a/FluentTerminal.App.Services/Terminal.cs +++ b/FluentTerminal.App.Services/Terminal.cs @@ -11,7 +11,7 @@ namespace FluentTerminal.App.Services { private readonly ITrayProcessCommunicationService _trayProcessCommunicationService; private Func> _selectedTextCallback; - private bool _closingFromUI; + private bool _closingFromUi; private bool _exited; private readonly bool _requireShellProcessStart; @@ -33,7 +33,7 @@ namespace FluentTerminal.App.Services _exited = true; Exited?.Invoke(this, status.ExitCode); - if (_closingFromUI || status.ExitCode <= 0) + if (_closingFromUi || status.ExitCode <= 0) { Closed?.Invoke(this, System.EventArgs.Empty); } @@ -82,7 +82,7 @@ namespace FluentTerminal.App.Services Closed?.Invoke(this, System.EventArgs.Empty); return; } - _closingFromUI = true; + _closingFromUi = true; _trayProcessCommunicationService.UnsubscribeFromTerminalOutput(Id); await _trayProcessCommunicationService.CloseTerminal(Id).ConfigureAwait(true); } @@ -134,11 +134,8 @@ namespace FluentTerminal.App.Services } /// - /// to be called by view when ready + /// To be called by view when ready /// - /// - /// - /// public async Task StartShellProcess(ShellProfile shellProfile, TerminalSize size, SessionType sessionType, string termState) { if (!_requireShellProcessStart && !string.IsNullOrEmpty(termState)) diff --git a/FluentTerminal.App.ViewModels/MainViewModel.cs b/FluentTerminal.App.ViewModels/MainViewModel.cs index e860489..1a12221 100644 --- a/FluentTerminal.App.ViewModels/MainViewModel.cs +++ b/FluentTerminal.App.ViewModels/MainViewModel.cs @@ -511,7 +511,7 @@ namespace FluentTerminal.App.ViewModels { if (_applicationSettings.ConfirmClosingWindows) { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmCloseWindow"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(false); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmCloseWindow"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(false); if (result == DialogButton.OK) { diff --git a/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs b/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs index 8191082..7b41e54 100644 --- a/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs +++ b/FluentTerminal.App.ViewModels/ProfileViewModelBase.cs @@ -135,7 +135,7 @@ namespace FluentTerminal.App.ViewModels private async Task Delete() { - var result = await DialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), + var result = await DialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDeleteProfile"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) @@ -171,7 +171,7 @@ namespace FluentTerminal.App.ViewModels { if (HasChanges()) { - var result = await DialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), + var result = await DialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDiscardChanges"), DialogButton.OK, DialogButton.Cancel) .ConfigureAwait(true); @@ -198,21 +198,21 @@ namespace FluentTerminal.App.ViewModels if (!string.IsNullOrEmpty(error)) { - await DialogService.ShowMessageDialogAsnyc(I18N.Translate("InvalidInput"), error, DialogButton.OK); + await DialogService.ShowMessageDialogAsync(I18N.Translate("InvalidInput"), error, DialogButton.OK); return; } if (EnvironmentVariables.Select(x => x.Name).Any(x => string.IsNullOrWhiteSpace(x))) { - await DialogService.ShowMessageDialogAsnyc(I18N.Translate("InvalidInput"), I18N.Translate("EmptyEnvironmentVariableName"), DialogButton.OK); + await DialogService.ShowMessageDialogAsync(I18N.Translate("InvalidInput"), I18N.Translate("EmptyEnvironmentVariableName"), DialogButton.OK); return; } if (EnvironmentVariables.Select(x => x.Name).Distinct().Count() != EnvironmentVariables.Count) { - await DialogService.ShowMessageDialogAsnyc(I18N.Translate("InvalidInput"), I18N.Translate("DuplicateEnvironmentVariable"), DialogButton.OK); + await DialogService.ShowMessageDialogAsync(I18N.Translate("InvalidInput"), I18N.Translate("DuplicateEnvironmentVariable"), DialogButton.OK); return; } diff --git a/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs index ed7375b..2393a08 100644 --- a/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/GeneralPageViewModel.cs @@ -391,7 +391,7 @@ namespace FluentTerminal.App.ViewModels.Settings private async Task RestoreDefaults() { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreGeneralSettings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreGeneralSettings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { @@ -442,6 +442,12 @@ namespace FluentTerminal.App.ViewModels.Settings StartupTaskErrorMessage = I18N.Translate("DisabledByPolicy"); CanEnableStartupTask = false; break; + + case StartupTaskStatus.EnabledByPolicy: + StartupTaskEnabled = true; + StartupTaskErrorMessage = I18N.TranslateWithFallback("EnabledByPolicy", "Enabled by policy."); + CanEnableStartupTask = false; + break; } } diff --git a/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs b/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs index 13cadad..295ff51 100644 --- a/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/KeyBindingViewModel.cs @@ -119,7 +119,7 @@ namespace FluentTerminal.App.ViewModels.Settings private async Task Delete() { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDeleteKeybindings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDeleteKeybindings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { diff --git a/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs index 134b996..21b5dac 100644 --- a/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/KeyBindingsPageViewModel.cs @@ -74,7 +74,7 @@ namespace FluentTerminal.App.ViewModels.Settings private async Task RestoreDefaults() { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreKeybindings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreKeybindings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { diff --git a/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs index faa2d60..86214a5 100644 --- a/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/MousePageViewModel.cs @@ -107,7 +107,7 @@ namespace FluentTerminal.App.ViewModels.Settings private async Task RestoreDefaults() { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreMouseSettings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreMouseSettings"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { diff --git a/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs index 8c651f7..02350b2 100644 --- a/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/TerminalPageViewModel.cs @@ -228,7 +228,7 @@ namespace FluentTerminal.App.ViewModels.Settings private async Task RestoreDefaults() { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreTerminalOptions"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreTerminalOptions"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { diff --git a/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs b/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs index bbff7c8..fbe8e7f 100644 --- a/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs +++ b/FluentTerminal.App.ViewModels/Settings/ThemesPageViewModel.cs @@ -136,7 +136,7 @@ namespace FluentTerminal.App.ViewModels.Settings if (parser == null) { - await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("ImportThemeFailed"), I18N.Translate("NoSuitableParserFound"), DialogButton.OK).ConfigureAwait(false); + await _dialogService.ShowMessageDialogAsync(I18N.Translate("ImportThemeFailed"), I18N.Translate("NoSuitableParserFound"), DialogButton.OK).ConfigureAwait(false); return; } @@ -146,7 +146,7 @@ namespace FluentTerminal.App.ViewModels.Settings if (!string.IsNullOrWhiteSpace(exportedTheme.EncodedImage)) { - var importedImage = await _imageFileSystemService.ImportThemeImage(exportedTheme.BackgroundImage, exportedTheme.EncodedImage); + var importedImage = await _imageFileSystemService.ImportThemeImageAsync(exportedTheme.BackgroundImage, exportedTheme.EncodedImage); exportedTheme.BackgroundImage = importedImage; } @@ -156,7 +156,7 @@ namespace FluentTerminal.App.ViewModels.Settings } catch (Exception exception) { - await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("ImportThemeFailed"), exception.Message, DialogButton.OK).ConfigureAwait(false); + await _dialogService.ShowMessageDialogAsync(I18N.Translate("ImportThemeFailed"), exception.Message, DialogButton.OK).ConfigureAwait(false); } } } diff --git a/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs b/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs index 2ebfd55..0ddd09f 100644 --- a/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs +++ b/FluentTerminal.App.ViewModels/ShellProfileViewModel.cs @@ -74,7 +74,7 @@ namespace FluentTerminal.App.ViewModels throw new InvalidOperationException(); } - var result = await DialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), + var result = await DialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmRestoreProfile"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) diff --git a/FluentTerminal.App.ViewModels/TerminalViewModel.cs b/FluentTerminal.App.ViewModels/TerminalViewModel.cs index 7ccec21..c7366f2 100644 --- a/FluentTerminal.App.ViewModels/TerminalViewModel.cs +++ b/FluentTerminal.App.ViewModels/TerminalViewModel.cs @@ -588,7 +588,7 @@ namespace FluentTerminal.App.ViewModels if (ApplicationSettings.ConfirmClosingTabs) { - var result = await DialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), String.Format(I18N.Translate("ConfirmCloseTab"), ShellTitle), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await DialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), String.Format(I18N.Translate("ConfirmCloseTab"), ShellTitle), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.Cancel) { diff --git a/FluentTerminal.App.ViewModels/ThemeViewModel.cs b/FluentTerminal.App.ViewModels/ThemeViewModel.cs index 987e026..5a2b358 100644 --- a/FluentTerminal.App.ViewModels/ThemeViewModel.cs +++ b/FluentTerminal.App.ViewModels/ThemeViewModel.cs @@ -326,7 +326,7 @@ namespace FluentTerminal.App.ViewModels if (Model.BackgroundImage != null && BackgroundThemeFile != Model?.BackgroundImage) { - await _imageFileSystemService.RemoveImportedImage( + await _imageFileSystemService.RemoveImportedImageAsync( $"{Model.BackgroundImage?.Name}{Model.BackgroundImage?.FileType}"); } @@ -383,7 +383,7 @@ namespace FluentTerminal.App.ViewModels if (!_fallbackTheme.Equals(changedTheme)) { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDiscardChanges"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDiscardChanges"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { @@ -418,7 +418,7 @@ namespace FluentTerminal.App.ViewModels InEditMode = false; - await _imageFileSystemService.RemoveTemporaryBackgroundThemeImage(); + await _imageFileSystemService.RemoveTemporaryBackgroundThemeImageAsync(); } } else @@ -435,12 +435,12 @@ namespace FluentTerminal.App.ViewModels private async Task Delete() { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDeleteTheme"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDeleteTheme"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { await DeleteBackgroundImageIfExists(); - await _imageFileSystemService.RemoveTemporaryBackgroundThemeImage(); + await _imageFileSystemService.RemoveTemporaryBackgroundThemeImageAsync(); Deleted?.Invoke(this, EventArgs.Empty); } @@ -448,7 +448,7 @@ namespace FluentTerminal.App.ViewModels private async Task DeleteBackgroundImage() { - var result = await _dialogService.ShowMessageDialogAsnyc(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDeleteBackgroundImage"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); + var result = await _dialogService.ShowMessageDialogAsync(I18N.Translate("PleaseConfirm"), I18N.Translate("ConfirmDeleteBackgroundImage"), DialogButton.OK, DialogButton.Cancel).ConfigureAwait(true); if (result == DialogButton.OK) { @@ -490,14 +490,14 @@ namespace FluentTerminal.App.ViewModels var importedBackgroundThemeFile = await _fileSystemService.SaveImageInRoaming(BackgroundThemeFile); - await _imageFileSystemService.RemoveTemporaryBackgroundThemeImage(); + await _imageFileSystemService.RemoveTemporaryBackgroundThemeImageAsync(); return importedBackgroundThemeFile; } private async Task ChooseBackgroundImage() { - var choosenImage = await _imageFileSystemService.ImportTemporaryImageFile(new[] { ".jpeg", ".png", ".jpg" }); + var choosenImage = await _imageFileSystemService.ImportTemporaryImageFileAsync(new[] { ".jpeg", ".png", ".jpg" }); if(choosenImage == null) { @@ -511,7 +511,7 @@ namespace FluentTerminal.App.ViewModels { if (BackgroundThemeFile != null) { - await _imageFileSystemService.RemoveImportedImage( + await _imageFileSystemService.RemoveImportedImageAsync( $"{Model.BackgroundImage?.Name}{Model.BackgroundImage?.FileType}"); BackgroundThemeFile = null; diff --git a/FluentTerminal.App/Adapters/AppServiceConnectionAdapter.cs b/FluentTerminal.App/Adapters/AppServiceConnectionAdapter.cs index 7a755a9..853ba49 100644 --- a/FluentTerminal.App/Adapters/AppServiceConnectionAdapter.cs +++ b/FluentTerminal.App/Adapters/AppServiceConnectionAdapter.cs @@ -23,9 +23,9 @@ namespace FluentTerminal.App.Adapters MessageReceived?.Invoke(this, args.Request.Message); } - public async Task SendMessageAsync(ValueSet message) + public Task SendMessageAsync(ValueSet message) { - var response = await _appServiceConnection.SendMessageAsync(message); + var response = await _appServiceConnection.SendMessageAsync(message).ConfigureAwait(false); if (response.Status == AppServiceResponseStatus.Success) { diff --git a/FluentTerminal.App/Adapters/ApplicationViewAdapter.cs b/FluentTerminal.App/Adapters/ApplicationViewAdapter.cs index 514cb48..e195c97 100644 --- a/FluentTerminal.App/Adapters/ApplicationViewAdapter.cs +++ b/FluentTerminal.App/Adapters/ApplicationViewAdapter.cs @@ -49,18 +49,6 @@ namespace FluentTerminal.App.Adapters return ApiInformation.IsApiContractPresent(api, version); } - public Task RunOnDispatcherThread(Action action, bool enforceNewSchedule = true) - { - if (!enforceNewSchedule && _dispatcher.HasThreadAccess) - { - action(); - - return Task.CompletedTask; - } - - return _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => action()).AsTask(); - } - public Task ExecuteOnUiThreadAsync(Action action, CoreDispatcherPriority priority = CoreDispatcherPriority.Normal, bool enforceNewSchedule = false) => _dispatcher.ExecuteAsync(action, priority, enforceNewSchedule); @@ -86,10 +74,8 @@ namespace FluentTerminal.App.Adapters _applicationView.ExitFullScreenMode(); return true; } - else - { - return _applicationView.TryEnterFullScreenMode(); - } + + return _applicationView.TryEnterFullScreenMode(); } private async void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) diff --git a/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs b/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs index dd0c083..2923e0a 100644 --- a/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs +++ b/FluentTerminal.App/Dialogs/CreateKeyBindingDialog.xaml.cs @@ -13,6 +13,7 @@ using FluentTerminal.App.Services; namespace FluentTerminal.App.Dialogs { + // ReSharper disable once RedundantExtendsListEntry public sealed partial class CreateKeyBindingDialog : ContentDialog, ICreateKeyBindingDialog, INotifyPropertyChanged { private readonly IAcceleratorKeyValidator _acceleratorKeyValidator; @@ -76,23 +77,13 @@ namespace FluentTerminal.App.Dialogs public event PropertyChangedEventHandler PropertyChanged; - public async Task CreateKeyBinding() + public Task CreateKeyBinding() { - var result = await ShowAsync(); - - if (result == ContentDialogResult.Primary) - { - return new KeyBinding - { - Alt = Alt, - Ctrl = Ctrl, - Key = Key, - Meta = Meta, - Shift = Shift - }; - } - - return null; + return ShowAsync().AsTask() + .ContinueWith( + t => t.Result == ContentDialogResult.Primary + ? new KeyBinding {Alt = Alt, Ctrl = Ctrl, Key = Key, Meta = Meta, Shift = Shift} + : null, TaskContinuationOptions.OnlyOnRanToCompletion); } private void OnResetButtonPreviewKeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) @@ -143,6 +134,11 @@ namespace FluentTerminal.App.Dialogs private void Set(ref T field, T value, [CallerMemberName]string propertyName = "") { + if (field?.Equals(value) ?? value == null) + { + return; + } + field = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } diff --git a/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs b/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs index 7eaa45b..ed4b435 100644 --- a/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs +++ b/FluentTerminal.App/Dialogs/CustomCommandDialog.xaml.cs @@ -236,7 +236,7 @@ namespace FluentTerminal.App.Dialogs } } - public async Task GetCustomCommandAsync(ShellProfile input = null) + public Task GetCustomCommandAsync(ShellProfile input = null) { ViewModel = new CommandProfileProviderViewModel(_settingsService, _applicationView, _trayProcessCommunicationService, _historyService, input); @@ -245,9 +245,11 @@ namespace FluentTerminal.App.Dialogs _showDialogOperation = ShowAsync(); - var result = await _showDialogOperation.AsTask().ContinueWith(t => _dialogResult); - - return result != ContentDialogResult.Primary ? null : ViewModel.Model; + return _showDialogOperation.AsTask().ContinueWith(t => + (t.Status == TaskStatus.Canceled || t.Status == TaskStatus.RanToCompletion) && + _dialogResult == ContentDialogResult.Primary + ? ViewModel.Model + : null); } } } diff --git a/FluentTerminal.App/Dialogs/InputDialog.xaml.cs b/FluentTerminal.App/Dialogs/InputDialog.xaml.cs index 9910791..bc23fe4 100644 --- a/FluentTerminal.App/Dialogs/InputDialog.xaml.cs +++ b/FluentTerminal.App/Dialogs/InputDialog.xaml.cs @@ -10,10 +10,12 @@ using FluentTerminal.App.Utilities; namespace FluentTerminal.App.Dialogs { + // ReSharper disable once RedundantExtendsListEntry public sealed partial class InputDialog : ContentDialog, IInputDialog { - private bool EnterPressed = false; + // ReSharper disable once RedundantDefaultMemberInitializer + private bool _enterPressed = false; public string Input { get; private set; } public InputDialog(ISettingsService settingsService) @@ -25,14 +27,11 @@ namespace FluentTerminal.App.Dialogs RequestedTheme = ContrastHelper.GetIdealThemeForBackgroundColor(currentTheme.Colors.Background); } - public async Task GetInput() + public Task GetInput() { - var result = await ShowAsync(); - if (result == ContentDialogResult.Primary || EnterPressed) - { - return Input; - } - return null; + return ShowAsync().AsTask() + .ContinueWith(t => t.Result == ContentDialogResult.Primary || _enterPressed ? Input : null, + TaskContinuationOptions.OnlyOnRanToCompletion); } public void SetTitle(string title) @@ -44,7 +43,7 @@ namespace FluentTerminal.App.Dialogs { if (e.Key == VirtualKey.Enter) { - EnterPressed = true; + _enterPressed = true; Hide(); } } diff --git a/FluentTerminal.App/Dialogs/ShellProfileSelectionDialog.xaml.cs b/FluentTerminal.App/Dialogs/ShellProfileSelectionDialog.xaml.cs index 362abad..df59fc1 100644 --- a/FluentTerminal.App/Dialogs/ShellProfileSelectionDialog.xaml.cs +++ b/FluentTerminal.App/Dialogs/ShellProfileSelectionDialog.xaml.cs @@ -33,9 +33,11 @@ namespace FluentTerminal.App.Dialogs RequestedTheme = ContrastHelper.GetIdealThemeForBackgroundColor(currentTheme.Colors.Background); } - public async Task SelectProfile() + public Task SelectProfileAsync() { - return await ShowAsync() == ContentDialogResult.Primary ? SelectedProfile : null; + return ShowAsync().AsTask() + .ContinueWith(t => t.Result == ContentDialogResult.Primary ? SelectedProfile : null, + TaskContinuationOptions.OnlyOnRanToCompletion); } } } \ No newline at end of file diff --git a/FluentTerminal.App/FluentTerminal.App.csproj b/FluentTerminal.App/FluentTerminal.App.csproj index a88a185..1cc86fc 100644 --- a/FluentTerminal.App/FluentTerminal.App.csproj +++ b/FluentTerminal.App/FluentTerminal.App.csproj @@ -163,7 +163,6 @@ EnvironmentVariablesView.xaml - KeyBindingsView.xaml diff --git a/FluentTerminal.App/Services/FileSystemService.cs b/FluentTerminal.App/Services/FileSystemService.cs index 1913507..d3aa73d 100644 --- a/FluentTerminal.App/Services/FileSystemService.cs +++ b/FluentTerminal.App/Services/FileSystemService.cs @@ -1,5 +1,4 @@ -using FluentTerminal.App.Utilities; -using FluentTerminal.Models; +using FluentTerminal.Models; using System; using System.Collections.Generic; using System.IO; @@ -12,15 +11,13 @@ namespace FluentTerminal.App.Services { public class FileSystemService : IFileSystemService { - public async Task BrowseForDirectory() + public Task BrowseForDirectory() { - var picker = new FolderPicker(); + var picker = new FolderPicker{ SuggestedStartLocation = PickerLocationId.ComputerFolder }; picker.FileTypeFilter.Add(".whatever"); // else a ComException is thrown - picker.SuggestedStartLocation = PickerLocationId.ComputerFolder; - var folder = await picker.PickSingleFolderAsync(); - - return folder?.Path; + return picker.PickSingleFolderAsync().AsTask() + .ContinueWith(t => t.Result?.Path, TaskContinuationOptions.OnlyOnRanToCompletion); } public async Task OpenFile(IEnumerable fileTypes) @@ -61,9 +58,11 @@ namespace FluentTerminal.App.Services public async Task SaveTextFile(string name, string fileTypeDescription, string fileType, string content) { - var picker = new FileSavePicker(); - picker.SuggestedStartLocation = PickerLocationId.ComputerFolder; - picker.SuggestedFileName = name; + var picker = new FileSavePicker + { + SuggestedStartLocation = PickerLocationId.ComputerFolder, + SuggestedFileName = name + }; picker.FileTypeChoices.Add(fileTypeDescription, new List { fileType }); var file = await picker.PickSaveFileAsync(); diff --git a/FluentTerminal.App/Services/ImageFileSystemService.cs b/FluentTerminal.App/Services/ImageFileSystemService.cs index c475166..576a867 100644 --- a/FluentTerminal.App/Services/ImageFileSystemService.cs +++ b/FluentTerminal.App/Services/ImageFileSystemService.cs @@ -2,27 +2,17 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Text; using System.Threading.Tasks; -using Windows.Graphics.Imaging; -using Windows.Security.Cryptography; using Windows.Storage; using Windows.Storage.Pickers; -using Windows.Storage.Streams; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media.Imaging; namespace FluentTerminal.App.Services { public class ImageFileSystemService : IImageFileSystemService { - public async Task RemoveTemporaryBackgroundThemeImage() + public async Task RemoveTemporaryBackgroundThemeImageAsync() { - var folder = await ApplicationData.Current - .LocalCacheFolder - .TryGetItemAsync("BackgroundThemeTmp"); + var folder = await ApplicationData.Current.LocalCacheFolder.TryGetItemAsync("BackgroundThemeTmp"); if (folder == null) { @@ -30,15 +20,15 @@ namespace FluentTerminal.App.Services } var backgroundThemeTmpFolder = - await ApplicationData.Current - .LocalCacheFolder - .GetFolderAsync( - "BackgroundThemeTmp"); + await ApplicationData.Current.LocalCacheFolder.GetFolderAsync("BackgroundThemeTmp"); - await backgroundThemeTmpFolder.DeleteAsync(); + if (backgroundThemeTmpFolder != null) + { + await backgroundThemeTmpFolder.DeleteAsync(); + } } - public async Task ImportTemporaryImageFile(IEnumerable fileTypes) + public async Task ImportTemporaryImageFileAsync(IEnumerable fileTypes) { var picker = new FileOpenPicker { @@ -52,46 +42,55 @@ namespace FluentTerminal.App.Services var file = await picker.PickSingleFileAsync(); - if (file != null) + if (file == null) { - var backgroundThemeTmpFolder = - await ApplicationData.Current - .LocalCacheFolder - .CreateFolderAsync( - "BackgroundThemeTmp", - CreationCollisionOption.OpenIfExists); - - var item = await backgroundThemeTmpFolder.TryGetItemAsync(file.Name); - - if (item == null) - { - var storageFile = await file.CopyAsync(backgroundThemeTmpFolder, file.Name); - - return new ImageFile( - storageFile.DisplayName, - storageFile.FileType, - $@"{backgroundThemeTmpFolder.Path}\{storageFile.Name}"); - } - - return new ImageFile( - file.DisplayName, - file.FileType, - $@"{backgroundThemeTmpFolder.Path}\{item.Name}"); + return null; } - return null; + var backgroundThemeTmpFolder = + await ApplicationData.Current.LocalCacheFolder.CreateFolderAsync("BackgroundThemeTmp", + CreationCollisionOption.OpenIfExists); + + if (backgroundThemeTmpFolder == null) + { + return null; + } + + var item = await backgroundThemeTmpFolder.TryGetItemAsync(file.Name); + + if (item == null) + { + var storageFile = await file.CopyAsync(backgroundThemeTmpFolder, file.Name); + + return new ImageFile(storageFile.DisplayName, storageFile.FileType, + $@"{backgroundThemeTmpFolder.Path}\{storageFile.Name}"); + } + + return new ImageFile(file.DisplayName, file.FileType, $@"{backgroundThemeTmpFolder.Path}\{item.Name}"); } - public async Task RemoveImportedImage(string fileName) + public async Task RemoveImportedImageAsync(string fileName) { - var backgroundThemeFolder = await ApplicationData.Current.RoamingFolder - .CreateFolderAsync("BackgroundTheme", CreationCollisionOption.OpenIfExists); + var backgroundThemeFolder = + await ApplicationData.Current.RoamingFolder.CreateFolderAsync("BackgroundTheme", + CreationCollisionOption.OpenIfExists); + + if (backgroundThemeFolder == null) + { + return; + } var item = await backgroundThemeFolder.TryGetItemAsync(fileName); - if (item != null) + if (item == null) + { + return; + } + + var file = await backgroundThemeFolder.GetFileAsync(fileName); + + if (file != null) { - var file = await backgroundThemeFolder.GetFileAsync(fileName); await file.DeleteAsync(StorageDeleteOption.PermanentDelete); } } @@ -111,29 +110,25 @@ namespace FluentTerminal.App.Services return Convert.ToBase64String(System.IO.File.ReadAllBytes(imageFile.Path)); } - public async Task ImportThemeImage(ImageFile backgroundImage, string encodedImage) + public async Task ImportThemeImageAsync(ImageFile backgroundImage, string encodedImage) { var bitmapData = Convert.FromBase64String(encodedImage); - MemoryStream streamBitmap = new MemoryStream(bitmapData); + var streamBitmap = new MemoryStream(bitmapData); - var localFolder = await ApplicationData.Current - .RoamingFolder - .CreateFolderAsync("BackgroundTheme", CreationCollisionOption.OpenIfExists); + var localFolder = + await ApplicationData.Current.RoamingFolder.CreateFolderAsync("BackgroundTheme", + CreationCollisionOption.OpenIfExists); - var storageFile = await localFolder - .CreateFileAsync( - $"{backgroundImage.Name}{backgroundImage.FileType}", - CreationCollisionOption.GenerateUniqueName); + var storageFile = await localFolder.CreateFileAsync($"{backgroundImage.Name}{backgroundImage.FileType}", + CreationCollisionOption.GenerateUniqueName); - using (Stream stream = await storageFile.OpenStreamForWriteAsync()) + using (var stream = await storageFile.OpenStreamForWriteAsync()) { stream.Seek(0, SeekOrigin.Begin); streamBitmap.WriteTo(stream); } - return new ImageFile(storageFile.DisplayName, - storageFile.FileType, - storageFile.Path); + return new ImageFile(storageFile.DisplayName, storageFile.FileType, storageFile.Path); } } } diff --git a/FluentTerminal.App/Services/StartupTaskService.cs b/FluentTerminal.App/Services/StartupTaskService.cs index fd9042a..4494353 100644 --- a/FluentTerminal.App/Services/StartupTaskService.cs +++ b/FluentTerminal.App/Services/StartupTaskService.cs @@ -7,41 +7,38 @@ namespace FluentTerminal.App.Services { public class StartupTaskService : IStartupTaskService { - public const string StartupTaskname = "FluentTerminalStartupTask"; + private const string StartupTaskName = "FluentTerminalStartupTask"; - public async Task GetStatus() + public Task GetStatus() { - var startupTask = await StartupTask.GetAsync(StartupTaskname); - return ConvertState(startupTask.State); + return StartupTask.GetAsync(StartupTaskName).AsTask().ContinueWith(t => ToStartupTaskStatus(t.Result.State), + TaskContinuationOptions.OnlyOnRanToCompletion); } public async Task EnableStartupTask() { - var startupTask = await StartupTask.GetAsync(StartupTaskname); + var startupTask = await StartupTask.GetAsync(StartupTaskName); var newState = await startupTask.RequestEnableAsync(); - return ConvertState(newState); + return ToStartupTaskStatus(newState); } - public async Task DisableStartupTask() + public Task DisableStartupTask() { - var startupTask = await StartupTask.GetAsync(StartupTaskname); - startupTask.Disable(); + return StartupTask.GetAsync(StartupTaskName).AsTask().ContinueWith(t => t.Result.Disable(), + TaskContinuationOptions.OnlyOnRanToCompletion); } - private StartupTaskStatus ConvertState(StartupTaskState state) + private StartupTaskStatus ToStartupTaskStatus(StartupTaskState state) { - switch (state) + return state switch { - case StartupTaskState.Disabled: - return StartupTaskStatus.Disabled; - case StartupTaskState.DisabledByUser: - return StartupTaskStatus.DisabledByUser; - case StartupTaskState.Enabled: - return StartupTaskStatus.Enabled; - case StartupTaskState.DisabledByPolicy: - return StartupTaskStatus.DisabledByPolicy; - } - throw new NotImplementedException(); + StartupTaskState.Disabled => StartupTaskStatus.Disabled, + StartupTaskState.DisabledByUser => StartupTaskStatus.DisabledByUser, + StartupTaskState.Enabled => StartupTaskStatus.Enabled, + StartupTaskState.DisabledByPolicy => StartupTaskStatus.DisabledByPolicy, + StartupTaskState.EnabledByPolicy => StartupTaskStatus.EnabledByPolicy, + _ => throw new ArgumentOutOfRangeException(nameof(state), state, null) + }; } } } diff --git a/FluentTerminal.App/Utilities/StorageFileExtensions.cs b/FluentTerminal.App/Utilities/StorageFileExtensions.cs deleted file mode 100644 index 6e12ae7..0000000 --- a/FluentTerminal.App/Utilities/StorageFileExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.Storage; -using Windows.Storage.Streams; - -namespace FluentTerminal.App.Utilities -{ - public static class StorageFileExtensions - { - public static async Task ImageToBase64String(this StorageFile storageFile) - { - var stream = await storageFile.OpenAsync(FileAccessMode.Read); - - var reader = new DataReader(stream.GetInputStreamAt(0)); - await reader.LoadAsync((uint)stream.Size); - byte[] byteArray = new byte[stream.Size]; - reader.ReadBytes(byteArray); - - return Convert.ToBase64String(byteArray); - } - } -} diff --git a/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs b/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs index 67bd9d1..624efaa 100644 --- a/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs +++ b/FluentTerminal.App/ViewModels/CommandProfileProviderViewModel.cs @@ -106,7 +106,7 @@ namespace FluentTerminal.App.ViewModels protected override async Task CopyToProfileAsync(ShellProfile profile) { - await base.CopyToProfileAsync(profile); + await base.CopyToProfileAsync(profile).ConfigureAwait(false); var command = _command?.Trim(); @@ -167,7 +167,8 @@ namespace FluentTerminal.App.ViewModels } else { - profile.Location = await _trayProcessCommunicationService.GetCommandPathAsync(cmd); + profile.Location = + await _trayProcessCommunicationService.GetCommandPathAsync(cmd).ConfigureAwait(false); } profile.Arguments = match.Groups["args"].Success ? match.Groups["args"].Value.Trim() : null; @@ -177,7 +178,7 @@ namespace FluentTerminal.App.ViewModels public override async Task ValidateAsync() { - var error = await base.ValidateAsync(); + var error = await base.ValidateAsync().ConfigureAwait(false); if (!string.IsNullOrEmpty(error)) { @@ -217,7 +218,7 @@ namespace FluentTerminal.App.ViewModels if (command.Contains(Path.PathSeparator)) { - if (await _trayProcessCommunicationService.CheckFileExistsAsync(command)) + if (await _trayProcessCommunicationService.CheckFileExistsAsync(command).ConfigureAwait(false)) { return null; } @@ -227,7 +228,8 @@ namespace FluentTerminal.App.ViewModels try { - await _trayProcessCommunicationService.GetCommandPathAsync(match.Groups["cmd"].Value); + await _trayProcessCommunicationService.GetCommandPathAsync(match.Groups["cmd"].Value) + .ConfigureAwait(false); } catch (Exception e) { @@ -296,7 +298,7 @@ namespace FluentTerminal.App.ViewModels try { - await SetFilterAsync(filter, containsPrevious); + await SetFilterAsync(filter, containsPrevious).ConfigureAwait(false); } catch { @@ -421,7 +423,7 @@ namespace FluentTerminal.App.ViewModels public override async Task> GetUrlAsync() { - var error = await ValidateAsync(); + var error = await ValidateAsync().ConfigureAwait(false); if (!string.IsNullOrEmpty(error)) { diff --git a/FluentTerminal.App/Views/MainPage.xaml.cs b/FluentTerminal.App/Views/MainPage.xaml.cs index c7fe69f..b54dbee 100644 --- a/FluentTerminal.App/Views/MainPage.xaml.cs +++ b/FluentTerminal.App/Views/MainPage.xaml.cs @@ -152,7 +152,7 @@ namespace FluentTerminal.App.Views private async void TabView_Drop(object sender, NewTabRequestedEventArgs e) { - if (e.DragEventArgs.DataView.Properties.TryGetValue(Constants.TerminalViewModelStateId, out object stateObj) && stateObj is string terminalViewModelState) + if (e.DragEventArgs.DataView.Properties.TryGetValue(Constants.TerminalViewModelStateId, out var stateObj) && stateObj is string terminalViewModelState) { await ViewModel.AddTabAsync(terminalViewModelState, e.Position); } @@ -199,7 +199,7 @@ namespace FluentTerminal.App.Views set { SetValue(DraggingHappensProperty, value); } } - static private event EventHandler DraggingHappensChanged; + private static event EventHandler DraggingHappensChanged; private void TabDropArea_DragEnter(object sender, DragEventArgs e) { diff --git a/FluentTerminal.App/Views/TerminalView.xaml.cs b/FluentTerminal.App/Views/TerminalView.xaml.cs index b9979ea..5164e62 100644 --- a/FluentTerminal.App/Views/TerminalView.xaml.cs +++ b/FluentTerminal.App/Views/TerminalView.xaml.cs @@ -104,7 +104,7 @@ namespace FluentTerminal.App.Views private async void OnThemeChanged(object sender, TerminalTheme e) { - await _terminalView.ChangeTheme(e).ConfigureAwait(true); + await _terminalView.ChangeTheme(e); SetGridBackgroundTheme(e); } diff --git a/FluentTerminal.App/Views/XtermTerminalView.xaml.cs b/FluentTerminal.App/Views/XtermTerminalView.xaml.cs index 7106b3b..3f78403 100644 --- a/FluentTerminal.App/Views/XtermTerminalView.xaml.cs +++ b/FluentTerminal.App/Views/XtermTerminalView.xaml.cs @@ -108,11 +108,11 @@ namespace FluentTerminal.App.Views if (size == null) { - await Task.Delay(delay); + await Task.Delay(delay).ConfigureAwait(false); } else { - await ViewModel.Terminal.SetSize(_requestedSize); + await ViewModel.Terminal.SetSize(_requestedSize).ConfigureAwait(false); } } } @@ -252,10 +252,10 @@ namespace FluentTerminal.App.Views var theme = ViewModel.TerminalTheme; // Waiting for WebView.NavigationCompleted event to happen - await _tcsNavigationCompleted.Task.ConfigureAwait(true); + await _tcsNavigationCompleted.Task.ConfigureAwait(false); - var size = await CreateXtermView(options, theme.Colors, - FlattenKeyBindings(keyBindings, profiles, sshprofiles)).ConfigureAwait(true); + var size = await CreateXtermViewAsync(options, theme.Colors, + FlattenKeyBindings(keyBindings, profiles, sshprofiles)).ConfigureAwait(false); // Waiting for IxtermEventListener.OnInitialized() call to happen await _tcsConnected.Task; @@ -279,10 +279,13 @@ namespace FluentTerminal.App.Views } } - var response = await ViewModel.Terminal.StartShellProcess(ViewModel.ShellProfile, size, sessionType, ViewModel.XtermBufferState).ConfigureAwait(true); + var response = await ViewModel.Terminal.StartShellProcess(ViewModel.ShellProfile, size, sessionType, ViewModel.XtermBufferState).ConfigureAwait(false); if (!response.Success) { - await ViewModel.DialogService.ShowMessageDialogAsnyc("Error", response.Error, DialogButton.OK).ConfigureAwait(true); + await Dispatcher.ExecuteAsync(async () => + await ViewModel.DialogService.ShowMessageDialogAsync("Error", response.Error, DialogButton.OK)) + .ConfigureAwait(false); + ViewModel.Terminal.ReportLauchFailed(); return; } @@ -305,7 +308,7 @@ namespace FluentTerminal.App.Views tracker.SetSuccessfulSessionStart(); } - _webView.Focus(FocusState.Programmatic); + await Dispatcher.ExecuteAsync(() => _webView.Focus(FocusState.Programmatic)).ConfigureAwait(false); } public void DisposalPrepare() @@ -446,13 +449,14 @@ namespace FluentTerminal.App.Views ((IxtermEventListener)this).OnKeyboardCommand(nameof(Command.Copy)); } - private async Task CreateXtermView(TerminalOptions options, TerminalColors theme, IEnumerable keyBindings) + private Task CreateXtermViewAsync(TerminalOptions options, TerminalColors theme, IEnumerable keyBindings) { var serializedOptions = JsonConvert.SerializeObject(options); var serializedTheme = JsonConvert.SerializeObject(theme); var serializedKeyBindings = JsonConvert.SerializeObject(keyBindings); - var size = await ExecuteScriptAsync($"createTerminal('{serializedOptions}', '{serializedTheme}', '{serializedKeyBindings}')").ConfigureAwait(true); - return JsonConvert.DeserializeObject(size); + return ExecuteScriptAsync( + $"createTerminal('{serializedOptions}', '{serializedTheme}', '{serializedKeyBindings}')") + .ContinueWith(t => JsonConvert.DeserializeObject(t.Result)); } private async Task ExecuteScriptAsync(string script) @@ -464,8 +468,8 @@ namespace FluentTerminal.App.Views try { - var scriptTask = - await Dispatcher.ExecuteAsync(() => _webView.InvokeScriptAsync("eval", new[] {script})); + var scriptTask = await Dispatcher.ExecuteAsync(() => _webView.InvokeScriptAsync("eval", new[] {script})) + .ConfigureAwait(false); return await scriptTask; } diff --git a/FluentTerminal.Models/Enums/StartupTaskStatus.cs b/FluentTerminal.Models/Enums/StartupTaskStatus.cs index d5c780c..83d6710 100644 --- a/FluentTerminal.Models/Enums/StartupTaskStatus.cs +++ b/FluentTerminal.Models/Enums/StartupTaskStatus.cs @@ -1,14 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace FluentTerminal.Models.Enums +namespace FluentTerminal.Models.Enums { + // Mirrors Windows.ApplicationModel.StartupTaskState public enum StartupTaskStatus { - Enabled, - Disabled, - DisabledByUser, - DisabledByPolicy + Disabled = 0, + DisabledByUser = 1, + Enabled = 2, + DisabledByPolicy = 3, + EnabledByPolicy = 4 } }