Browse Source

Merge pull request #143 from ionite34/fix-dispatchers

pull/18/head
Ionite 1 year ago committed by GitHub
parent
commit
f95305e385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      StabilityMatrix/DataDirectoryMigrationDialog.xaml.cs
  2. 5
      StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs
  3. 2
      StabilityMatrix/ViewModels/LaunchViewModel.cs
  4. 2
      StabilityMatrix/ViewModels/MainWindowViewModel.cs

16
StabilityMatrix/DataDirectoryMigrationDialog.xaml.cs

@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using AsyncAwaitBestPractices;
using StabilityMatrix.ViewModels;
using Wpf.Ui.Contracts;
using Wpf.Ui.Controls.ContentDialogControl;
@ -27,12 +29,20 @@ public partial class DataDirectoryMigrationDialog : ContentDialog
private void DataDirectoryMigrationDialog_OnLoaded(object sender, RoutedEventArgs e)
{
viewModel.OnLoaded();
viewModel.OnLoaded().SafeFireAndForget();
}
private void NoThanks_OnClick(object sender, RoutedEventArgs e)
private async void NoThanks_OnClick(object sender, RoutedEventArgs e)
{
viewModel.CleanupOldInstall();
try
{
await Task.Run(viewModel.CleanupOldInstall);
}
catch (Exception)
{
// ignored
}
Hide(ContentDialogResult.Primary);
}

5
StabilityMatrix/ViewModels/DataDirectoryMigrationViewModel.cs

@ -136,7 +136,7 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
// Since we are going to recreate venvs, need python to be installed
if (!prerequisiteHelper.IsPythonInstalled)
{
MigrateProgressText = "Preparing Environment";
MigrateProgressText = "Preparing Environment...";
await prerequisiteHelper.InstallPythonIfNecessary();
}
@ -154,6 +154,7 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
var oldLibraryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix");
var oldPackages = settingsManager.GetOldInstalledPackages().ToArray();
MigrateProgressText = "Migrating Packages...";
foreach (var package in oldPackages)
{
settingsManager.RemoveInstalledPackage(package);
@ -192,7 +193,7 @@ public partial class DataDirectoryMigrationViewModel : ObservableObject
await Task.Run(() => Utilities.CopyDirectory(oldModelsDir, newModelsDir, true));
MigrateProgressText = "Cleaning up...";
CleanupOldInstall();
await Task.Run(CleanupOldInstall);
}
IsMigrating = false;

2
StabilityMatrix/ViewModels/LaunchViewModel.cs

@ -368,7 +368,7 @@ public partial class LaunchViewModel : ObservableObject
basePackage.Exited -= OnExit;
basePackage.StartupComplete -= RunningPackageOnStartupComplete;
Dispatcher.CurrentDispatcher.Invoke(() =>
Application.Current.Dispatcher.Invoke(() =>
{
ConsoleHistory?.Add($"Venv process exited with code {exitCode}");
SetProcessRunning(false);

2
StabilityMatrix/ViewModels/MainWindowViewModel.cs

@ -218,7 +218,7 @@ public partial class MainWindowViewModel : ObservableObject
Task.Run(async () =>
{
await Task.Delay(5000);
Dispatcher.CurrentDispatcher.Invoke(() =>
Application.Current.Dispatcher.Invoke(() =>
{
ProgressState = TaskbarItemProgressState.None;
ProgressValue = 0;

Loading…
Cancel
Save