-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
48 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace BilibiliLiveRecordDownLoader.Utils | ||
{ | ||
public static class TaskQueueKeyConstants | ||
{ | ||
public const string LiveRecordKey = @"直播回放下载"; | ||
public const string ContentDialogKey = @"ContentDialog"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 28 additions & 10 deletions
38
BilibiliLiveRecordDownLoader/Views/Dialogs/DisposableContentDialog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,47 @@ | ||
using BilibiliLiveRecordDownLoader.Services; | ||
using BilibiliLiveRecordDownLoader.Utils; | ||
using ModernWpf.Controls; | ||
using Punchclock; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
#pragma warning disable VSTHRD001 | ||
namespace BilibiliLiveRecordDownLoader.Views.Dialogs | ||
{ | ||
public class DisposableContentDialog : ContentDialog, IDisposable | ||
{ | ||
private readonly OperationQueue _queue; | ||
|
||
public DisposableContentDialog() | ||
{ | ||
_queue = DI.GetService<OperationQueue>(); | ||
Owner = DI.GetService<MainWindow>(); | ||
} | ||
|
||
public virtual void Dispose() | ||
{ | ||
Hide(); | ||
} | ||
|
||
public new Task<ContentDialogResult> ShowAsync() | ||
public async Task<ContentDialogResult> SafeShowAsync(int priority = 1, ContentDialogResult defaultResult = ContentDialogResult.None) | ||
{ | ||
Hide(); | ||
if (Owner is not null) | ||
{ | ||
Owner.Focus(); | ||
} | ||
else | ||
return await _queue.Enqueue(priority, TaskQueueKeyConstants.ContentDialogKey, async () => | ||
{ | ||
DI.GetService<MainWindow>().Focus(); | ||
} | ||
return base.ShowAsync(); | ||
var res = defaultResult; | ||
try | ||
{ | ||
await Dispatcher.Invoke(async () => | ||
{ | ||
Owner!.Focus(); | ||
res = await ShowAsync(); | ||
}); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
|
||
} | ||
return res; | ||
}); | ||
} | ||
} | ||
} |