Skip to content

Commit

Permalink
Theme fixes, major perf. improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
WamWooWam committed Sep 19, 2024
1 parent 0b054b2 commit 1c5664a
Show file tree
Hide file tree
Showing 27 changed files with 666 additions and 679 deletions.
3 changes: 3 additions & 0 deletions Unicord.Universal.Background/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
<runtime>
<GCConserveMemory enabled="5"/>
</runtime>
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>
1 change: 0 additions & 1 deletion Unicord.Universal.Background/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
Application.Run(new NotificationApplicationContext());
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<ProjectReference Include="..\libraries\DSharpPlus\DSharpPlus\DSharpPlus.csproj" />
<ProjectReference Include="..\Libraries\MomentSharp\MomentSharp\MomentSharp.csproj" />
<ProjectReference Include="..\Libraries\WamWooWam.Core\WamWooWam.Core\WamWooWam.Core.csproj" />
<ProjectReference Include="..\Unicord\Unicord.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Unicord.Universal.Package/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
IgnorableNamespaces="uap mp uap2 uap3 uap4 uap5 rescap">
<Identity Name="24101WamWooWamRD.Unicord" Publisher="CN=0F22111D-EDF0-42F0-B58D-26C4C5C5054B" Version="2.0.24.0" />
<Identity Name="24101WamWooWamRD.Unicord" Publisher="CN=0F22111D-EDF0-42F0-B58D-26C4C5C5054B" Version="2.0.27.0" />
<mp:PhoneIdentity PhoneProductId="5783aabf-3049-421f-ae1d-e88bd89018f2" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>ms-resource:AppDisplayName</DisplayName>
Expand Down
320 changes: 160 additions & 160 deletions Unicord.Universal/Controls/ImageElement.cs
Original file line number Diff line number Diff line change
@@ -1,167 +1,167 @@
using Microsoft.Toolkit.Uwp.UI.Controls;
using System;
using System.Globalization;
using System.Net.Mail;
using System.Web;
using Unicord.Universal.Utilities;
using WamWooWam.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Imaging;

namespace Unicord.Universal.Controls
{
public sealed class ImageElement : Control
{
public int ImageWidth
{
get => (int)GetValue(ImageWidthProperty);
set => SetValue(ImageWidthProperty, value);
}

public static readonly DependencyProperty ImageWidthProperty =
DependencyProperty.Register("ImageWidth", typeof(int), typeof(ImageElement), new PropertyMetadata(0));

public int ImageHeight
{
get => (int)GetValue(ImageHeightProperty);
set => SetValue(ImageHeightProperty, value);
}

public static readonly DependencyProperty ImageHeightProperty =
DependencyProperty.Register("ImageHeight", typeof(int), typeof(ImageElement), new PropertyMetadata(0));

public Uri ImageUri
{
get => (Uri)GetValue(ImageUriProperty);
set => SetValue(ImageUriProperty, value);
}

public static readonly DependencyProperty ImageUriProperty =
DependencyProperty.Register("ImageUri", typeof(Uri), typeof(ImageElement), new PropertyMetadata(null, OnImageChanged));

public bool IsSpoiler
{
get => (bool)GetValue(IsSpoilerProperty);
set => SetValue(IsSpoilerProperty, value);
}

public static readonly DependencyProperty IsSpoilerProperty =
DependencyProperty.Register("IsSpoiler", typeof(bool), typeof(ImageElement), new PropertyMetadata(false));

private bool _templated;
private BitmapImage _img;
private bool _addedEvent;

public ImageElement()
{
DefaultStyleKey = typeof(ImageElement);
Unloaded += ImageElement_Unloaded;
}

private static void OnImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ImageElement element)
{
if (!element._templated)
{
element._templated = element.ApplyTemplate();
using Microsoft.Toolkit.Uwp.UI.Controls;
using System;
using System.Globalization;
using System.Net.Mail;
using System.Web;
using Unicord.Universal.Utilities;
using WamWooWam.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Imaging;

namespace Unicord.Universal.Controls
{
public sealed class ImageElement : Control
{
public int ImageWidth
{
get => (int)GetValue(ImageWidthProperty);
set => SetValue(ImageWidthProperty, value);
}

public static readonly DependencyProperty ImageWidthProperty =
DependencyProperty.Register("ImageWidth", typeof(int), typeof(ImageElement), new PropertyMetadata(0));

public int ImageHeight
{
get => (int)GetValue(ImageHeightProperty);
set => SetValue(ImageHeightProperty, value);
}

public static readonly DependencyProperty ImageHeightProperty =
DependencyProperty.Register("ImageHeight", typeof(int), typeof(ImageElement), new PropertyMetadata(0));

public Uri ImageUri
{
get => (Uri)GetValue(ImageUriProperty);
set => SetValue(ImageUriProperty, value);
}

public static readonly DependencyProperty ImageUriProperty =
DependencyProperty.Register("ImageUri", typeof(Uri), typeof(ImageElement), new PropertyMetadata(null, OnImageChanged));

public bool IsSpoiler
{
get => (bool)GetValue(IsSpoilerProperty);
set => SetValue(IsSpoilerProperty, value);
}

public static readonly DependencyProperty IsSpoilerProperty =
DependencyProperty.Register("IsSpoiler", typeof(bool), typeof(ImageElement), new PropertyMetadata(false));

private bool _templated;
private BitmapImage _img;
private bool _addedEvent;

public ImageElement()
{
DefaultStyleKey = typeof(ImageElement);
Unloaded += ImageElement_Unloaded;
}

private static void OnImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is ImageElement element)
{
if (!element._templated)
{
element._templated = element.ApplyTemplate();
}

LoadImage(element);
}
}

private static void LoadImage(ImageElement element)
{
var image = element.GetTemplateChild("image") as ImageEx;
if (image == null || element.ImageUri == null) return;

double width = element.ImageWidth;
double height = element.ImageHeight;
LoadImage(element);
}
}

private static void LoadImage(ImageElement element)
{
var image = element.GetTemplateChild("image") as ImageEx;
if (image == null || element.ImageUri == null) return;

double width = element.ImageWidth;
double height = element.ImageHeight;
Drawing.ScaleProportions(ref width, ref height, 480, 480);

var thumbUrl = new UriBuilder(element.ImageUri);
var query = HttpUtility.ParseQueryString(thumbUrl.Query);
if (Tools.ShouldUseWebP)
query["format"] = "webp";
query["width"] = ((int)width).ToString(CultureInfo.InvariantCulture);
query["height"] = ((int)height).ToString(CultureInfo.InvariantCulture);
thumbUrl.Query = query.ToString();

element._img = new BitmapImage(thumbUrl.Uri)
{
DecodePixelWidth = (int)width,
DecodePixelHeight = (int)height
};

//image.Width = width;
//image.Height = height;

if (!App.RoamingSettings.Read(Constants.GIF_AUTOPLAY, true) || NetworkHelper.IsNetworkLimited)
{
element._img.AutoPlay = false;
image.PointerEntered += element.Image_PointerEntered;
image.PointerExited += element.Image_PointerExited;
}
else if (!element._addedEvent)
{
element._addedEvent = true;
Window.Current.VisibilityChanged += element.Current_VisibilityChanged;
}

image.Source = element._img;
}

protected override void OnApplyTemplate()
{
_templated = true;

if (ImageUri != null)
{
LoadImage(this);
}
}

private void Image_PointerExited(object sender, PointerRoutedEventArgs e)
{
if (sender is ImageEx i && i.Source is BitmapImage image)
{
image.Stop();
}
}

private void Image_PointerEntered(object sender, PointerRoutedEventArgs e)
{
if (sender is ImageEx i && i.Source is BitmapImage image)
{
image.Play();
}
}

private void Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e)
{
if (_img != null)
{
if (e.Visible)
{
_img.Play();
}
else
{
_img.Stop();
}
}
}

private void ImageElement_Unloaded(object sender, RoutedEventArgs e)
{
_img = null;
if (_addedEvent)
{
Window.Current.VisibilityChanged -= Current_VisibilityChanged;
}
}
}
}
query["format"] = "webp";
query["width"] = ((int)width).ToString(CultureInfo.InvariantCulture);
query["height"] = ((int)height).ToString(CultureInfo.InvariantCulture);
thumbUrl.Query = query.ToString();

element._img = new BitmapImage(thumbUrl.Uri)
{
DecodePixelWidth = (int)width,
DecodePixelHeight = (int)height
};

//image.Width = width;
//image.Height = height;

if (!App.RoamingSettings.Read(Constants.GIF_AUTOPLAY, true) || NetworkHelper.IsNetworkLimited)
{
element._img.AutoPlay = false;
image.PointerEntered += element.Image_PointerEntered;
image.PointerExited += element.Image_PointerExited;
}
else if (!element._addedEvent)
{
element._addedEvent = true;
Window.Current.VisibilityChanged += element.Current_VisibilityChanged;
}

image.Source = element._img;
}

protected override void OnApplyTemplate()
{
_templated = true;

if (ImageUri != null)
{
LoadImage(this);
}
}

private void Image_PointerExited(object sender, PointerRoutedEventArgs e)
{
if (sender is ImageEx i && i.Source is BitmapImage image)
{
image.Stop();
}
}

private void Image_PointerEntered(object sender, PointerRoutedEventArgs e)
{
if (sender is ImageEx i && i.Source is BitmapImage image)
{
image.Play();
}
}

private void Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e)
{
if (_img != null)
{
if (e.Visible)
{
_img.Play();
}
else
{
_img.Stop();
}
}
}

private void ImageElement_Unloaded(object sender, RoutedEventArgs e)
{
_img = null;
if (_addedEvent)
{
Window.Current.VisibilityChanged -= Current_VisibilityChanged;
}
}
}
}
2 changes: 1 addition & 1 deletion Unicord.Universal/Misc/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class Logger
}, new LoggerFilterOptions()
{
#if DEBUG
MinLevel = LogLevel.Trace
MinLevel = LogLevel.Debug
#else
MinLevel = LogLevel.Information
#endif
Expand Down
2 changes: 1 addition & 1 deletion Unicord.Universal/Models/ChannelEditViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Unicord.Universal.Models
{
public class ChannelEditViewModel : NotifyPropertyChangeImpl
public class ChannelEditViewModel : ViewModelBase
{
public ChannelEditViewModel(DiscordChannel channel)
{
Expand Down
Loading

0 comments on commit 1c5664a

Please sign in to comment.