Browse Source

neon: Fix apps for different accounts not loading in account settings

pull/67/head
jld3103 2 years ago
parent
commit
c600dc36a9
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 1
      packages/neon/integration_test/screenshot_test.dart
  2. 1
      packages/neon/lib/main.dart
  3. 28
      packages/neon/lib/src/blocs/accounts.dart
  4. 2
      packages/neon/lib/src/blocs/apps.dart
  5. 30
      packages/neon/lib/src/models/account.dart
  6. 7
      packages/neon/lib/src/pages/home/home.dart
  7. 2
      packages/neon/lib/src/pages/settings/account_specific_settings.dart
  8. 4
      packages/neon/lib/src/pages/settings/settings.dart

1
packages/neon/integration_test/screenshot_test.dart

@ -119,6 +119,7 @@ Future pumpAppPage(
sharedPreferences,
globalOptions,
packageInfo,
allAppImplementations,
);
if (account != null) {
accountsBloc.addAccount(account..setupClient(packageInfo));

1
packages/neon/lib/main.dart

@ -47,6 +47,7 @@ Future main() async {
sharedPreferences,
globalOptions,
packageInfo,
allAppImplementations,
);
final pushNotificationsBloc = PushNotificationsBloc(
accountsBloc,

28
packages/neon/lib/src/blocs/accounts.dart

@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:convert';
import 'package:neon/src/blocs/apps.dart';
import 'package:neon/src/blocs/user_details.dart';
import 'package:neon/src/blocs/user_status.dart';
import 'package:neon/src/models/account.dart';
@ -32,6 +33,7 @@ class AccountsBloc extends $AccountsBloc {
this._sharedPreferences,
this._globalOptions,
this._packageInfo,
this._allAppImplementations,
) {
_accountsSubject.listen((final accounts) async {
_globalOptions.updateAccounts(accounts);
@ -118,30 +120,34 @@ class AccountsBloc extends $AccountsBloc {
}
}
AccountSpecificOptions? getOptions([Account? account]) {
account ??= _activeAccountSubject.valueOrNull;
if (account != null) {
final accountID = account.id;
if (_accountsOptions[accountID] != null) {
return _accountsOptions[accountID];
}
AccountSpecificOptions getOptions(final Account account) => _accountsOptions[account.id] ??= AccountSpecificOptions(
Storage('accounts-${account.id}', _sharedPreferences),
getAppsBloc(account),
);
return _accountsOptions[accountID] =
AccountSpecificOptions(Storage('accounts-${account.id}', _sharedPreferences));
AppsBloc getAppsBloc(final Account account) {
if (_accountsAppsBlocs[account.id] != null) {
return _accountsAppsBlocs[account.id]!;
}
return null;
return AppsBloc(
_requestManager,
this,
account,
_allAppImplementations,
);
}
final RequestManager _requestManager;
final Storage _storage;
final SharedPreferences _sharedPreferences;
final GlobalOptions _globalOptions;
final List<AppImplementation> _allAppImplementations;
final PackageInfo _packageInfo;
final _keyAccounts = 'accounts';
final _keyLastUsedAccount = 'last-used-account';
final _accountsOptions = <String, AccountSpecificOptions>{};
final _accountsAppsBlocs = <String, AppsBloc>{};
late final _activeAccountSubject = BehaviorSubject<Account?>.seeded(null);
late final _accountsSubject = BehaviorSubject<List<Account>>.seeded([]);
String? pushNotificationApp;

2
packages/neon/lib/src/blocs/apps.dart

@ -66,7 +66,7 @@ class AppsBloc extends $AppsBloc {
setActiveApp(_accountsBloc.pushNotificationApp);
_accountsBloc.pushNotificationApp = null;
} else {
final options = _accountsBloc.getOptions(_account)!..updateApps(appImplementations);
final options = _accountsBloc.getOptions(_account);
unawaited(
options.initialApp.stream.first.then((var initialApp) {
if (initialApp == null) {

30
packages/neon/lib/src/models/account.dart

@ -4,6 +4,7 @@ import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/blocs/apps.dart';
import 'package:neon/src/neon.dart';
import 'package:nextcloud/nextcloud.dart';
import 'package:package_info_plus/package_info_plus.dart';
@ -88,27 +89,30 @@ extension NextcloudClientHelpers on NextcloudClient {
}
class AccountSpecificOptions {
AccountSpecificOptions(this._storage);
AccountSpecificOptions(
this._storage,
this._appsBloc,
) {
_appsBloc.appImplementations.listen((final result) {
if (result.data != null) {
_appIDsSubject.add({
null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic,
for (final app in result.data!) ...{
app.id: app.name,
},
});
}
});
}
final Storage _storage;
final AppsBloc _appsBloc;
final _appIDsSubject = BehaviorSubject<Map<String?, LabelBuilder>>();
late final List<Option> options = [
initialApp,
];
void updateApps(final List<AppImplementation> apps) {
if (apps.isEmpty) {
return;
}
_appIDsSubject.add({
null: (final context) => AppLocalizations.of(context).accountOptionsAutomatic,
for (final app in apps) ...{
app.id: app.name,
},
});
}
Future reset() async {
for (final option in options) {
await option.reset();

7
packages/neon/lib/src/pages/home/home.dart

@ -35,6 +35,7 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
_platform = Provider.of<NeonPlatform>(context, listen: false);
_globalOptions = Provider.of<GlobalOptions>(context, listen: false);
final accountsBloc = RxBlocProvider.of<AccountsBloc>(context);
_appsBloc = accountsBloc.getAppsBloc(widget.account);
if (_platform.canUseSystemTray) {
tray.trayManager.addListener(this);
@ -94,12 +95,6 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
}
}
});
_appsBloc = AppsBloc(
_requestManager,
accountsBloc,
widget.account,
Provider.of<List<AppImplementation>>(context, listen: false),
);
WidgetsBinding.instance.addPostFrameCallback((final _) async {
final appImplementations = Provider.of<List<AppImplementation>>(context, listen: false);

2
packages/neon/lib/src/pages/settings/account_specific_settings.dart

@ -10,7 +10,7 @@ class AccountSpecificSettingsPage extends StatelessWidget {
final AccountsBloc bloc;
final Account account;
late final _options = bloc.getOptions(account)!;
late final _options = bloc.getOptions(account);
late final _userDetailsBloc = bloc.getUserDetailsBloc(account);
late final _name = account.client.humanReadableID;

4
packages/neon/lib/src/pages/settings/settings.dart

@ -30,7 +30,7 @@ class _SettingsPageState extends State<SettingsPage> {
}
for (final account in accountsBloc.accounts.value) {
await accountsBloc.getOptions(account)!.reset();
await accountsBloc.getOptions(account).reset();
}
}
},
@ -52,7 +52,7 @@ class _SettingsPageState extends State<SettingsPage> {
accountSpecificOptions: {
if (accountsSnapshot.hasData) ...{
for (final account in accountsSnapshot.data!) ...{
account: accountsBloc.getOptions(account)!.options,
account: accountsBloc.getOptions(account).options,
},
},
},

Loading…
Cancel
Save