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.DeleteAsync(mergedInbox).ConfigureAwait(false);
await Connection.DeleteAsync<MergedInbox>(mergedInbox).ConfigureAwait(false);
// Change the startup entity id if it was the merged inbox.
// Take the first account as startup account.
@@ -135,7 +135,7 @@ public class AccountService : BaseDatabaseService, IAccountService
accountFolderList.Add(folder);
folder.IsSticky = false;
await Connection.UpdateAsync(folder);
await Connection.UpdateAsync(folder, typeof(MailItemFolder));
}
accountFolderDictionary.Add(account, accountFolderList);
@@ -170,20 +170,20 @@ public class AccountService : BaseDatabaseService, IAccountService
{
folder.IsSticky = true;
await Connection.UpdateAsync(folder);
await Connection.UpdateAsync(folder, typeof(MailItemFolder));
}
}
}
}
// 3. Insert merged inbox and assign accounts.
await Connection.InsertAsync(mergedInbox);
await Connection.InsertAsync(mergedInbox, typeof(MergedInbox));
foreach (var account in accountsToMerge)
{
account.MergedInboxId = mergedInbox.Id;
await Connection.UpdateAsync(account);
await Connection.UpdateAsync(account, typeof(MailAccount));
}
WeakReferenceMessenger.Default.Send(new AccountsMenuRefreshRequested());
@@ -254,7 +254,7 @@ public class AccountService : BaseDatabaseService, IAccountService
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);
}
@@ -321,9 +321,9 @@ public class AccountService : BaseDatabaseService, IAccountService
await Connection.Table<CustomServerInformation>().DeleteAsync(a => a.AccountId == account.Id);
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);
@@ -370,7 +370,7 @@ public class AccountService : BaseDatabaseService, IAccountService
IsRootContact = true
};
await Connection.InsertOrReplaceAsync(accountContact).ConfigureAwait(false);
await Connection.InsertOrReplaceAsync(accountContact, typeof(AccountContact)).ConfigureAwait(false);
await UpdateAccountAsync(account).ConfigureAwait(false);
}
@@ -402,15 +402,15 @@ public class AccountService : BaseDatabaseService, IAccountService
public async Task UpdateAccountAsync(MailAccount account)
{
await Connection.UpdateAsync(account.Preferences).ConfigureAwait(false);
await Connection.UpdateAsync(account).ConfigureAwait(false);
await Connection.UpdateAsync(account.Preferences, typeof(MailAccountPreferences)).ConfigureAwait(false);
await Connection.UpdateAsync(account, typeof(MailAccount)).ConfigureAwait(false);
ReportUIChange(new AccountUpdatedMessage(account));
}
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)
@@ -421,7 +421,7 @@ public class AccountService : BaseDatabaseService, IAccountService
// Insert new ones.
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
};
await Connection.InsertAsync(newAlias);
await Connection.InsertAsync(newAlias, typeof(MailAccountAlias));
localAliases.Add(newAlias);
}
else
@@ -460,7 +460,7 @@ public class AccountService : BaseDatabaseService, IAccountService
existingAlias.ReplyToAddress = remoteAlias.ReplyToAddress;
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();
idealPrimaryAlias.IsPrimary = true;
await Connection.UpdateAsync(idealPrimaryAlias).ConfigureAwait(false);
await Connection.UpdateAsync(idealPrimaryAlias, typeof(MailAccountAlias)).ConfigureAwait(false);
}
if (shouldUpdateRoot)
@@ -486,7 +486,7 @@ public class AccountService : BaseDatabaseService, IAccountService
var idealRootAlias = localAliases.Find(a => a.AliasAddress == account.Address) ?? localAliases.First();
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;
}
await Connection.InsertAsync(account);
await Connection.InsertAsync(account, typeof(MailAccount));
var preferences = new MailAccountPreferences()
{
@@ -552,10 +552,10 @@ public class AccountService : BaseDatabaseService, IAccountService
account.Preferences.SignatureIdForFollowingMessages = defaultSignature.Id;
account.Preferences.IsSignatureEnabled = true;
await Connection.InsertAsync(preferences);
await Connection.InsertAsync(preferences, typeof(MailAccountPreferences));
if (customServerInformation != null)
await Connection.InsertAsync(customServerInformation);
await Connection.InsertAsync(customServerInformation, typeof(CustomServerInformation));
}
//public async Task<string> UpdateSynchronizationIdentifierAsync(Guid accountId, string newIdentifier)
@@ -600,7 +600,7 @@ public class AccountService : BaseDatabaseService, IAccountService
account.Order = pair.Value;
await Connection.UpdateAsync(account);
await Connection.UpdateAsync(account, typeof(MailAccount));
}
Messenger.Send(new AccountMenuItemsReordered(accountIdOrderPair));
+6 -6
View File
@@ -29,14 +29,14 @@ public class CalendarService : BaseDatabaseService, ICalendarService
public async Task InsertAccountCalendarAsync(AccountCalendar accountCalendar)
{
await Connection.InsertAsync(accountCalendar);
await Connection.InsertAsync(accountCalendar, typeof(AccountCalendar));
WeakReferenceMessenger.Default.Send(new CalendarListAdded(accountCalendar));
}
public async Task UpdateAccountCalendarAsync(AccountCalendar accountCalendar)
{
await Connection.UpdateAsync(accountCalendar);
await Connection.UpdateAsync(accountCalendar, typeof(AccountCalendar));
WeakReferenceMessenger.Default.Send(new CalendarListUpdated(accountCalendar));
}
@@ -51,7 +51,7 @@ public class CalendarService : BaseDatabaseService, ICalendarService
var rawQuery = deleteCalendarItemsQuery.GetRawQuery();
await Connection.ExecuteAsync(rawQuery);
await Connection.DeleteAsync(accountCalendar);
await Connection.DeleteAsync<AccountCalendar>(accountCalendar);
WeakReferenceMessenger.Default.Send(new CalendarListDeleted(accountCalendar));
}
@@ -85,11 +85,11 @@ public class CalendarService : BaseDatabaseService, ICalendarService
{
await Connection.RunInTransactionAsync((conn) =>
{
conn.Insert(calendarItem);
conn.Insert(calendarItem, typeof(CalendarItem));
if (attendees != null)
{
conn.InsertAll(attendees);
conn.InsertAll(attendees, typeof(CalendarEventAttendee));
}
});
@@ -236,7 +236,7 @@ public class CalendarService : BaseDatabaseService, ICalendarService
connection.Execute(query.GetRawQuery());
// Insert new attendees.
connection.InsertAll(allAttendees);
connection.InsertAll(allAttendees, typeof(CalendarEventAttendee));
});
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 };
await Connection.InsertAsync(contact).ConfigureAwait(false);
await Connection.InsertAsync(contact, typeof(AccountContact)).ConfigureAwait(false);
return contact;
}
@@ -57,11 +57,11 @@ public class ContactService : BaseDatabaseService, IContactService
{
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.
{
await Connection.InsertOrReplaceAsync(info).ConfigureAwait(false);
await Connection.InsertOrReplaceAsync(info, typeof(AccountContact)).ConfigureAwait(false);
}
}
catch (Exception ex)
@@ -95,7 +95,7 @@ public class ContactService : BaseDatabaseService, IContactService
// Mark the contact as overridden when manually updated
contact.IsOverridden = true;
await Connection.UpdateAsync(contact).ConfigureAwait(false);
await Connection.UpdateAsync(contact, typeof(AccountContact)).ConfigureAwait(false);
return contact;
}
@@ -106,7 +106,7 @@ public class ContactService : BaseDatabaseService, IContactService
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(CalendarItem),
// typeof(Reminder),
await Connection.CreateTablesAsync(CreateFlags.None,
typeof(MailCopy),
typeof(MailItemFolder),
typeof(MailAccount),
typeof(AccountContact),
typeof(CustomServerInformation),
typeof(AccountSignature),
typeof(MergedInbox),
typeof(MailAccountPreferences),
typeof(MailAccountAlias),
typeof(Thumbnail),
typeof(KeyboardShortcut)
await Task.WhenAll(
Connection.CreateTableAsync<MailCopy>(),
Connection.CreateTableAsync<MailItemFolder>(),
Connection.CreateTableAsync<MailAccount>(),
Connection.CreateTableAsync<AccountContact>(),
Connection.CreateTableAsync<CustomServerInformation>(),
Connection.CreateTableAsync<AccountSignature>(),
Connection.CreateTableAsync<MergedInbox>(),
Connection.CreateTableAsync<MailAccountPreferences>(),
Connection.CreateTableAsync<MailAccountAlias>(),
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);
await Connection.InsertAsync(folder).ConfigureAwait(false);
await Connection.InsertAsync(folder, typeof(MailItemFolder)).ConfigureAwait(false);
}
else
{
@@ -483,7 +483,7 @@ public class FolderService : BaseDatabaseService, IFolderService
_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)
@@ -504,7 +504,7 @@ public class FolderService : BaseDatabaseService, IFolderService
_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.
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.CreatedAt = DateTime.UtcNow;
await Connection.InsertAsync(shortcut);
await Connection.InsertAsync(shortcut, typeof(KeyboardShortcut));
}
else
{
await Connection.UpdateAsync(shortcut);
await Connection.UpdateAsync(shortcut, typeof(KeyboardShortcut));
}
return shortcut;
+4 -4
View File
@@ -99,7 +99,7 @@ public class MailService : BaseDatabaseService, IMailService
copy.ThreadId = draftCreationOptions.ReferencedMessage.MailCopy.ThreadId;
}
await Connection.InsertAsync(copy);
await Connection.InsertAsync(copy, typeof(MailCopy));
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);
await Connection.InsertAsync(mailCopy).ConfigureAwait(false);
await Connection.InsertAsync(mailCopy, typeof(MailCopy)).ConfigureAwait(false);
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);
await Connection.UpdateAsync(mailCopy).ConfigureAwait(false);
await Connection.UpdateAsync(mailCopy, typeof(MailCopy)).ConfigureAwait(false);
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);
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.
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)
{
await Connection.InsertAsync(signature);
await Connection.InsertAsync(signature, typeof(AccountSignature));
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>"
};
await Connection.InsertAsync(defaultSignature);
await Connection.InsertAsync(defaultSignature, typeof(AccountSignature));
return defaultSignature;
}
public async Task<AccountSignature> UpdateSignatureAsync(AccountSignature signature)
{
await Connection.UpdateAsync(signature);
await Connection.UpdateAsync(signature, typeof(AccountSignature));
return signature;
}
public async Task<AccountSignature> DeleteSignatureAsync(AccountSignature signature)
{
await Connection.DeleteAsync(signature);
await Connection.DeleteAsync<AccountSignature>(signature);
return signature;
}