Repository navigation
Add multi-account support - #143
Open
justin13888 wants to merge 11 commits into
Open
justin13888 wants to merge 11 commits into
justin13888 wants to merge 11 commits into
Conversation
Replace the single "UserSession" keychain item with one item per account
("session.<storeID>"), managed by a new AccountStore. Display order and the
active account are kept in UserDefaults; the keychain stays the source of
truth for which accounts exist.
Existing sessions are migrated on launch. The new item is written and read
back before the legacy item is deleted, so an interrupted migration is
retried safely, and an unreadable legacy item is left untouched. Store
directories are already keyed by storeID, so no files move.
Signing out now removes only that account's item instead of every item in
the app's keychain service. The SDK session delegate reads and writes the
client's own item, so token refreshes can't overwrite another account.
Also removes the unused MatrixClientSessionDelegate.
When the server ends a session, stop that client's sync and show a "You were signed out" banner in the sidebar instead of dropping the client immediately. Previously the stale session stayed in the keychain and was restored again on the next launch. Every login attempt creates a store directory before the user signs in, and abandoned attempts left those directories behind. On launch, remove UUID-named store directories that belong to no account and are more than ten minutes old. The sweep is skipped while an unmigrated legacy session exists, and it keeps the stores of sessions that can't be decoded. Store path helpers move to StoreDirectories.
AppState now holds every signed-in account and which one is active. `matrixClient` returns the active account, so existing views are unchanged. All accounts are restored at launch and keep syncing in the background. An account that fails to restore is skipped instead of blocking the others. Signing in adds an account rather than replacing the current one. Signing in to an account that's already listed is rejected, and the new session is signed out again so it doesn't linger as an extra device. If the listed account was signed out by the server, the new session replaces it in the same position. Each window remembers the selected room and space per account and restores them when switching back. Window state saved by earlier versions has no account and is adopted by the first account shown, so existing windows reopen on the same room. Signing out of one account no longer quits the app when others remain.
A menu at the top of the sidebar shows the active account. It lists every account with its unread count, and has Add Account and Sign Out (with a confirmation). A new Account menu in the menu bar lists accounts with Command-Control-1 through 9 and also offers Add Account. The sign-in sheet now knows why it's shown. When adding an account it has a Cancel button. When an account was signed out by the server, the banner offers Sign In Again, which opens the sheet pre-filled with that user ID and replaces the old session in place. It also offers Remove Account. The Account and Sessions settings tabs show which account they apply to. MatrixClient loads its own display name and avatar for these labels.
The notification center has a single delegate, but every account's MatrixNotifications set itself as that delegate, so only the last account could handle clicks. A NotificationRouter owned by AppState now handles clicks for all accounts. Notifications carry the receiving account's storeID and are grouped by account. When more than one account is signed in, the subtitle names the account. Clicking a notification switches to its account and opens the room. A click that launches the app is held until accounts are restored. The Dock badge shows unread rooms summed across all accounts. AppState is now its only writer; previously each client overwrote the others' count. Logs for sync, sign-out, auth errors and session saves now include the account's storeID, so logs from different accounts can be told apart.
A login client can only sign in once. After a rejected duplicate sign-in, the Add Account sheet reused the spent client, so signing in as another account on the same homeserver failed with "new logged-in session is different than current client session". Fetch new login details after every failed attempt.
The sidebar switcher was a native menu, which drops custom labels, so it showed only the display name without an avatar. Display names aren't unique either. Replace it with a button that opens a popover listing each account's avatar, display name, and Matrix ID, with the active account checked and unread counts or a signed-out tag. The Account menu now titles items "Name — @user:server".
The SDK sizes each store's connection pool at four connections per CPU
core, and every connection holds two file descriptors. With four
databases per account, two accounts on a 12-core Mac held over 300
descriptors, past the default limit of 256. Further sign-in attempts,
which each build a client with its own store, then failed to open
databases ("unable to open database file") or sockets, stalled syncing
accounts, and crashed when AppKit could not create a Metal context.
Limit each pool to 8 connections, about 64 descriptors per account.
Apps start with a soft limit of 256 open files. Every signed-in account keeps its SQLite stores and sync connections open, and each sign-in attempt opens another store, so a few accounts can run out even with capped connection pools. Raise the soft limit to 4096 (or the hard limit, if lower) before any account opens its stores.
macOS hides notifications from the frontmost app unless its delegate asks to present them, so while Mactrix was focused nothing showed that another account had received a message. Present those with a banner and sound. The active account stays silent as before, since its rooms are already in the sidebar.
Unread rooms in inactive accounts were only visible after opening the switcher popover. Show their total next to the switcher's chevron and include it in the button's accessibility label. Signed-out accounts are left out, matching the popover, which marks them instead of counting.
justin13888
marked this pull request as ready for review
November 23, 2026 23:01
Author
|
Finally verified all the individual checks on checklist one-by-one. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets Mactrix stay signed in to several Matrix accounts at once. One account is active app-wide; every account keeps syncing in the background so notifications and the Dock badge cover all of them.
Built as 7 self-contained commits that each build and pass tests, so it can be reviewed commit by commit:
AccountStorereplaces the singleUserSessionitem withsession.<storeID>items, plus a crash-safe migration of the existing session. Sign-out no longer wipes the whole keychain service.AppState.accounts+ active account (matrixClientstays as an alias, so views are untouched); duplicate sign-ins are rejected; per-account room selection per window.Migration
storeID, so no files move.Testing
xcodebuild testpasses on every commit (184 tests; new:AccountStoreTests,StoreDirectoriesTests,WindowStateAccountTests).build analyzeis clean.mainkeeps the existing session and selected roomNot covered