feat: sincronizar cor do tema via account data da conta Matrix

A cor escolhida no Appearance passa a ser guardada em im.fluffychat.account_config (primary_color), em vez de apenas nas preferencias locais do dispositivo.

- ApplicationAccountConfig ganha primaryColor, preservado em updateApplicationAccountConfig e no novo setApplicationAccountColor
- ThemeController restaura a cor da conta activa, aguarda accountDataLoading e reage a alteracoes remotas via onSync
- A cor final e derivada de _accountPrimaryColor ?? _localPrimaryColor, evitando corrida entre as preferencias locais e o sync
- Matrix notifica a troca de conta activa em initMatrix, setActiveClient e logout, corrigindo o indice do cliente activo
- Apagar o wallpaper preserva a cor; testes de serializacao do modelo
This commit is contained in:
2026-09-25 12:53:21 -03:00
parent 7534ecf7d1
commit 058926cf6f
6 changed files with 262 additions and 49 deletions

View File

@@ -44,10 +44,13 @@ class Matrix extends StatefulWidget {
final SharedPreferences store;
final ValueChanged<Client?>? onActiveClientChanged;
const Matrix({
this.child,
required this.clients,
required this.store,
this.onActiveClientChanged,
this.queryParameters,
super.key,
});
@@ -89,11 +92,21 @@ class MatrixState extends State<Matrix> {
final i = widget.clients.indexWhere((c) => c == cl);
if (i != -1) {
_activeClient = i;
_notifyActiveClientChanged();
} else {
Logs().w('Tried to set an unknown client ${cl!.userID} as active');
}
}
void _notifyActiveClientChanged() {
final callback = widget.onActiveClientChanged;
if (callback == null) return;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
callback(widget.clients.isEmpty ? null : client);
});
}
List<Client?>? get currentBundle {
if (!hasComplexBundles) {
return List.from(widget.clients);
@@ -256,19 +269,27 @@ class MatrixState extends State<Matrix> {
.where((state) => state == LoginState.loggedOut)
.listen((_) {
final loggedInWithMultipleClients = widget.clients.length > 1;
final activeClient = client;
final removedIndex = widget.clients.indexOf(c);
final wasActive = removedIndex != -1 && activeClient == c;
_cancelSubs(c.clientName);
widget.clients.remove(c);
ClientManager.removeClientNameFromStore(c.clientName, store);
InitWithRestoreExtension.deleteSessionBackup(name);
if (removedIndex != -1 && _activeClient > removedIndex) {
_activeClient--;
}
if (wasActive) {
_activeClient = -1;
}
if (removedIndex != -1) {
_notifyActiveClientChanged();
}
if (loggedInWithMultipleClients) {
final snackbarContext =
TatuChatApp
.router
.routerDelegate
.navigatorKey
.currentContext ??
TatuChatApp.router.routerDelegate.navigatorKey.currentContext ??
context;
if (!snackbarContext.mounted) return;
@@ -349,6 +370,7 @@ class MatrixState extends State<Matrix> {
},
);
}
_notifyActiveClientChanged();
}
void didChangeAppLifecycleState(AppLifecycleState state) {