Fix - Resolved an issue where the window could get stuck in a minimized state when minimized using the taskbar icon https://github.com/Crunchy-DL/Crunchy-Downloader/issues/102

This commit is contained in:
Elwador 2024-08-27 02:16:59 +02:00
parent 47fae7e933
commit 33dba5322e
2 changed files with 15 additions and 8 deletions

View File

@ -45,7 +45,7 @@ public class Widevine{
var fileInfo = new FileInfo(file); var fileInfo = new FileInfo(file);
if (fileInfo.Length < 1024 * 8 && !fileInfo.Attributes.HasFlag(FileAttributes.Directory)){ if (fileInfo.Length < 1024 * 8 && !fileInfo.Attributes.HasFlag(FileAttributes.Directory)){
string fileContents = File.ReadAllText(file, Encoding.UTF8); string fileContents = File.ReadAllText(file, Encoding.UTF8);
if (fileContents.Contains("-BEGIN RSA PRIVATE KEY-")){ if (fileContents.Contains("-BEGIN RSA PRIVATE KEY-") || fileContents.Contains("-BEGIN PRIVATE KEY-")){
privateKey = File.ReadAllBytes(file); privateKey = File.ReadAllBytes(file);
} }

View File

@ -1,11 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Platform; using Avalonia.Platform;
using CRD.Downloader.Crunchyroll; using CRD.Downloader.Crunchyroll;
using CRD.Utils; using CRD.Utils;
@ -13,7 +12,6 @@ using CRD.Utils.Files;
using CRD.Utils.Structs; using CRD.Utils.Structs;
using CRD.Utils.Updater; using CRD.Utils.Updater;
using CRD.ViewModels; using CRD.ViewModels;
using CRD.Views;
using CRD.Views.Utils; using CRD.Views.Utils;
using FluentAvalonia.Core; using FluentAvalonia.Core;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
@ -77,7 +75,7 @@ public partial class MainWindow : AppWindow{
//select first element as default //select first element as default
var nv = this.FindControl<NavigationView>("NavView"); var nv = this.FindControl<NavigationView>("NavView");
nv.SelectedItem = nv.MenuItems.ElementAt(0); nv.SelectedItem = IEnumerableExtensions.ElementAt(nv.MenuItems, 0);
selectedNavVieItem = nv.SelectedItem; selectedNavVieItem = nv.SelectedItem;
MessageBus.Current.Listen<NavigationMessage>() MessageBus.Current.Listen<NavigationMessage>()
@ -246,9 +244,8 @@ public partial class MainWindow : AppWindow{
} }
private void OnWindowStateChanged(object sender, AvaloniaPropertyChangedEventArgs e){ private void OnWindowStateChanged(object sender, AvaloniaPropertyChangedEventArgs e){
if (e.Property == Window.WindowStateProperty){ if (e.Property == WindowStateProperty){
if (WindowState == WindowState.Normal){ if (WindowState == WindowState.Normal){
// When the window is restored to normal, use the stored restore size and position
Width = _restoreSize.Width; Width = _restoreSize.Width;
Height = _restoreSize.Height; Height = _restoreSize.Height;
Position = _restorePosition; Position = _restorePosition;
@ -258,7 +255,17 @@ public partial class MainWindow : AppWindow{
private void OnPositionChanged(object sender, PixelPointEventArgs e){ private void OnPositionChanged(object sender, PixelPointEventArgs e){
if (WindowState == WindowState.Normal){ if (WindowState == WindowState.Normal){
_restorePosition = e.Point; var screens = Screens.All;
bool isWithinAnyScreen = screens.Any(screen =>
e.Point.X >= screen.WorkingArea.X &&
e.Point.X <= screen.WorkingArea.X + screen.WorkingArea.Width &&
e.Point.Y >= screen.WorkingArea.Y &&
e.Point.Y <= screen.WorkingArea.Y + screen.WorkingArea.Height);
if (isWithinAnyScreen){
_restorePosition = e.Point;
}
} }
} }