2023-05-20 01:27:35 +12:00
|
|
|
|
// <copyright file="StaticResources.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu.Resources
|
|
|
|
|
{
|
|
|
|
|
using System.Drawing;
|
2023-08-12 08:25:25 +12:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
2023-05-20 01:27:35 +12:00
|
|
|
|
using System.Windows.Media;
|
2023-08-12 08:25:25 +12:00
|
|
|
|
using System.Windows.Media.Imaging;
|
2023-05-20 01:27:35 +12:00
|
|
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
|
|
2023-08-12 08:25:25 +12:00
|
|
|
|
internal static class StaticResources
|
2023-05-20 01:27:35 +12:00
|
|
|
|
{
|
|
|
|
|
internal static readonly Icon LoadingIcon = Properties.Resources.Loading;
|
|
|
|
|
|
2023-08-12 08:25:25 +12:00
|
|
|
|
private static readonly object ApplicationImgSrcLock = new();
|
2023-05-20 01:27:35 +12:00
|
|
|
|
private static readonly object LoadingImgSrcLock = new ();
|
|
|
|
|
|
2023-08-12 08:25:25 +12:00
|
|
|
|
private static ImageSource? applicationgImgSrc;
|
2023-05-20 01:27:35 +12:00
|
|
|
|
private static ImageSource? loadingImgSrc;
|
|
|
|
|
|
2023-08-12 08:25:25 +12:00
|
|
|
|
public static ImageSource? ApplicationImgSrc
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (applicationgImgSrc == null)
|
|
|
|
|
{
|
|
|
|
|
lock (ApplicationImgSrcLock)
|
|
|
|
|
{
|
|
|
|
|
if (applicationgImgSrc == null)
|
|
|
|
|
{
|
|
|
|
|
applicationgImgSrc = LoadFromAssemblyManifestResources("Resources.SystemTrayMenu.png");
|
|
|
|
|
applicationgImgSrc?.Freeze(); // Make it accessible for any thread
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return applicationgImgSrc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ImageSource LoadingImgSrc
|
2023-05-20 01:27:35 +12:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (loadingImgSrc == null)
|
|
|
|
|
{
|
|
|
|
|
lock (LoadingImgSrcLock)
|
|
|
|
|
{
|
|
|
|
|
if (loadingImgSrc == null)
|
|
|
|
|
{
|
2023-05-20 06:43:19 +12:00
|
|
|
|
loadingImgSrc = Properties.Resources.Loading.ToBitmapSource();
|
2023-05-20 07:26:47 +12:00
|
|
|
|
loadingImgSrc.Freeze(); // Make it accessible for any thread
|
2023-05-20 01:27:35 +12:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return loadingImgSrc;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-12 08:25:25 +12:00
|
|
|
|
|
|
|
|
|
private static ImageSource? LoadFromAssemblyManifestResources(string name)
|
|
|
|
|
{
|
|
|
|
|
Assembly myassembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
string myname = myassembly.GetName().Name ?? string.Empty;
|
|
|
|
|
|
|
|
|
|
using (Stream? imgstream = myassembly.GetManifestResourceStream(myname + "." + name))
|
|
|
|
|
{
|
|
|
|
|
if (imgstream != null)
|
|
|
|
|
{
|
|
|
|
|
BitmapImage imageSource = new();
|
|
|
|
|
imageSource.BeginInit();
|
|
|
|
|
imageSource.StreamSource = imgstream;
|
|
|
|
|
imageSource.EndInit();
|
|
|
|
|
|
|
|
|
|
return imageSource;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-05-20 01:27:35 +12:00
|
|
|
|
}
|
|
|
|
|
}
|