mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 03:32:20 +08:00
WPF: Disable minimize to tray icon when a ContentDialog is open. fix #316
This commit is contained in:
parent
fa9cb75c97
commit
f7be8e9516
2
BannedSymbols.txt
Normal file
2
BannedSymbols.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
M:ModernWpf.Controls.ContentDialog.ShowAsync
|
||||||
|
M:ModernWpf.Controls.ContentDialog.ShowAsync(ModernWpf.Controls.ContentDialogPlacement)
|
|
@ -92,6 +92,7 @@
|
||||||
<Compile Include="Controls\CloseWindowConfirmDialog.xaml.cs">
|
<Compile Include="Controls\CloseWindowConfirmDialog.xaml.cs">
|
||||||
<DependentUpon>CloseWindowConfirmDialog.xaml</DependentUpon>
|
<DependentUpon>CloseWindowConfirmDialog.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Controls\ContentDialogExtensions.cs" />
|
||||||
<Compile Include="Controls\DeleteRoomConfirmDialog.xaml.cs">
|
<Compile Include="Controls\DeleteRoomConfirmDialog.xaml.cs">
|
||||||
<DependentUpon>DeleteRoomConfirmDialog.xaml</DependentUpon>
|
<DependentUpon>DeleteRoomConfirmDialog.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -407,4 +408,4 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Exec Command="$(PkgNuGet_CommandLine)\tools\NuGet pack BililiveRecorder.nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=Release -OutputDirectory $(NupkgReleaseDir) -BasePath $(OutDir) -NonInteractive -ForceEnglishOutput" />
|
<Exec Command="$(PkgNuGet_CommandLine)\tools\NuGet pack BililiveRecorder.nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=Release -OutputDirectory $(NupkgReleaseDir) -BasePath $(OutDir) -NonInteractive -ForceEnglishOutput" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
23
BililiveRecorder.WPF/Controls/ContentDialogExtensions.cs
Normal file
23
BililiveRecorder.WPF/Controls/ContentDialogExtensions.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using ModernWpf.Controls;
|
||||||
|
|
||||||
|
namespace BililiveRecorder.WPF.Controls
|
||||||
|
{
|
||||||
|
internal static class ContentDialogExtensions
|
||||||
|
{
|
||||||
|
internal static async Task<ContentDialogResult> ShowAndDisableMinimizeToTrayAsync(this ContentDialog contentDialog)
|
||||||
|
{
|
||||||
|
var mw = (NewMainWindow)Application.Current.MainWindow;
|
||||||
|
mw.HideToTrayBlockedByContentDialog = true;
|
||||||
|
|
||||||
|
#pragma warning disable RS0030 // Do not used banned APIs
|
||||||
|
var result = await contentDialog.ShowAsync();
|
||||||
|
#pragma warning restore RS0030 // Do not used banned APIs
|
||||||
|
|
||||||
|
mw.HideToTrayBlockedByContentDialog = false;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using BililiveRecorder.WPF.Controls;
|
||||||
using ModernWpf.Controls;
|
using ModernWpf.Controls;
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
@ -19,7 +20,7 @@ namespace BililiveRecorder.WPF.Models
|
||||||
public static Commands OpenContentDialog { get; } = new Commands
|
public static Commands OpenContentDialog { get; } = new Commands
|
||||||
{
|
{
|
||||||
#pragma warning disable VSTHRD101 // Avoid unsupported async delegates
|
#pragma warning disable VSTHRD101 // Avoid unsupported async delegates
|
||||||
ExecuteDelegate = async o => { try { await (o as ContentDialog)!.ShowAsync(); } catch (Exception) { } }
|
ExecuteDelegate = async o => { try { await (o as ContentDialog)!.ShowAndDisableMinimizeToTrayAsync(); } catch (Exception) { } }
|
||||||
#pragma warning restore VSTHRD101 // Avoid unsupported async delegates
|
#pragma warning restore VSTHRD101 // Avoid unsupported async delegates
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using BililiveRecorder.WPF.Controls;
|
using BililiveRecorder.WPF.Controls;
|
||||||
|
@ -66,10 +65,11 @@ namespace BililiveRecorder.WPF
|
||||||
|
|
||||||
private bool notification_showed = false;
|
private bool notification_showed = false;
|
||||||
public bool HideToTray { get; set; } = false;
|
public bool HideToTray { get; set; } = false;
|
||||||
|
public bool HideToTrayBlockedByContentDialog { get; set; } = false;
|
||||||
|
|
||||||
private void Window_StateChanged(object sender, EventArgs e)
|
private void Window_StateChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (this.HideToTray && this.WindowState == WindowState.Minimized)
|
if (this.HideToTray && !this.HideToTrayBlockedByContentDialog && this.WindowState == WindowState.Minimized)
|
||||||
{
|
{
|
||||||
this.Hide();
|
this.Hide();
|
||||||
if (!this.notification_showed)
|
if (!this.notification_showed)
|
||||||
|
@ -102,7 +102,7 @@ namespace BililiveRecorder.WPF
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (await new CloseWindowConfirmDialog().ShowAsync() == ContentDialogResult.Primary)
|
if (await new CloseWindowConfirmDialog { Owner = Application.Current.MainWindow }.ShowAndDisableMinimizeToTrayAsync() == ContentDialogResult.Primary)
|
||||||
{
|
{
|
||||||
this.CloseConfirmed = true;
|
this.CloseConfirmed = true;
|
||||||
_ = this.Dispatcher.BeginInvoke(this.Close, DispatcherPriority.Normal);
|
_ = this.Dispatcher.BeginInvoke(this.Close, DispatcherPriority.Normal);
|
||||||
|
|
|
@ -119,10 +119,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
{
|
{
|
||||||
var dialog = new DeleteRoomConfirmDialog
|
var dialog = new DeleteRoomConfirmDialog
|
||||||
{
|
{
|
||||||
DataContext = room
|
DataContext = room,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = await dialog.ShowAsync();
|
var result = await dialog.ShowAndDisableMinimizeToTrayAsync();
|
||||||
|
|
||||||
if (result == ContentDialogResult.Primary)
|
if (result == ContentDialogResult.Primary)
|
||||||
{
|
{
|
||||||
|
@ -139,7 +140,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await new PerRoomSettingsDialog { DataContext = sender }.ShowAsync();
|
await new PerRoomSettingsDialog
|
||||||
|
{
|
||||||
|
DataContext = sender,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
|
}.ShowAndDisableMinimizeToTrayAsync();
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
|
@ -162,7 +167,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await new AddRoomFailedDialog { DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.InvalidInput }.ShowAsync();
|
await new AddRoomFailedDialog
|
||||||
|
{
|
||||||
|
DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.InvalidInput,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
|
}.ShowAndDisableMinimizeToTrayAsync();
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
return;
|
return;
|
||||||
|
@ -173,7 +182,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await new AddRoomFailedDialog { DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.RoomIdNegative }.ShowAsync();
|
await new AddRoomFailedDialog
|
||||||
|
{
|
||||||
|
DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.RoomIdNegative,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
|
}.ShowAndDisableMinimizeToTrayAsync();
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
return;
|
return;
|
||||||
|
@ -182,7 +195,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await new AddRoomFailedDialog { DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.RoomIdZero }.ShowAsync();
|
await new AddRoomFailedDialog
|
||||||
|
{
|
||||||
|
DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.RoomIdZero,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
|
}.ShowAndDisableMinimizeToTrayAsync();
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
return;
|
return;
|
||||||
|
@ -192,7 +209,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await new AddRoomFailedDialog { DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.Duplicate }.ShowAsync();
|
await new AddRoomFailedDialog
|
||||||
|
{
|
||||||
|
DataContext = AddRoomFailedDialog.AddRoomFailedErrorText.Duplicate,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
|
}.ShowAndDisableMinimizeToTrayAsync();
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -169,9 +169,10 @@ You can uninstall me in system settings.", "安装成功 Installed", MessageBoxB
|
||||||
{
|
{
|
||||||
Error = error,
|
Error = error,
|
||||||
Path = lastdir,
|
Path = lastdir,
|
||||||
SkipAsking = pathInfo.SkipAsking
|
SkipAsking = pathInfo.SkipAsking,
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
};
|
};
|
||||||
var dialogResult = await dialog.ShowAsync();
|
var dialogResult = await dialog.ShowAndDisableMinimizeToTrayAsync();
|
||||||
switch (dialogResult)
|
switch (dialogResult)
|
||||||
{
|
{
|
||||||
case ContentDialogResult.Primary:
|
case ContentDialogResult.Primary:
|
||||||
|
|
|
@ -73,10 +73,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
progressDialog = new AutoFixProgressDialog()
|
progressDialog = new AutoFixProgressDialog()
|
||||||
{
|
{
|
||||||
CancelButtonVisibility = Visibility.Visible,
|
CancelButtonVisibility = Visibility.Visible,
|
||||||
CancellationTokenSource = new CancellationTokenSource()
|
CancellationTokenSource = new CancellationTokenSource(),
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
};
|
};
|
||||||
var token = progressDialog.CancellationTokenSource.Token;
|
var token = progressDialog.CancellationTokenSource.Token;
|
||||||
var showTask = progressDialog.ShowAsync();
|
var showTask = progressDialog.ShowAndDisableMinimizeToTrayAsync();
|
||||||
|
|
||||||
string? output_path;
|
string? output_path;
|
||||||
{
|
{
|
||||||
|
@ -170,10 +171,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
progressDialog = new AutoFixProgressDialog()
|
progressDialog = new AutoFixProgressDialog()
|
||||||
{
|
{
|
||||||
CancelButtonVisibility = Visibility.Visible,
|
CancelButtonVisibility = Visibility.Visible,
|
||||||
CancellationTokenSource = new CancellationTokenSource()
|
CancellationTokenSource = new CancellationTokenSource(),
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
};
|
};
|
||||||
var token = progressDialog.CancellationTokenSource.Token;
|
var token = progressDialog.CancellationTokenSource.Token;
|
||||||
var showTask = progressDialog.ShowAsync();
|
var showTask = progressDialog.ShowAndDisableMinimizeToTrayAsync();
|
||||||
|
|
||||||
var req = new AnalyzeRequest
|
var req = new AnalyzeRequest
|
||||||
{
|
{
|
||||||
|
@ -245,10 +247,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
progressDialog = new AutoFixProgressDialog()
|
progressDialog = new AutoFixProgressDialog()
|
||||||
{
|
{
|
||||||
CancelButtonVisibility = Visibility.Visible,
|
CancelButtonVisibility = Visibility.Visible,
|
||||||
CancellationTokenSource = new CancellationTokenSource()
|
CancellationTokenSource = new CancellationTokenSource(),
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
};
|
};
|
||||||
var token = progressDialog.CancellationTokenSource.Token;
|
var token = progressDialog.CancellationTokenSource.Token;
|
||||||
var showTask = progressDialog.ShowAsync();
|
var showTask = progressDialog.ShowAndDisableMinimizeToTrayAsync();
|
||||||
|
|
||||||
var outputPath = string.Empty;
|
var outputPath = string.Empty;
|
||||||
{
|
{
|
||||||
|
|
|
@ -134,10 +134,11 @@ namespace BililiveRecorder.WPF.Pages
|
||||||
progressDialog = new AutoFixProgressDialog()
|
progressDialog = new AutoFixProgressDialog()
|
||||||
{
|
{
|
||||||
CancelButtonVisibility = Visibility.Collapsed,
|
CancelButtonVisibility = Visibility.Collapsed,
|
||||||
CancellationTokenSource = new CancellationTokenSource()
|
CancellationTokenSource = new CancellationTokenSource(),
|
||||||
|
Owner = Application.Current.MainWindow
|
||||||
};
|
};
|
||||||
var token = progressDialog.CancellationTokenSource.Token;
|
var token = progressDialog.CancellationTokenSource.Token;
|
||||||
var showTask = progressDialog.ShowAsync();
|
var showTask = progressDialog.ShowAndDisableMinimizeToTrayAsync();
|
||||||
|
|
||||||
string? outputPath;
|
string? outputPath;
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,9 +7,16 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.3">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10">
|
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<AdditionalFiles Include="$(MSBuildThisFileDirectory)BannedSymbols.txt" Link="BannedSymbols.txt"/>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user