Make services aot compatible.

This commit is contained in:
Burak Kaan Köse
2025-11-14 14:28:10 +01:00
parent d9ef81729f
commit 8cb8f27e00
8 changed files with 58 additions and 57 deletions
+21 -21
View File
@@ -92,7 +92,7 @@ public class AccountService : BaseDatabaseService, IAccountService
}); });
await Connection.ExecuteAsync(query.GetRawQuery()).ConfigureAwait(false); await Connection.ExecuteAsync(query.GetRawQuery()).ConfigureAwait(false);
await Connection.DeleteAsync(mergedInbox).ConfigureAwait(false); await Connection.DeleteAsync<MergedInbox>(mergedInbox).ConfigureAwait(false);
// Change the startup entity id if it was the merged inbox. // Change the startup entity id if it was the merged inbox.
// Take the first account as startup account. // Take the first account as startup account.
@@ -135,7 +135,7 @@ public class AccountService : BaseDatabaseService, IAccountService
accountFolderList.Add(folder); accountFolderList.Add(folder);
folder.IsSticky = false; folder.IsSticky = false;
await Connection.UpdateAsync(folder); await Connection.UpdateAsync(folder, typeof(MailItemFolder));
} }
accountFolderDictionary.Add(account, accountFolderList); accountFolderDictionary.Add(account, accountFolderList);
@@ -170,20 +170,20 @@ public class AccountService : BaseDatabaseService, IAccountService
{ {
folder.IsSticky = true; folder.IsSticky = true;
await Connection.UpdateAsync(folder); await Connection.UpdateAsync(folder, typeof(MailItemFolder));
} }
} }
} }
} }
// 3. Insert merged inbox and assign accounts. // 3. Insert merged inbox and assign accounts.
await Connection.InsertAsync(mergedInbox); await Connection.InsertAsync(mergedInbox, typeof(MergedInbox));
foreach (var account in accountsToMerge) foreach (var account in accountsToMerge)
{ {
account.MergedInboxId = mergedInbox.Id; account.MergedInboxId = mergedInbox.Id;
await Connection.UpdateAsync(account); await Connection.UpdateAsync(account, typeof(MailAccount));
} }
WeakReferenceMessenger.Default.Send(new AccountsMenuRefreshRequested()); WeakReferenceMessenger.Default.Send(new AccountsMenuRefreshRequested());
@@ -254,7 +254,7 @@ public class AccountService : BaseDatabaseService, IAccountService
Id = Guid.NewGuid() Id = Guid.NewGuid()
}; };
await Connection.InsertAsync(rootAlias).ConfigureAwait(false); await Connection.InsertAsync(rootAlias, typeof(MailAccountAlias)).ConfigureAwait(false);
Log.Information("Created root alias for the account {AccountId}", accountId); Log.Information("Created root alias for the account {AccountId}", accountId);
} }
@@ -321,9 +321,9 @@ public class AccountService : BaseDatabaseService, IAccountService
await Connection.Table<CustomServerInformation>().DeleteAsync(a => a.AccountId == account.Id); await Connection.Table<CustomServerInformation>().DeleteAsync(a => a.AccountId == account.Id);
if (account.Preferences != null) if (account.Preferences != null)
await Connection.DeleteAsync(account.Preferences); await Connection.DeleteAsync<MailAccountPreferences>(account.Preferences);
await Connection.DeleteAsync(account); await Connection.DeleteAsync<MailAccount>(account);
await _mimeFileService.DeleteUserMimeCacheAsync(account.Id).ConfigureAwait(false); await _mimeFileService.DeleteUserMimeCacheAsync(account.Id).ConfigureAwait(false);
@@ -370,7 +370,7 @@ public class AccountService : BaseDatabaseService, IAccountService
IsRootContact = true IsRootContact = true
}; };
await Connection.InsertOrReplaceAsync(accountContact).ConfigureAwait(false); await Connection.InsertOrReplaceAsync(accountContact, typeof(AccountContact)).ConfigureAwait(false);
await UpdateAccountAsync(account).ConfigureAwait(false); await UpdateAccountAsync(account).ConfigureAwait(false);
} }
@@ -402,15 +402,15 @@ public class AccountService : BaseDatabaseService, IAccountService
public async Task UpdateAccountAsync(MailAccount account) public async Task UpdateAccountAsync(MailAccount account)
{ {
await Connection.UpdateAsync(account.Preferences).ConfigureAwait(false); await Connection.UpdateAsync(account.Preferences, typeof(MailAccountPreferences)).ConfigureAwait(false);
await Connection.UpdateAsync(account).ConfigureAwait(false); await Connection.UpdateAsync(account, typeof(MailAccount)).ConfigureAwait(false);
ReportUIChange(new AccountUpdatedMessage(account)); ReportUIChange(new AccountUpdatedMessage(account));
} }
public async Task UpdateAccountCustomServerInformationAsync(CustomServerInformation customServerInformation) public async Task UpdateAccountCustomServerInformationAsync(CustomServerInformation customServerInformation)
{ {
await Connection.UpdateAsync(customServerInformation).ConfigureAwait(false); await Connection.UpdateAsync(customServerInformation, typeof(CustomServerInformation)).ConfigureAwait(false);
} }
public async Task UpdateAccountAliasesAsync(Guid accountId, List<MailAccountAlias> aliases) public async Task UpdateAccountAliasesAsync(Guid accountId, List<MailAccountAlias> aliases)
@@ -421,7 +421,7 @@ public class AccountService : BaseDatabaseService, IAccountService
// Insert new ones. // Insert new ones.
foreach (var alias in aliases) foreach (var alias in aliases)
{ {
await Connection.InsertAsync(alias).ConfigureAwait(false); await Connection.InsertAsync(alias, typeof(MailAccountAlias)).ConfigureAwait(false);
} }
} }
@@ -449,7 +449,7 @@ public class AccountService : BaseDatabaseService, IAccountService
AliasSenderName = remoteAlias.AliasSenderName AliasSenderName = remoteAlias.AliasSenderName
}; };
await Connection.InsertAsync(newAlias); await Connection.InsertAsync(newAlias, typeof(MailAccountAlias));
localAliases.Add(newAlias); localAliases.Add(newAlias);
} }
else else
@@ -460,7 +460,7 @@ public class AccountService : BaseDatabaseService, IAccountService
existingAlias.ReplyToAddress = remoteAlias.ReplyToAddress; existingAlias.ReplyToAddress = remoteAlias.ReplyToAddress;
existingAlias.AliasSenderName = remoteAlias.AliasSenderName; existingAlias.AliasSenderName = remoteAlias.AliasSenderName;
await Connection.UpdateAsync(existingAlias); await Connection.UpdateAsync(existingAlias, typeof(MailAccountAlias));
} }
} }
@@ -476,7 +476,7 @@ public class AccountService : BaseDatabaseService, IAccountService
var idealPrimaryAlias = localAliases.Find(a => a.AliasAddress == account.Address) ?? localAliases.First(); var idealPrimaryAlias = localAliases.Find(a => a.AliasAddress == account.Address) ?? localAliases.First();
idealPrimaryAlias.IsPrimary = true; idealPrimaryAlias.IsPrimary = true;
await Connection.UpdateAsync(idealPrimaryAlias).ConfigureAwait(false); await Connection.UpdateAsync(idealPrimaryAlias, typeof(MailAccountAlias)).ConfigureAwait(false);
} }
if (shouldUpdateRoot) if (shouldUpdateRoot)
@@ -486,7 +486,7 @@ public class AccountService : BaseDatabaseService, IAccountService
var idealRootAlias = localAliases.Find(a => a.AliasAddress == account.Address) ?? localAliases.First(); var idealRootAlias = localAliases.Find(a => a.AliasAddress == account.Address) ?? localAliases.First();
idealRootAlias.IsRootAlias = true; idealRootAlias.IsRootAlias = true;
await Connection.UpdateAsync(idealRootAlias).ConfigureAwait(false); await Connection.UpdateAsync(idealRootAlias, typeof(MailAccountAlias)).ConfigureAwait(false);
} }
} }
@@ -519,7 +519,7 @@ public class AccountService : BaseDatabaseService, IAccountService
account.Order = accountCount; account.Order = accountCount;
} }
await Connection.InsertAsync(account); await Connection.InsertAsync(account, typeof(MailAccount));
var preferences = new MailAccountPreferences() var preferences = new MailAccountPreferences()
{ {
@@ -552,10 +552,10 @@ public class AccountService : BaseDatabaseService, IAccountService
account.Preferences.SignatureIdForFollowingMessages = defaultSignature.Id; account.Preferences.SignatureIdForFollowingMessages = defaultSignature.Id;
account.Preferences.IsSignatureEnabled = true; account.Preferences.IsSignatureEnabled = true;
await Connection.InsertAsync(preferences); await Connection.InsertAsync(preferences, typeof(MailAccountPreferences));
if (customServerInformation != null) if (customServerInformation != null)
await Connection.InsertAsync(customServerInformation); await Connection.InsertAsync(customServerInformation, typeof(CustomServerInformation));
} }
//public async Task<string> UpdateSynchronizationIdentifierAsync(Guid accountId, string newIdentifier) //public async Task<string> UpdateSynchronizationIdentifierAsync(Guid accountId, string newIdentifier)
@@ -600,7 +600,7 @@ public class AccountService : BaseDatabaseService, IAccountService
account.Order = pair.Value; account.Order = pair.Value;
await Connection.UpdateAsync(account); await Connection.UpdateAsync(account, typeof(MailAccount));
} }
Messenger.Send(new AccountMenuItemsReordered(accountIdOrderPair)); Messenger.Send(new AccountMenuItemsReordered(accountIdOrderPair));
+6 -6
View File
@@ -29,14 +29,14 @@ public class CalendarService : BaseDatabaseService, ICalendarService
public async Task InsertAccountCalendarAsync(AccountCalendar accountCalendar) public async Task InsertAccountCalendarAsync(AccountCalendar accountCalendar)
{ {
await Connection.InsertAsync(accountCalendar); await Connection.InsertAsync(accountCalendar, typeof(AccountCalendar));
WeakReferenceMessenger.Default.Send(new CalendarListAdded(accountCalendar)); WeakReferenceMessenger.Default.Send(new CalendarListAdded(accountCalendar));
} }
public async Task UpdateAccountCalendarAsync(AccountCalendar accountCalendar) public async Task UpdateAccountCalendarAsync(AccountCalendar accountCalendar)
{ {
await Connection.UpdateAsync(accountCalendar); await Connection.UpdateAsync(accountCalendar, typeof(AccountCalendar));
WeakReferenceMessenger.Default.Send(new CalendarListUpdated(accountCalendar)); WeakReferenceMessenger.Default.Send(new CalendarListUpdated(accountCalendar));
} }
@@ -51,7 +51,7 @@ public class CalendarService : BaseDatabaseService, ICalendarService
var rawQuery = deleteCalendarItemsQuery.GetRawQuery(); var rawQuery = deleteCalendarItemsQuery.GetRawQuery();
await Connection.ExecuteAsync(rawQuery); await Connection.ExecuteAsync(rawQuery);
await Connection.DeleteAsync(accountCalendar); await Connection.DeleteAsync<AccountCalendar>(accountCalendar);
WeakReferenceMessenger.Default.Send(new CalendarListDeleted(accountCalendar)); WeakReferenceMessenger.Default.Send(new CalendarListDeleted(accountCalendar));
} }
@@ -85,11 +85,11 @@ public class CalendarService : BaseDatabaseService, ICalendarService
{ {
await Connection.RunInTransactionAsync((conn) => await Connection.RunInTransactionAsync((conn) =>
{ {
conn.Insert(calendarItem); conn.Insert(calendarItem, typeof(CalendarItem));
if (attendees != null) if (attendees != null)
{ {
conn.InsertAll(attendees); conn.InsertAll(attendees, typeof(CalendarEventAttendee));
} }
}); });
@@ -236,7 +236,7 @@ public class CalendarService : BaseDatabaseService, ICalendarService
connection.Execute(query.GetRawQuery()); connection.Execute(query.GetRawQuery());
// Insert new attendees. // Insert new attendees.
connection.InsertAll(allAttendees); connection.InsertAll(allAttendees, typeof(CalendarEventAttendee));
}); });
return await Connection.Table<CalendarEventAttendee>().Where(a => a.CalendarItemId == calendarItemId).ToListAsync(); return await Connection.Table<CalendarEventAttendee>().Where(a => a.CalendarItemId == calendarItemId).ToListAsync();
+5 -5
View File
@@ -19,7 +19,7 @@ public class ContactService : BaseDatabaseService, IContactService
{ {
var contact = new AccountContact() { Address = address, Name = displayName }; var contact = new AccountContact() { Address = address, Name = displayName };
await Connection.InsertAsync(contact).ConfigureAwait(false); await Connection.InsertAsync(contact, typeof(AccountContact)).ConfigureAwait(false);
return contact; return contact;
} }
@@ -57,11 +57,11 @@ public class ContactService : BaseDatabaseService, IContactService
{ {
if (currentContact == null) if (currentContact == null)
{ {
await Connection.InsertAsync(info).ConfigureAwait(false); await Connection.InsertAsync(info, typeof(AccountContact)).ConfigureAwait(false);
} }
else if (!currentContact.IsRootContact && !currentContact.IsOverridden) // Don't update root contacts or overridden contacts. else if (!currentContact.IsRootContact && !currentContact.IsOverridden) // Don't update root contacts or overridden contacts.
{ {
await Connection.InsertOrReplaceAsync(info).ConfigureAwait(false); await Connection.InsertOrReplaceAsync(info, typeof(AccountContact)).ConfigureAwait(false);
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -95,7 +95,7 @@ public class ContactService : BaseDatabaseService, IContactService
// Mark the contact as overridden when manually updated // Mark the contact as overridden when manually updated
contact.IsOverridden = true; contact.IsOverridden = true;
await Connection.UpdateAsync(contact).ConfigureAwait(false); await Connection.UpdateAsync(contact, typeof(AccountContact)).ConfigureAwait(false);
return contact; return contact;
} }
@@ -106,7 +106,7 @@ public class ContactService : BaseDatabaseService, IContactService
if (contact != null && !contact.IsRootContact) if (contact != null && !contact.IsRootContact)
{ {
await Connection.DeleteAsync(contact).ConfigureAwait(false); await Connection.DeleteAsync<AccountContact>(contact).ConfigureAwait(false);
} }
} }
+13 -12
View File
@@ -47,18 +47,19 @@ public class DatabaseService : IDatabaseService
// typeof(CalendarEventAttendee), // typeof(CalendarEventAttendee),
// typeof(CalendarItem), // typeof(CalendarItem),
// typeof(Reminder), // typeof(Reminder),
await Connection.CreateTablesAsync(CreateFlags.None,
typeof(MailCopy), await Task.WhenAll(
typeof(MailItemFolder), Connection.CreateTableAsync<MailCopy>(),
typeof(MailAccount), Connection.CreateTableAsync<MailItemFolder>(),
typeof(AccountContact), Connection.CreateTableAsync<MailAccount>(),
typeof(CustomServerInformation), Connection.CreateTableAsync<AccountContact>(),
typeof(AccountSignature), Connection.CreateTableAsync<CustomServerInformation>(),
typeof(MergedInbox), Connection.CreateTableAsync<AccountSignature>(),
typeof(MailAccountPreferences), Connection.CreateTableAsync<MergedInbox>(),
typeof(MailAccountAlias), Connection.CreateTableAsync<MailAccountPreferences>(),
typeof(Thumbnail), Connection.CreateTableAsync<MailAccountAlias>(),
typeof(KeyboardShortcut) Connection.CreateTableAsync<Thumbnail>(),
Connection.CreateTableAsync<KeyboardShortcut>()
); );
} }
} }
+3 -3
View File
@@ -452,7 +452,7 @@ public class FolderService : BaseDatabaseService, IFolderService
{ {
_logger.Debug("Inserting folder {Id} - {FolderName}", folder.Id, folder.FolderName, folder.MailAccountId); _logger.Debug("Inserting folder {Id} - {FolderName}", folder.Id, folder.FolderName, folder.MailAccountId);
await Connection.InsertAsync(folder).ConfigureAwait(false); await Connection.InsertAsync(folder, typeof(MailItemFolder)).ConfigureAwait(false);
} }
else else
{ {
@@ -483,7 +483,7 @@ public class FolderService : BaseDatabaseService, IFolderService
_logger.Debug("Updating folder {FolderName}", folder.Id, folder.FolderName); _logger.Debug("Updating folder {FolderName}", folder.Id, folder.FolderName);
await Connection.UpdateAsync(folder).ConfigureAwait(false); await Connection.UpdateAsync(folder, typeof(MailItemFolder)).ConfigureAwait(false);
} }
private async Task DeleteFolderAsync(MailItemFolder folder) private async Task DeleteFolderAsync(MailItemFolder folder)
@@ -504,7 +504,7 @@ public class FolderService : BaseDatabaseService, IFolderService
_logger.Debug("Deleting folder {FolderName}", folder.FolderName); _logger.Debug("Deleting folder {FolderName}", folder.FolderName);
await Connection.DeleteAsync(folder).ConfigureAwait(false); await Connection.DeleteAsync<MailItemFolder>(folder).ConfigureAwait(false);
// Delete all existing mails from this folder. // Delete all existing mails from this folder.
await Connection.ExecuteAsync("DELETE FROM MailCopy WHERE FolderId = ?", folder.Id); await Connection.ExecuteAsync("DELETE FROM MailCopy WHERE FolderId = ?", folder.Id);
+2 -2
View File
@@ -51,11 +51,11 @@ public class KeyboardShortcutService : BaseDatabaseService, IKeyboardShortcutSer
{ {
shortcut.Id = Guid.NewGuid(); shortcut.Id = Guid.NewGuid();
shortcut.CreatedAt = DateTime.UtcNow; shortcut.CreatedAt = DateTime.UtcNow;
await Connection.InsertAsync(shortcut); await Connection.InsertAsync(shortcut, typeof(KeyboardShortcut));
} }
else else
{ {
await Connection.UpdateAsync(shortcut); await Connection.UpdateAsync(shortcut, typeof(KeyboardShortcut));
} }
return shortcut; return shortcut;
+4 -4
View File
@@ -99,7 +99,7 @@ public class MailService : BaseDatabaseService, IMailService
copy.ThreadId = draftCreationOptions.ReferencedMessage.MailCopy.ThreadId; copy.ThreadId = draftCreationOptions.ReferencedMessage.MailCopy.ThreadId;
} }
await Connection.InsertAsync(copy); await Connection.InsertAsync(copy, typeof(MailCopy));
await _mimeFileService.SaveMimeMessageAsync(copy.FileId, createdDraftMimeMessage, composerAccount.Id); await _mimeFileService.SaveMimeMessageAsync(copy.FileId, createdDraftMimeMessage, composerAccount.Id);
@@ -527,7 +527,7 @@ public class MailService : BaseDatabaseService, IMailService
_logger.Debug("Inserting mail {MailCopyId} to {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName); _logger.Debug("Inserting mail {MailCopyId} to {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName);
await Connection.InsertAsync(mailCopy).ConfigureAwait(false); await Connection.InsertAsync(mailCopy, typeof(MailCopy)).ConfigureAwait(false);
ReportUIChange(new MailAddedMessage(mailCopy)); ReportUIChange(new MailAddedMessage(mailCopy));
} }
@@ -543,7 +543,7 @@ public class MailService : BaseDatabaseService, IMailService
_logger.Debug("Updating mail {MailCopyId} with Folder {FolderId}", mailCopy.Id, mailCopy.FolderId); _logger.Debug("Updating mail {MailCopyId} with Folder {FolderId}", mailCopy.Id, mailCopy.FolderId);
await Connection.UpdateAsync(mailCopy).ConfigureAwait(false); await Connection.UpdateAsync(mailCopy, typeof(MailCopy)).ConfigureAwait(false);
ReportUIChange(new MailUpdatedMessage(mailCopy)); ReportUIChange(new MailUpdatedMessage(mailCopy));
} }
@@ -559,7 +559,7 @@ public class MailService : BaseDatabaseService, IMailService
_logger.Debug("Deleting mail {Id} from folder {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName); _logger.Debug("Deleting mail {Id} from folder {FolderName}", mailCopy.Id, mailCopy.AssignedFolder.FolderName);
await Connection.DeleteAsync(mailCopy).ConfigureAwait(false); await Connection.DeleteAsync<MailCopy>(mailCopy).ConfigureAwait(false);
// If there are no more copies exists of the same mail, delete the MIME file as well. // If there are no more copies exists of the same mail, delete the MIME file as well.
var isMailExists = await IsMailExistsAsync(mailCopy.Id).ConfigureAwait(false); var isMailExists = await IsMailExistsAsync(mailCopy.Id).ConfigureAwait(false);
+4 -4
View File
@@ -20,7 +20,7 @@ public class SignatureService(IDatabaseService databaseService) : BaseDatabaseSe
public async Task<AccountSignature> CreateSignatureAsync(AccountSignature signature) public async Task<AccountSignature> CreateSignatureAsync(AccountSignature signature)
{ {
await Connection.InsertAsync(signature); await Connection.InsertAsync(signature, typeof(AccountSignature));
return signature; return signature;
} }
@@ -36,21 +36,21 @@ public class SignatureService(IDatabaseService databaseService) : BaseDatabaseSe
HtmlBody = @"<p>Sent from <a href=""https://github.com/bkaankose/Wino-Mail/"">Wino Mail</a> for Windows</p>" HtmlBody = @"<p>Sent from <a href=""https://github.com/bkaankose/Wino-Mail/"">Wino Mail</a> for Windows</p>"
}; };
await Connection.InsertAsync(defaultSignature); await Connection.InsertAsync(defaultSignature, typeof(AccountSignature));
return defaultSignature; return defaultSignature;
} }
public async Task<AccountSignature> UpdateSignatureAsync(AccountSignature signature) public async Task<AccountSignature> UpdateSignatureAsync(AccountSignature signature)
{ {
await Connection.UpdateAsync(signature); await Connection.UpdateAsync(signature, typeof(AccountSignature));
return signature; return signature;
} }
public async Task<AccountSignature> DeleteSignatureAsync(AccountSignature signature) public async Task<AccountSignature> DeleteSignatureAsync(AccountSignature signature)
{ {
await Connection.DeleteAsync(signature); await Connection.DeleteAsync<AccountSignature>(signature);
return signature; return signature;
} }