|
|
@ -1,3 +1,7 @@ |
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.Diagnostics.LogViewer; |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.Diagnostics.LogViewer.Extensions; |
|
|
|
|
|
|
|
#endif |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
@ -32,10 +36,7 @@ using Polly.Timeout; |
|
|
|
using Refit; |
|
|
|
using Refit; |
|
|
|
using Sentry; |
|
|
|
using Sentry; |
|
|
|
using StabilityMatrix.Avalonia.Controls; |
|
|
|
using StabilityMatrix.Avalonia.Controls; |
|
|
|
using StabilityMatrix.Avalonia.Controls.CodeCompletion; |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.DesignData; |
|
|
|
using StabilityMatrix.Avalonia.DesignData; |
|
|
|
using StabilityMatrix.Avalonia.Diagnostics.LogViewer; |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.Diagnostics.LogViewer.Extensions; |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.Helpers; |
|
|
|
using StabilityMatrix.Avalonia.Helpers; |
|
|
|
using StabilityMatrix.Avalonia.Languages; |
|
|
|
using StabilityMatrix.Avalonia.Languages; |
|
|
|
using StabilityMatrix.Avalonia.Models; |
|
|
|
using StabilityMatrix.Avalonia.Models; |
|
|
@ -46,8 +47,8 @@ using StabilityMatrix.Avalonia.ViewModels.Base; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.CheckpointBrowser; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.CheckpointBrowser; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.CheckpointManager; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.CheckpointManager; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Dialogs; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Dialogs; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.PackageManager; |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Inference; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Inference; |
|
|
|
|
|
|
|
using StabilityMatrix.Avalonia.ViewModels.PackageManager; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Settings; |
|
|
|
using StabilityMatrix.Avalonia.ViewModels.Settings; |
|
|
|
using StabilityMatrix.Avalonia.Views; |
|
|
|
using StabilityMatrix.Avalonia.Views; |
|
|
|
using StabilityMatrix.Avalonia.Views.Dialogs; |
|
|
|
using StabilityMatrix.Avalonia.Views.Dialogs; |
|
|
@ -73,11 +74,18 @@ namespace StabilityMatrix.Avalonia; |
|
|
|
|
|
|
|
|
|
|
|
public sealed class App : Application |
|
|
|
public sealed class App : Application |
|
|
|
{ |
|
|
|
{ |
|
|
|
[NotNull] public static IServiceProvider? Services { get; private set; } |
|
|
|
[NotNull] |
|
|
|
[NotNull] public static Visual? VisualRoot { get; private set; } |
|
|
|
public static IServiceProvider? Services { get; private set; } |
|
|
|
[NotNull] public static IStorageProvider? StorageProvider { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
[NotNull] |
|
|
|
|
|
|
|
public static Visual? VisualRoot { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NotNull] |
|
|
|
|
|
|
|
public static IStorageProvider? StorageProvider { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Global |
|
|
|
// ReSharper disable once MemberCanBePrivate.Global |
|
|
|
[NotNull] public static IConfiguration? Config { get; private set; } |
|
|
|
[NotNull] |
|
|
|
|
|
|
|
public static IConfiguration? Config { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable once MemberCanBePrivate.Global |
|
|
|
// ReSharper disable once MemberCanBePrivate.Global |
|
|
|
public IClassicDesktopStyleApplicationLifetime? DesktopLifetime => |
|
|
|
public IClassicDesktopStyleApplicationLifetime? DesktopLifetime => |
|
|
@ -123,8 +131,9 @@ public sealed class App : Application |
|
|
|
setupWindow.ShowActivated = true; |
|
|
|
setupWindow.ShowActivated = true; |
|
|
|
setupWindow.ShowAsyncCts = new CancellationTokenSource(); |
|
|
|
setupWindow.ShowAsyncCts = new CancellationTokenSource(); |
|
|
|
|
|
|
|
|
|
|
|
setupWindow.ExtendClientAreaChromeHints = Program.Args.NoWindowChromeEffects ? |
|
|
|
setupWindow.ExtendClientAreaChromeHints = Program.Args.NoWindowChromeEffects |
|
|
|
ExtendClientAreaChromeHints.NoChrome : ExtendClientAreaChromeHints.PreferSystemChrome; |
|
|
|
? ExtendClientAreaChromeHints.NoChrome |
|
|
|
|
|
|
|
: ExtendClientAreaChromeHints.PreferSystemChrome; |
|
|
|
|
|
|
|
|
|
|
|
DesktopLifetime.MainWindow = setupWindow; |
|
|
|
DesktopLifetime.MainWindow = setupWindow; |
|
|
|
|
|
|
|
|
|
|
@ -151,15 +160,17 @@ public sealed class App : Application |
|
|
|
|
|
|
|
|
|
|
|
private void ShowMainWindow() |
|
|
|
private void ShowMainWindow() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (DesktopLifetime is null) return; |
|
|
|
if (DesktopLifetime is null) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
var mainViewModel = Services.GetRequiredService<MainWindowViewModel>(); |
|
|
|
var mainViewModel = Services.GetRequiredService<MainWindowViewModel>(); |
|
|
|
|
|
|
|
|
|
|
|
var mainWindow = Services.GetRequiredService<MainWindow>(); |
|
|
|
var mainWindow = Services.GetRequiredService<MainWindow>(); |
|
|
|
mainWindow.DataContext = mainViewModel; |
|
|
|
mainWindow.DataContext = mainViewModel; |
|
|
|
|
|
|
|
|
|
|
|
mainWindow.ExtendClientAreaChromeHints = Program.Args.NoWindowChromeEffects ? |
|
|
|
mainWindow.ExtendClientAreaChromeHints = Program.Args.NoWindowChromeEffects |
|
|
|
ExtendClientAreaChromeHints.NoChrome : ExtendClientAreaChromeHints.PreferSystemChrome; |
|
|
|
? ExtendClientAreaChromeHints.NoChrome |
|
|
|
|
|
|
|
: ExtendClientAreaChromeHints.PreferSystemChrome; |
|
|
|
|
|
|
|
|
|
|
|
var settingsManager = Services.GetRequiredService<ISettingsManager>(); |
|
|
|
var settingsManager = Services.GetRequiredService<ISettingsManager>(); |
|
|
|
var windowSettings = settingsManager.Settings.WindowSettings; |
|
|
|
var windowSettings = settingsManager.Settings.WindowSettings; |
|
|
@ -176,16 +187,22 @@ public sealed class App : Application |
|
|
|
|
|
|
|
|
|
|
|
mainWindow.Closing += (_, _) => |
|
|
|
mainWindow.Closing += (_, _) => |
|
|
|
{ |
|
|
|
{ |
|
|
|
var validWindowPosition = |
|
|
|
var validWindowPosition = mainWindow.Screens.All.Any( |
|
|
|
mainWindow.Screens.All.Any(screen => screen.Bounds.Contains(mainWindow.Position)); |
|
|
|
screen => screen.Bounds.Contains(mainWindow.Position) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
settingsManager.Transaction(s => |
|
|
|
settingsManager.Transaction( |
|
|
|
{ |
|
|
|
s => |
|
|
|
s.WindowSettings = new WindowSettings( |
|
|
|
{ |
|
|
|
mainWindow.Width, mainWindow.Height, |
|
|
|
s.WindowSettings = new WindowSettings( |
|
|
|
validWindowPosition ? mainWindow.Position.X : 0, |
|
|
|
mainWindow.Width, |
|
|
|
validWindowPosition ? mainWindow.Position.Y : 0); |
|
|
|
mainWindow.Height, |
|
|
|
}, ignoreMissingLibraryDir: true); |
|
|
|
validWindowPosition ? mainWindow.Position.X : 0, |
|
|
|
|
|
|
|
validWindowPosition ? mainWindow.Position.Y : 0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
ignoreMissingLibraryDir: true |
|
|
|
|
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
mainWindow.Closed += (_, _) => Shutdown(); |
|
|
|
mainWindow.Closed += (_, _) => Shutdown(); |
|
|
|
|
|
|
|
|
|
|
@ -213,7 +230,8 @@ public sealed class App : Application |
|
|
|
|
|
|
|
|
|
|
|
internal static void ConfigurePageViewModels(IServiceCollection services) |
|
|
|
internal static void ConfigurePageViewModels(IServiceCollection services) |
|
|
|
{ |
|
|
|
{ |
|
|
|
services.AddSingleton<PackageManagerViewModel>() |
|
|
|
services |
|
|
|
|
|
|
|
.AddSingleton<PackageManagerViewModel>() |
|
|
|
.AddSingleton<SettingsViewModel>() |
|
|
|
.AddSingleton<SettingsViewModel>() |
|
|
|
.AddSingleton<InferenceSettingsViewModel>() |
|
|
|
.AddSingleton<InferenceSettingsViewModel>() |
|
|
|
.AddSingleton<CheckpointBrowserViewModel>() |
|
|
|
.AddSingleton<CheckpointBrowserViewModel>() |
|
|
@ -223,29 +241,29 @@ public sealed class App : Application |
|
|
|
.AddSingleton<ProgressManagerViewModel>() |
|
|
|
.AddSingleton<ProgressManagerViewModel>() |
|
|
|
.AddSingleton<InferenceViewModel>(); |
|
|
|
.AddSingleton<InferenceViewModel>(); |
|
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<MainWindowViewModel>(provider => |
|
|
|
services.AddSingleton<MainWindowViewModel>( |
|
|
|
new MainWindowViewModel(provider.GetRequiredService<ISettingsManager>(), |
|
|
|
provider => |
|
|
|
provider.GetRequiredService<IDiscordRichPresenceService>(), |
|
|
|
new MainWindowViewModel( |
|
|
|
provider.GetRequiredService<ServiceManager<ViewModelBase>>(), |
|
|
|
provider.GetRequiredService<ISettingsManager>(), |
|
|
|
provider.GetRequiredService<ITrackedDownloadService>()) |
|
|
|
provider.GetRequiredService<IDiscordRichPresenceService>(), |
|
|
|
{ |
|
|
|
provider.GetRequiredService<ServiceManager<ViewModelBase>>(), |
|
|
|
Pages = |
|
|
|
provider.GetRequiredService<ITrackedDownloadService>() |
|
|
|
{ |
|
|
|
) |
|
|
|
provider.GetRequiredService<LaunchPageViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<InferenceViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<PackageManagerViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<CheckpointsPageViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<CheckpointBrowserViewModel>(), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
FooterPages = |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
provider.GetRequiredService<SettingsViewModel>() |
|
|
|
Pages = |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
provider.GetRequiredService<LaunchPageViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<InferenceViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<PackageManagerViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<CheckpointsPageViewModel>(), |
|
|
|
|
|
|
|
provider.GetRequiredService<CheckpointBrowserViewModel>(), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
FooterPages = { provider.GetRequiredService<SettingsViewModel>() } |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Register disposable view models for shutdown cleanup |
|
|
|
// Register disposable view models for shutdown cleanup |
|
|
|
services.AddSingleton<IDisposable>(p |
|
|
|
services.AddSingleton<IDisposable>(p => p.GetRequiredService<LaunchPageViewModel>()); |
|
|
|
=> p.GetRequiredService<LaunchPageViewModel>()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static void ConfigureDialogViewModels(IServiceCollection services) |
|
|
|
internal static void ConfigureDialogViewModels(IServiceCollection services) |
|
|
@ -290,36 +308,37 @@ public sealed class App : Application |
|
|
|
services.AddTransient<BatchSizeCardViewModel>(); |
|
|
|
services.AddTransient<BatchSizeCardViewModel>(); |
|
|
|
|
|
|
|
|
|
|
|
// Dialog factory |
|
|
|
// Dialog factory |
|
|
|
services.AddSingleton<ServiceManager<ViewModelBase>>(provider => |
|
|
|
services.AddSingleton<ServiceManager<ViewModelBase>>( |
|
|
|
new ServiceManager<ViewModelBase>() |
|
|
|
provider => |
|
|
|
.Register(provider.GetRequiredService<InstallerViewModel>) |
|
|
|
new ServiceManager<ViewModelBase>() |
|
|
|
.Register(provider.GetRequiredService<OneClickInstallViewModel>) |
|
|
|
.Register(provider.GetRequiredService<InstallerViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SelectModelVersionViewModel>) |
|
|
|
.Register(provider.GetRequiredService<OneClickInstallViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SelectDataDirectoryViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SelectModelVersionViewModel>) |
|
|
|
.Register(provider.GetRequiredService<LaunchOptionsViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SelectDataDirectoryViewModel>) |
|
|
|
.Register(provider.GetRequiredService<UpdateViewModel>) |
|
|
|
.Register(provider.GetRequiredService<LaunchOptionsViewModel>) |
|
|
|
.Register(provider.GetRequiredService<CheckpointBrowserCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<UpdateViewModel>) |
|
|
|
.Register(provider.GetRequiredService<CheckpointFolder>) |
|
|
|
.Register(provider.GetRequiredService<CheckpointBrowserCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<CheckpointFile>) |
|
|
|
.Register(provider.GetRequiredService<CheckpointFolder>) |
|
|
|
.Register(provider.GetRequiredService<PackageCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<CheckpointFile>) |
|
|
|
.Register(provider.GetRequiredService<RefreshBadgeViewModel>) |
|
|
|
.Register(provider.GetRequiredService<PackageCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ExceptionViewModel>) |
|
|
|
.Register(provider.GetRequiredService<RefreshBadgeViewModel>) |
|
|
|
.Register(provider.GetRequiredService<EnvVarsViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ExceptionViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ProgressManagerViewModel>) |
|
|
|
.Register(provider.GetRequiredService<EnvVarsViewModel>) |
|
|
|
.Register(provider.GetRequiredService<InferenceTextToImageViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ProgressManagerViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SeedCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<InferenceTextToImageViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SamplerCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SeedCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ImageGalleryCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<SamplerCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<PromptCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ImageGalleryCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<StackCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<PromptCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<StackExpanderViewModel>) |
|
|
|
.Register(provider.GetRequiredService<StackCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<UpscalerCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<StackExpanderViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ModelCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<UpscalerCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<BatchSizeCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ModelCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ImageViewerViewModel>) |
|
|
|
.Register(provider.GetRequiredService<BatchSizeCardViewModel>) |
|
|
|
.Register(provider.GetRequiredService<FirstLaunchSetupViewModel>) |
|
|
|
.Register(provider.GetRequiredService<ImageViewerViewModel>) |
|
|
|
.Register(provider.GetRequiredService<PackageImportViewModel>) |
|
|
|
.Register(provider.GetRequiredService<FirstLaunchSetupViewModel>) |
|
|
|
); |
|
|
|
.Register(provider.GetRequiredService<PackageImportViewModel>) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static void ConfigureViews(IServiceCollection services) |
|
|
|
internal static void ConfigureViews(IServiceCollection services) |
|
|
@ -404,13 +423,15 @@ public sealed class App : Application |
|
|
|
services.AddSingleton<IModelIndexService, ModelIndexService>(); |
|
|
|
services.AddSingleton<IModelIndexService, ModelIndexService>(); |
|
|
|
|
|
|
|
|
|
|
|
services.AddSingleton<ITrackedDownloadService, TrackedDownloadService>(); |
|
|
|
services.AddSingleton<ITrackedDownloadService, TrackedDownloadService>(); |
|
|
|
services.AddSingleton<IDisposable>(provider => |
|
|
|
services.AddSingleton<IDisposable>( |
|
|
|
(IDisposable) provider.GetRequiredService<ITrackedDownloadService>()); |
|
|
|
provider => (IDisposable)provider.GetRequiredService<ITrackedDownloadService>() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Rich presence |
|
|
|
// Rich presence |
|
|
|
services.AddSingleton<IDiscordRichPresenceService, DiscordRichPresenceService>(); |
|
|
|
services.AddSingleton<IDiscordRichPresenceService, DiscordRichPresenceService>(); |
|
|
|
services.AddSingleton<IDisposable>(provider => |
|
|
|
services.AddSingleton<IDisposable>( |
|
|
|
provider.GetRequiredService<IDiscordRichPresenceService>()); |
|
|
|
provider => provider.GetRequiredService<IDiscordRichPresenceService>() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
Config = new ConfigurationBuilder() |
|
|
|
Config = new ConfigurationBuilder() |
|
|
|
.SetBasePath(Directory.GetCurrentDirectory()) |
|
|
|
.SetBasePath(Directory.GetCurrentDirectory()) |
|
|
@ -460,13 +481,13 @@ public sealed class App : Application |
|
|
|
jsonSerializerOptions.Converters.Add(new ObjectToInferredTypesConverter()); |
|
|
|
jsonSerializerOptions.Converters.Add(new ObjectToInferredTypesConverter()); |
|
|
|
jsonSerializerOptions.Converters.Add(new DefaultUnknownEnumConverter<CivitFileType>()); |
|
|
|
jsonSerializerOptions.Converters.Add(new DefaultUnknownEnumConverter<CivitFileType>()); |
|
|
|
jsonSerializerOptions.Converters.Add( |
|
|
|
jsonSerializerOptions.Converters.Add( |
|
|
|
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); |
|
|
|
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) |
|
|
|
|
|
|
|
); |
|
|
|
jsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; |
|
|
|
jsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; |
|
|
|
|
|
|
|
|
|
|
|
var defaultRefitSettings = new RefitSettings |
|
|
|
var defaultRefitSettings = new RefitSettings |
|
|
|
{ |
|
|
|
{ |
|
|
|
ContentSerializer = |
|
|
|
ContentSerializer = new SystemTextJsonContentSerializer(jsonSerializerOptions) |
|
|
|
new SystemTextJsonContentSerializer(jsonSerializerOptions) |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Refit settings for IApiFactory |
|
|
|
// Refit settings for IApiFactory |
|
|
@ -475,8 +496,7 @@ public sealed class App : Application |
|
|
|
defaultSystemTextJsonSettings.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; |
|
|
|
defaultSystemTextJsonSettings.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; |
|
|
|
var apiFactoryRefitSettings = new RefitSettings |
|
|
|
var apiFactoryRefitSettings = new RefitSettings |
|
|
|
{ |
|
|
|
{ |
|
|
|
ContentSerializer = |
|
|
|
ContentSerializer = new SystemTextJsonContentSerializer(defaultSystemTextJsonSettings), |
|
|
|
new SystemTextJsonContentSerializer(defaultSystemTextJsonSettings), |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// HTTP Policies |
|
|
|
// HTTP Policies |
|
|
@ -488,9 +508,10 @@ public sealed class App : Application |
|
|
|
HttpStatusCode.ServiceUnavailable, // 503 |
|
|
|
HttpStatusCode.ServiceUnavailable, // 503 |
|
|
|
HttpStatusCode.GatewayTimeout // 504 |
|
|
|
HttpStatusCode.GatewayTimeout // 504 |
|
|
|
}; |
|
|
|
}; |
|
|
|
var delay = Backoff |
|
|
|
var delay = Backoff.DecorrelatedJitterBackoffV2( |
|
|
|
.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromMilliseconds(80), |
|
|
|
medianFirstRetryDelay: TimeSpan.FromMilliseconds(80), |
|
|
|
retryCount: 5); |
|
|
|
retryCount: 5 |
|
|
|
|
|
|
|
); |
|
|
|
var retryPolicy = HttpPolicyExtensions |
|
|
|
var retryPolicy = HttpPolicyExtensions |
|
|
|
.HandleTransientHttpError() |
|
|
|
.HandleTransientHttpError() |
|
|
|
.Or<TimeoutRejectedException>() |
|
|
|
.Or<TimeoutRejectedException>() |
|
|
@ -499,25 +520,29 @@ public sealed class App : Application |
|
|
|
|
|
|
|
|
|
|
|
// Shorter timeout for local requests |
|
|
|
// Shorter timeout for local requests |
|
|
|
var localTimeout = Policy.TimeoutAsync<HttpResponseMessage>(TimeSpan.FromSeconds(3)); |
|
|
|
var localTimeout = Policy.TimeoutAsync<HttpResponseMessage>(TimeSpan.FromSeconds(3)); |
|
|
|
var localDelay = Backoff |
|
|
|
var localDelay = Backoff.DecorrelatedJitterBackoffV2( |
|
|
|
.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromMilliseconds(50), |
|
|
|
medianFirstRetryDelay: TimeSpan.FromMilliseconds(50), |
|
|
|
retryCount: 3); |
|
|
|
retryCount: 3 |
|
|
|
|
|
|
|
); |
|
|
|
var localRetryPolicy = HttpPolicyExtensions |
|
|
|
var localRetryPolicy = HttpPolicyExtensions |
|
|
|
.HandleTransientHttpError() |
|
|
|
.HandleTransientHttpError() |
|
|
|
.Or<TimeoutRejectedException>() |
|
|
|
.Or<TimeoutRejectedException>() |
|
|
|
.OrResult(r => retryStatusCodes.Contains(r.StatusCode)) |
|
|
|
.OrResult(r => retryStatusCodes.Contains(r.StatusCode)) |
|
|
|
.WaitAndRetryAsync(localDelay, onRetryAsync: (_, _) => |
|
|
|
.WaitAndRetryAsync( |
|
|
|
{ |
|
|
|
localDelay, |
|
|
|
Debug.WriteLine("Retrying local request..."); |
|
|
|
onRetryAsync: (_, _) => |
|
|
|
return Task.CompletedTask; |
|
|
|
{ |
|
|
|
}); |
|
|
|
Debug.WriteLine("Retrying local request..."); |
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// named client for update |
|
|
|
// named client for update |
|
|
|
services.AddHttpClient("UpdateClient") |
|
|
|
services.AddHttpClient("UpdateClient").AddPolicyHandler(retryPolicy); |
|
|
|
.AddPolicyHandler(retryPolicy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add Refit clients |
|
|
|
// Add Refit clients |
|
|
|
services.AddRefitClient<ICivitApi>(defaultRefitSettings) |
|
|
|
services |
|
|
|
|
|
|
|
.AddRefitClient<ICivitApi>(defaultRefitSettings) |
|
|
|
.ConfigureHttpClient(c => |
|
|
|
.ConfigureHttpClient(c => |
|
|
|
{ |
|
|
|
{ |
|
|
|
c.BaseAddress = new Uri("https://civitai.com"); |
|
|
|
c.BaseAddress = new Uri("https://civitai.com"); |
|
|
@ -526,18 +551,21 @@ public sealed class App : Application |
|
|
|
.AddPolicyHandler(retryPolicy); |
|
|
|
.AddPolicyHandler(retryPolicy); |
|
|
|
|
|
|
|
|
|
|
|
// Add Refit client managers |
|
|
|
// Add Refit client managers |
|
|
|
services.AddHttpClient("A3Client") |
|
|
|
services |
|
|
|
|
|
|
|
.AddHttpClient("A3Client") |
|
|
|
.AddPolicyHandler(localTimeout.WrapAsync(localRetryPolicy)); |
|
|
|
.AddPolicyHandler(localTimeout.WrapAsync(localRetryPolicy)); |
|
|
|
|
|
|
|
|
|
|
|
/*services.AddHttpClient("IComfyApi") |
|
|
|
/*services.AddHttpClient("IComfyApi") |
|
|
|
.AddPolicyHandler(localTimeout.WrapAsync(localRetryPolicy));*/ |
|
|
|
.AddPolicyHandler(localTimeout.WrapAsync(localRetryPolicy));*/ |
|
|
|
|
|
|
|
|
|
|
|
// Add Refit client factory |
|
|
|
// Add Refit client factory |
|
|
|
services.AddSingleton<IApiFactory, ApiFactory>(provider => |
|
|
|
services.AddSingleton<IApiFactory, ApiFactory>( |
|
|
|
new ApiFactory(provider.GetRequiredService<IHttpClientFactory>()) |
|
|
|
provider => |
|
|
|
{ |
|
|
|
new ApiFactory(provider.GetRequiredService<IHttpClientFactory>()) |
|
|
|
RefitSettings = apiFactoryRefitSettings, |
|
|
|
{ |
|
|
|
}); |
|
|
|
RefitSettings = apiFactoryRefitSettings, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
ConditionalAddLogViewer(services); |
|
|
|
ConditionalAddLogViewer(services); |
|
|
|
|
|
|
|
|
|
|
@ -545,18 +573,21 @@ public sealed class App : Application |
|
|
|
services.AddLogging(builder => |
|
|
|
services.AddLogging(builder => |
|
|
|
{ |
|
|
|
{ |
|
|
|
builder.ClearProviders(); |
|
|
|
builder.ClearProviders(); |
|
|
|
builder.AddFilter("Microsoft.Extensions.Http", LogLevel.Warning) |
|
|
|
builder |
|
|
|
|
|
|
|
.AddFilter("Microsoft.Extensions.Http", LogLevel.Warning) |
|
|
|
.AddFilter("Microsoft.Extensions.Http.DefaultHttpClientFactory", LogLevel.Warning) |
|
|
|
.AddFilter("Microsoft.Extensions.Http.DefaultHttpClientFactory", LogLevel.Warning) |
|
|
|
.AddFilter("Microsoft", LogLevel.Warning) |
|
|
|
.AddFilter("Microsoft", LogLevel.Warning) |
|
|
|
.AddFilter("System", LogLevel.Warning); |
|
|
|
.AddFilter("System", LogLevel.Warning); |
|
|
|
builder.SetMinimumLevel(LogLevel.Debug); |
|
|
|
builder.SetMinimumLevel(LogLevel.Debug); |
|
|
|
#if DEBUG |
|
|
|
#if DEBUG |
|
|
|
builder.AddNLog(ConfigureLogging(), |
|
|
|
builder.AddNLog( |
|
|
|
|
|
|
|
ConfigureLogging(), |
|
|
|
new NLogProviderOptions |
|
|
|
new NLogProviderOptions |
|
|
|
{ |
|
|
|
{ |
|
|
|
IgnoreEmptyEventId = false, |
|
|
|
IgnoreEmptyEventId = false, |
|
|
|
CaptureEventId = EventIdCaptureType.Legacy |
|
|
|
CaptureEventId = EventIdCaptureType.Legacy |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
#else |
|
|
|
#else |
|
|
|
builder.AddNLog(ConfigureLogging()); |
|
|
|
builder.AddNLog(ConfigureLogging()); |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -573,8 +604,8 @@ public sealed class App : Application |
|
|
|
/// <exception cref="NullReferenceException">If Application.Current is null</exception> |
|
|
|
/// <exception cref="NullReferenceException">If Application.Current is null</exception> |
|
|
|
public static void Shutdown(int exitCode = 0) |
|
|
|
public static void Shutdown(int exitCode = 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (Current is null) throw new NullReferenceException( |
|
|
|
if (Current is null) |
|
|
|
"Current Application was null when Shutdown called"); |
|
|
|
throw new NullReferenceException("Current Application was null when Shutdown called"); |
|
|
|
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) |
|
|
|
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) |
|
|
|
{ |
|
|
|
{ |
|
|
|
lifetime.Shutdown(exitCode); |
|
|
|
lifetime.Shutdown(exitCode); |
|
|
@ -588,11 +619,9 @@ public sealed class App : Application |
|
|
|
var settingsManager = Services.GetRequiredService<ISettingsManager>(); |
|
|
|
var settingsManager = Services.GetRequiredService<ISettingsManager>(); |
|
|
|
|
|
|
|
|
|
|
|
// If RemoveFolderLinksOnShutdown is set, delete all package junctions |
|
|
|
// If RemoveFolderLinksOnShutdown is set, delete all package junctions |
|
|
|
if (settingsManager is |
|
|
|
if ( |
|
|
|
{ |
|
|
|
settingsManager is { IsLibraryDirSet: true, Settings.RemoveFolderLinksOnShutdown: true } |
|
|
|
IsLibraryDirSet: true, |
|
|
|
) |
|
|
|
Settings.RemoveFolderLinksOnShutdown: true |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
var sharedFolders = Services.GetRequiredService<ISharedFolders>(); |
|
|
|
var sharedFolders = Services.GetRequiredService<ISharedFolders>(); |
|
|
|
sharedFolders.RemoveLinksForAllPackages(); |
|
|
|
sharedFolders.RemoveLinksForAllPackages(); |
|
|
@ -615,21 +644,30 @@ public sealed class App : Application |
|
|
|
|
|
|
|
|
|
|
|
ConditionalAddLogViewerNLog(setupBuilder); |
|
|
|
ConditionalAddLogViewerNLog(setupBuilder); |
|
|
|
|
|
|
|
|
|
|
|
setupBuilder.LoadConfiguration(builder => { |
|
|
|
setupBuilder.LoadConfiguration(builder => |
|
|
|
var debugTarget = builder.ForTarget("console").WriteTo(new DebuggerTarget |
|
|
|
{ |
|
|
|
{ |
|
|
|
var debugTarget = builder |
|
|
|
Layout = "${message}" |
|
|
|
.ForTarget("console") |
|
|
|
}).WithAsync(); |
|
|
|
.WriteTo(new DebuggerTarget { Layout = "${message}" }) |
|
|
|
|
|
|
|
.WithAsync(); |
|
|
|
var fileTarget = builder.ForTarget("logfile").WriteTo(new FileTarget |
|
|
|
|
|
|
|
{ |
|
|
|
var fileTarget = builder |
|
|
|
Layout = "${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}", |
|
|
|
.ForTarget("logfile") |
|
|
|
ArchiveOldFileOnStartup = true, |
|
|
|
.WriteTo( |
|
|
|
FileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.log", |
|
|
|
new FileTarget |
|
|
|
ArchiveFileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.{#}.log", |
|
|
|
{ |
|
|
|
ArchiveNumbering = ArchiveNumberingMode.Rolling, |
|
|
|
Layout = |
|
|
|
MaxArchiveFiles = 2 |
|
|
|
"${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}", |
|
|
|
}).WithAsync(); |
|
|
|
ArchiveOldFileOnStartup = true, |
|
|
|
|
|
|
|
FileName = |
|
|
|
|
|
|
|
"${specialfolder:folder=ApplicationData}/StabilityMatrix/app.log", |
|
|
|
|
|
|
|
ArchiveFileName = |
|
|
|
|
|
|
|
"${specialfolder:folder=ApplicationData}/StabilityMatrix/app.{#}.log", |
|
|
|
|
|
|
|
ArchiveNumbering = ArchiveNumberingMode.Rolling, |
|
|
|
|
|
|
|
MaxArchiveFiles = 2 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.WithAsync(); |
|
|
|
|
|
|
|
|
|
|
|
// Filter some sources to be warn levels or above only |
|
|
|
// Filter some sources to be warn levels or above only |
|
|
|
builder.ForLogger("System.*").WriteToNil(NLog.LogLevel.Warn); |
|
|
|
builder.ForLogger("System.*").WriteToNil(NLog.LogLevel.Warn); |
|
|
@ -637,16 +675,17 @@ public sealed class App : Application |
|
|
|
builder.ForLogger("Microsoft.Extensions.Http.*").WriteToNil(NLog.LogLevel.Warn); |
|
|
|
builder.ForLogger("Microsoft.Extensions.Http.*").WriteToNil(NLog.LogLevel.Warn); |
|
|
|
|
|
|
|
|
|
|
|
// Disable console trace logging by default |
|
|
|
// Disable console trace logging by default |
|
|
|
builder.ForLogger("StabilityMatrix.Avalonia.ViewModels.ConsoleViewModel").WriteToNil(NLog.LogLevel.Debug); |
|
|
|
builder |
|
|
|
|
|
|
|
.ForLogger("StabilityMatrix.Avalonia.ViewModels.ConsoleViewModel") |
|
|
|
|
|
|
|
.WriteToNil(NLog.LogLevel.Debug); |
|
|
|
|
|
|
|
|
|
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Trace).WriteTo(debugTarget); |
|
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Trace).WriteTo(debugTarget); |
|
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteTo(fileTarget); |
|
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteTo(fileTarget); |
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
#if DEBUG |
|
|
|
var logViewerTarget = builder.ForTarget("DataStoreLogger").WriteTo(new DataStoreLoggerTarget() |
|
|
|
var logViewerTarget = builder |
|
|
|
{ |
|
|
|
.ForTarget("DataStoreLogger") |
|
|
|
Layout = "${message}" |
|
|
|
.WriteTo(new DataStoreLoggerTarget() { Layout = "${message}" }); |
|
|
|
}); |
|
|
|
|
|
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Trace).WriteTo(logViewerTarget); |
|
|
|
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Trace).WriteTo(logViewerTarget); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
}); |
|
|
|
}); |
|
|
@ -676,13 +715,19 @@ public sealed class App : Application |
|
|
|
[Conditional("DEBUG")] |
|
|
|
[Conditional("DEBUG")] |
|
|
|
private static void ConditionalAddLogViewer(IServiceCollection services) |
|
|
|
private static void ConditionalAddLogViewer(IServiceCollection services) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
services.AddLogViewer(); |
|
|
|
services.AddLogViewer(); |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Conditional("DEBUG")] |
|
|
|
[Conditional("DEBUG")] |
|
|
|
private static void ConditionalAddLogViewerNLog(ISetupBuilder setupBuilder) |
|
|
|
private static void ConditionalAddLogViewerNLog(ISetupBuilder setupBuilder) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setupBuilder.SetupExtensions(extensionBuilder => |
|
|
|
#if DEBUG |
|
|
|
extensionBuilder.RegisterTarget<DataStoreLoggerTarget>("DataStoreLogger")); |
|
|
|
setupBuilder.SetupExtensions( |
|
|
|
|
|
|
|
extensionBuilder => |
|
|
|
|
|
|
|
extensionBuilder.RegisterTarget<DataStoreLoggerTarget>("DataStoreLogger") |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|