Migrate mail printing to WinUI print preview
This commit is contained in:
@@ -58,9 +58,9 @@ public partial class MailRenderingPageViewModel : MailBaseViewModel,
|
||||
private MimeMessageInformation initializedMimeMessageInformation = null;
|
||||
|
||||
// Func to get WebView2 to save current HTML as PDF to given location.
|
||||
// Used in 'Save as' and 'Print' functionality.
|
||||
// Used in 'Save as' functionality.
|
||||
public Func<string, Task<bool>> SaveHTMLasPDFFunc { get; set; }
|
||||
public Func<WebView2PrintSettingsModel, Task<PrintingResult>> DirectPrintFuncAsync { get; set; }
|
||||
public Func<WebView2PrintSettingsModel, Task<Stream>> RenderPdfStreamFuncAsync { get; set; }
|
||||
public Func<string, Task> RenderHtmlAsyncFunc { get; set; }
|
||||
public Func<Task> ClearRenderedHtmlAsyncFunc { get; set; }
|
||||
|
||||
@@ -275,17 +275,17 @@ public partial class MailRenderingPageViewModel : MailBaseViewModel,
|
||||
}
|
||||
else if (operation == MailOperation.Print)
|
||||
{
|
||||
var settings = await _dialogService.ShowPrintDialogAsync();
|
||||
|
||||
if (settings == null) return;
|
||||
|
||||
var printingResult = await DirectPrintFuncAsync.Invoke(settings);
|
||||
var printingResult = await PrintAsync();
|
||||
|
||||
// TODO: More detailed printing result handling.
|
||||
if (printingResult == PrintingResult.Submitted)
|
||||
{
|
||||
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingSuccessTitle, Translator.DialogMessage_PrintingSuccessMessage, InfoBarMessageType.Success);
|
||||
}
|
||||
else if (printingResult == PrintingResult.Canceled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (printingResult == PrintingResult.Failed)
|
||||
{
|
||||
_dialogService.InfoBarMessage(Translator.DialogMessage_PrintingFailedTitle, Translator.DialogMessage_PrintingFailedMessage, InfoBarMessageType.Error);
|
||||
@@ -784,6 +784,22 @@ public partial class MailRenderingPageViewModel : MailBaseViewModel,
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<PrintingResult> PrintAsync()
|
||||
{
|
||||
if (RenderPdfStreamFuncAsync == null)
|
||||
return PrintingResult.Failed;
|
||||
|
||||
var windowHandle = NativeAppService.GetCoreWindowHwnd();
|
||||
if (windowHandle == IntPtr.Zero)
|
||||
return PrintingResult.Failed;
|
||||
|
||||
var printTitle = string.IsNullOrWhiteSpace(Subject)
|
||||
? Translator.MailItemNoSubject
|
||||
: Subject;
|
||||
|
||||
return await PrintService.PrintAsync(windowHandle, printTitle, RenderPdfStreamFuncAsync);
|
||||
}
|
||||
|
||||
// Returns created file path.
|
||||
private async Task<string> SaveAttachmentInternalAsync(MailAttachmentViewModel attachmentViewModel, string saveFolderPath)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user