Add Windows share target draft attachment flow

This commit is contained in:
Burak Kaan Köse
2026-04-14 01:23:39 +02:00
parent 4bea53a667
commit aa16609f89
9 changed files with 307 additions and 3 deletions
+24 -1
View File
@@ -19,6 +19,7 @@ using Wino.Core.Domain.Extensions;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.MailItem;
using Wino.Core.Domain.Models;
using Wino.Core.Domain.Models.Launch;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.Extensions;
using Wino.Core.Services;
@@ -159,6 +160,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
public readonly IPreferencesService PreferencesService;
public readonly IContactService ContactService;
public readonly ISmimeCertificateService _smimeCertificateService;
private readonly IShareActivationService _shareActivationService;
public ComposePageViewModel(IMailDialogService dialogService,
IMailService mailService,
@@ -172,7 +174,8 @@ public partial class ComposePageViewModel : MailBaseViewModel,
IContactService contactService,
IFontService fontService,
IPreferencesService preferencesService,
ISmimeCertificateService smimeCertificateService)
ISmimeCertificateService smimeCertificateService,
IShareActivationService shareActivationService)
{
NativeAppService = nativeAppService;
ContactService = contactService;
@@ -188,6 +191,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
_emailTemplateService = emailTemplateService;
_worker = worker;
_smimeCertificateService = smimeCertificateService;
_shareActivationService = shareActivationService;
foreach (var cert in _smimeCertificateService.GetCertificates(emailAddress: SelectedAlias?.AliasAddress))
{
@@ -752,6 +756,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
await LoadAddressInfoAsync(replyingMime.Bcc, BCCItems);
LoadAttachments();
ApplyPendingSharedAttachments();
if (replyingMime.Cc.Any() || replyingMime.Bcc.Any())
IsCCBCCVisible = true;
@@ -783,6 +788,24 @@ public partial class ComposePageViewModel : MailBaseViewModel,
}
}
private void ApplyPendingSharedAttachments()
{
var draftUniqueId = CurrentMailDraftItem?.MailCopy?.UniqueId ?? Guid.Empty;
if (draftUniqueId == Guid.Empty)
return;
var shareRequest = _shareActivationService.ConsumePendingComposeShareRequest(draftUniqueId);
if (shareRequest?.Files == null || shareRequest.Files.Count == 0)
return;
foreach (var sharedFile in shareRequest.Files)
{
IncludedAttachments.Add(new MailAttachmentViewModel(sharedFile));
}
}
private async Task LoadAddressInfoAsync(InternetAddressList list, ObservableCollection<AccountContact> collection)
{
foreach (var item in list)
+44 -2
View File
@@ -15,8 +15,9 @@ using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.MenuItems;
using Wino.Core.Domain.Models.Folders;
using Wino.Core.Domain.Models;
using Wino.Core.Domain.Models.Folders;
using Wino.Core.Domain.Models.Launch;
using Wino.Core.Domain.Models.MailItem;
using Wino.Core.Domain.Models.Navigation;
using Wino.Core.Domain.Models.Synchronization;
@@ -84,6 +85,7 @@ public partial class MailAppShellViewModel : MailBaseViewModel,
private readonly IMimeFileService _mimeFileService;
private readonly IWebView2RuntimeValidatorService _webView2RuntimeValidatorService;
private readonly IStoreUpdateService _storeUpdateService;
private readonly IShareActivationService _shareActivationService;
private readonly INativeAppService _nativeAppService;
private readonly IMailService _mailService;
@@ -109,7 +111,8 @@ public partial class MailAppShellViewModel : MailBaseViewModel,
IConfigurationService configurationService,
IStartupBehaviorService startupBehaviorService,
IWebView2RuntimeValidatorService webView2RuntimeValidatorService,
IStoreUpdateService storeUpdateService)
IStoreUpdateService storeUpdateService,
IShareActivationService shareActivationService)
{
StatePersistenceService = statePersistanceService;
@@ -131,6 +134,7 @@ public partial class MailAppShellViewModel : MailBaseViewModel,
_winoRequestDelegator = winoRequestDelegator;
_webView2RuntimeValidatorService = webView2RuntimeValidatorService;
_storeUpdateService = storeUpdateService;
_shareActivationService = shareActivationService;
}
protected override void OnDispatcherAssigned()
@@ -274,6 +278,7 @@ public partial class MailAppShellViewModel : MailBaseViewModel,
}
await ProcessLaunchOptionsAsync();
await HandlePendingShareRequestAsync();
await ValidateWebView2RuntimeAsync();
if (shouldRunStartupFlows && !Debugger.IsAttached)
@@ -943,6 +948,9 @@ public partial class MailAppShellViewModel : MailBaseViewModel,
}
public async Task CreateNewMailForAsync(MailAccount account)
=> await CreateNewMailForAsync(account, null);
public async Task CreateNewMailForAsync(MailAccount account, MailShareRequest shareRequest)
{
if (account == null) return;
@@ -974,6 +982,11 @@ public partial class MailAppShellViewModel : MailBaseViewModel,
var (draftMailCopy, draftBase64MimeMessage) = await _mailService.CreateDraftAsync(account.Id, draftOptions).ConfigureAwait(false);
if (shareRequest?.Files?.Count > 0)
{
_shareActivationService.StagePendingComposeShareRequest(draftMailCopy.UniqueId, shareRequest);
}
var draftPreparationRequest = new DraftPreparationRequest(account, draftMailCopy, draftBase64MimeMessage, draftOptions.Reason);
await _winoRequestDelegator.ExecuteAsync(draftPreparationRequest);
}
@@ -1034,6 +1047,35 @@ public partial class MailAppShellViewModel : MailBaseViewModel,
await CreateNewMailForAsync(targetAccount);
}
public async Task HandlePendingShareRequestAsync()
{
var shareRequest = _shareActivationService.ConsumePendingShareRequest();
if (shareRequest?.Files == null || shareRequest.Files.Count == 0)
return;
var accounts = await _accountService.GetAccountsAsync();
if (!accounts.Any())
return;
MailAccount targetAccount = null;
if (accounts.Count == 1)
{
targetAccount = accounts[0];
}
else
{
targetAccount = await _dialogService.ShowAccountPickerDialogAsync(accounts);
}
if (targetAccount == null)
return;
await CreateNewMailForAsync(targetAccount, shareRequest);
}
private async Task RecreateMenuItemsAsync()
{
await _menuRefreshSemaphore.WaitAsync().ConfigureAwait(false);