Skip to content

Commit

Permalink
Merge pull request #342 from jibedoubleve/issue/319
Browse files Browse the repository at this point in the history
(#319) Add icons in toast notifications
  • Loading branch information
jibedoubleve authored Oct 26, 2023
2 parents 7b37507 + 23c96eb commit 0892843
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 20 deletions.
14 changes: 14 additions & 0 deletions src/Lanceur.SharedKernel/Mixins/UriMixin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Lanceur.SharedKernel.Mixins;

public static class UriMixin
{
#region Methods

public static Uri ToUri(this string path, UriKind kind) => new(path, kind);

public static Uri ToUriAbsolute(this string path) => path.ToUri(UriKind.Absolute);

public static Uri ToUriRelative(this string path) => path.ToUri(UriKind.Relative);

#endregion Methods
}
Binary file added src/Lanceur/Assets/IconError.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Lanceur/Assets/IconInfo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Lanceur/Assets/IconWarn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/Lanceur/Lanceur.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Remove="Assets\Modern-InformationCircle.png" />
<Content Include="Assets\IconInfo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="Assets\Modern-WarningCircle.png" />
<Content Include="Assets\IconWarn.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Remove="Assets\IconError.png" />
<Content Include="Assets\IconError.png" />
</ItemGroup>
</Project>
79 changes: 65 additions & 14 deletions src/Lanceur/Ui/ToastNotification.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
using Microsoft.Toolkit.Uwp.Notifications;
using System.IO;
using System.Reflection;
using Lanceur.SharedKernel.Mixins;
using Microsoft.Toolkit.Uwp.Notifications;
using System.Runtime.CompilerServices;
using System.Windows.Shapes;
using FileLocation = System.IO.Path;

namespace Lanceur.Ui
namespace Lanceur.Ui;

public class ToastNotification : INotification
{
public class ToastNotification : INotification
#region Enums

private enum Level
{
#region Methods
Information,
Warning,
Error
};

#endregion Enums

private void Show(string message, [CallerMemberName] string title = null)
#region Methods

private static void Show(Level level, string message, [CallerMemberName] string title = null)
{
var uri = level switch
{
new ToastContentBuilder()
.AddText(title)
.AddText(message)
.Show();
Level.Information => Icon.Info,
Level.Warning => Icon.Warn,
Level.Error => Icon.Error,
_ => Icon.None
};
new ToastContentBuilder()
.AddText(title)
.AddText(message)
.AddAppLogoOverride(uri.ToUriRelative(), ToastGenericAppLogoCrop.Circle)
.Show();
}

public void Error(string message) => Show(Level.Error, message);

public void Information(string message) => Show(Level.Information, message);

public void Warning(string message) => Show(Level.Warning, message);

#endregion Methods

#region Classes

private static class Icon
{
#region Constructors

static Icon()
{
var path = FileLocation.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Info = FileLocation.Combine(path, @"Assets\IconInfo.png");
Warn = FileLocation.Combine(path, @"Assets\IconWarn.png");
Error = FileLocation.Combine(path, @"Assets\IconError.png");
}

public void Error(string message) => Show(message);
#endregion Constructors

public void Information(string message) => Show(message);
#region Properties

public void Warning(string message) => Show(message);
public static string Error { get; }
public static string Info { get; }
public static string Warn { get; }
public static string None => string.Empty;

#endregion Methods
}
#endregion Properties
};

#endregion Classes
}
11 changes: 5 additions & 6 deletions src/Libraries/System.SQLite.Updater/ScriptManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ public ScriptCollection GetScripts()
{
var regex = new Regex(@"^.*?(\d{1,3}\.{0,1}\d{1,3}\.{0,1}\d{0,3}).*");
var match = regex.Matches(item.Key);
if (match.Count > 0 && match[0].Groups.Count >= 1)
{
var ver = match[0].Groups[1].Value.Trim('.');
var version = new Version(ver);
src.Add(version, item.Value);
}
if (match.Count <= 0 || match[0].Groups.Count < 1) continue;

var ver = match[0].Groups[1].Value.Trim('.');
var version = new Version(ver);
src.Add(version, item.Value);
}
var ordered = src.OrderBy(x => x.Key);
return new ScriptCollection(new Dictionary<Version, string>(ordered));
Expand Down

0 comments on commit 0892843

Please sign in to comment.