Added sample packaged project and added app context based on whether you are running the app natively or thru an app package
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
using Microsoft.Windows.Sdk;
|
||||
|
||||
namespace NotificationFlyout.Uwp.UI.Extensions
|
||||
{
|
||||
internal class ExecutionMode
|
||||
{
|
||||
internal static bool IsRunningWithIdentity()
|
||||
{
|
||||
uint packageNameLength = 0;
|
||||
int result = PInvoke.GetCurrentPackageFullName(ref packageNameLength, "1024");
|
||||
|
||||
return result != 15700;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,31 @@ using System.Drawing;
|
||||
using System.IO;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace NotificationFlyout.Uwp.UI.Extensions
|
||||
{
|
||||
public static class ImageSourceExtensions
|
||||
{
|
||||
public static Icon ConvertToIcon(this ImageSource imageSource, uint dpi)
|
||||
public static async Task<Icon> ConvertToIconAsync(this ImageSource imageSource, uint dpi)
|
||||
{
|
||||
var bitmapImage = (BitmapImage)imageSource;
|
||||
var uri = $"{AppDomain.CurrentDomain.BaseDirectory}{bitmapImage.UriSource}".Replace("ms-appx:///", "").Replace("/", "\\");
|
||||
if (!ExecutionMode.IsRunningWithIdentity())
|
||||
{
|
||||
var uri = $"{AppDomain.CurrentDomain.BaseDirectory}{bitmapImage.UriSource}".Replace("ms-appx:///", "").Replace("/", "\\");
|
||||
|
||||
using var stream = File.OpenRead(uri);
|
||||
return new Icon(stream, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
||||
using var stream = File.OpenRead(uri);
|
||||
return new Icon(stream, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
||||
}
|
||||
else
|
||||
{
|
||||
var storageFile = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(bitmapImage.UriSource);
|
||||
using var stream = await storageFile.OpenStreamForReadAsync();
|
||||
return new Icon(stream, new Size(PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CXICON, dpi), PInvoke.GetSystemMetricsForDpi((int)SystemMetricFlag.SM_CYICON, dpi)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private enum SystemMetricFlag : int
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
GetSystemMetricsForDpi
|
||||
GetSystemMetricsForDpi
|
||||
GetCurrentPackageFullName
|
||||
+3
-2
@@ -179,7 +179,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateIcons()
|
||||
private async void UpdateIcons()
|
||||
{
|
||||
if (!_isLoaded) return;
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
var iconSource = _systemPersonalisationHelper.Theme == SystemTheme.Dark ? _defaultIconSource : _lightIconSource;
|
||||
if (iconSource == null) return;
|
||||
|
||||
using var icon = iconSource.ConvertToIcon(dpi);
|
||||
using var icon = await iconSource.ConvertToIconAsync(dpi);
|
||||
_notificationIconHelper.SetIcon(icon.Handle);
|
||||
}
|
||||
|
||||
@@ -212,6 +212,7 @@ namespace NotificationFlyout.Wpf.UI.Controls
|
||||
flyoutHost.RequestedTheme = requestedTheme;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateWindow()
|
||||
{
|
||||
if (!_isLoaded) return;
|
||||
|
||||
Reference in New Issue
Block a user