forked from LykosAI/StabilityMatrix
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ionite34/StabilityMatrix
- Loading branch information
Showing
18 changed files
with
292 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
StabilityMatrix.Avalonia/FallbackRamCachedWebImageLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using AsyncAwaitBestPractices; | ||
using AsyncImageLoader.Loaders; | ||
using Avalonia.Media.Imaging; | ||
|
||
namespace StabilityMatrix.Avalonia; | ||
|
||
public readonly record struct ImageLoadFailedEventArgs(string Url, Exception Exception); | ||
|
||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] | ||
public class FallbackRamCachedWebImageLoader : RamCachedWebImageLoader | ||
{ | ||
private readonly WeakEventManager<ImageLoadFailedEventArgs> loadFailedEventManager = new(); | ||
|
||
public event EventHandler<ImageLoadFailedEventArgs> LoadFailed | ||
{ | ||
add => loadFailedEventManager.AddEventHandler(value); | ||
remove => loadFailedEventManager.RemoveEventHandler(value); | ||
} | ||
|
||
protected void OnLoadFailed(string url, Exception exception) => loadFailedEventManager.RaiseEvent( | ||
this, new ImageLoadFailedEventArgs(url, exception), nameof(LoadFailed)); | ||
|
||
/// <summary> | ||
/// Attempts to load bitmap | ||
/// </summary> | ||
/// <param name="url">Target url</param> | ||
/// <returns>Bitmap</returns> | ||
protected override async Task<Bitmap?> LoadAsync(string url) | ||
{ | ||
// Try to load from local file first | ||
if (File.Exists(url)) | ||
{ | ||
try | ||
{ | ||
return new Bitmap(url); | ||
} | ||
catch (Exception e) | ||
{ | ||
OnLoadFailed(url, e); | ||
return null; | ||
} | ||
} | ||
|
||
var internalOrCachedBitmap = | ||
await LoadFromInternalAsync(url).ConfigureAwait(false) | ||
?? await LoadFromGlobalCache(url).ConfigureAwait(false); | ||
|
||
if (internalOrCachedBitmap != null) return internalOrCachedBitmap; | ||
|
||
try | ||
{ | ||
var externalBytes = await LoadDataFromExternalAsync(url).ConfigureAwait(false); | ||
if (externalBytes == null) return null; | ||
|
||
using var memoryStream = new MemoryStream(externalBytes); | ||
var bitmap = new Bitmap(memoryStream); | ||
await SaveToGlobalCache(url, externalBytes).ConfigureAwait(false); | ||
return bitmap; | ||
} | ||
catch (Exception) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace StabilityMatrix.Avalonia.Models; | ||
|
||
/// <summary> | ||
/// Command line arguments passed to the application. | ||
/// </summary> | ||
public class AppArgs | ||
{ | ||
/// <summary> | ||
/// Whether to use the exception dialog while debugger is attached. | ||
/// When no debugger is attached, the exception dialog is always used. | ||
/// </summary> | ||
public bool DebugExceptionDialog { get; set; } | ||
|
||
/// <summary> | ||
/// Whether to use Sentry when a debugger is attached. | ||
/// </summary> | ||
public bool DebugSentry { get; set; } | ||
|
||
/// <summary> | ||
/// Whether to disable Sentry. | ||
/// </summary> | ||
public bool NoSentry { get; set; } | ||
|
||
/// <summary> | ||
/// Whether to disable window chrome effects | ||
/// </summary> | ||
public bool NoWindowChromeEffects { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.