Browse Source

Merge pull request #101 from jld3103/refactor/server-status

neon: Refactor server status handling
pull/102/head
jld3103 2 years ago committed by GitHub
parent
commit
92818e713a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/neon/lib/src/neon.dart
  2. 36
      packages/neon/lib/src/pages/home/home.dart
  3. 35
      packages/neon/lib/src/pages/home/widgets/server_status.dart

1
packages/neon/lib/src/neon.dart

@ -57,7 +57,6 @@ import 'package:xdg_directories/xdg_directories.dart' as xdg;
part 'app.dart'; part 'app.dart';
part 'pages/home/home.dart'; part 'pages/home/home.dart';
part 'pages/home/widgets/server_status.dart';
part 'pages/login/login.dart'; part 'pages/login/login.dart';
part 'pages/settings/account_specific_settings.dart'; part 'pages/settings/account_specific_settings.dart';
part 'pages/settings/nextcloud_app_specific_settings.dart'; part 'pages/settings/nextcloud_app_specific_settings.dart';

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

@ -65,10 +65,12 @@ class _HomePageState extends State<HomePage> {
if (!mounted) { if (!mounted) {
return; return;
} }
await _showUnsupportedVersion( await _showProblem(
id == 'core' AppLocalizations.of(context).errorUnsupportedVersion(
? AppLocalizations.of(context).coreName id == 'core'
: appsResult.data!.singleWhere((final a) => a.id == id).name(context), ? AppLocalizations.of(context).coreName
: appsResult.data!.singleWhere((final a) => a.id == id).name(context),
),
); );
} }
} catch (e, s) { } catch (e, s) {
@ -81,13 +83,32 @@ class _HomePageState extends State<HomePage> {
} }
} }
}); });
unawaited(_checkMaintenanceMode());
}
Future _checkMaintenanceMode() async {
try {
final status = await widget.account.client.core.getStatus();
if (status.maintenance) {
if (!mounted) {
return;
}
await _showProblem(
AppLocalizations.of(context).errorServerInMaintenanceMode,
);
}
} catch (e) {
debugPrint(e.toString());
ExceptionWidget.showSnackbar(context, e);
}
} }
Future _showUnsupportedVersion(final String appName) async { Future _showProblem(final String title) async {
await showDialog( await showDialog(
context: context, context: context,
builder: (final context) => AlertDialog( builder: (final context) => AlertDialog(
title: Text(AppLocalizations.of(context).errorUnsupportedVersion(appName)), title: Text(title),
actions: [ actions: [
ElevatedButton( ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
@ -508,9 +529,6 @@ class _HomePageState extends State<HomePage> {
Expanded( Expanded(
child: Column( child: Column(
children: [ children: [
ServerStatus(
account: widget.account,
),
ExceptionWidget( ExceptionWidget(
appsError, appsError,
onRetry: () { onRetry: () {

35
packages/neon/lib/src/pages/home/widgets/server_status.dart

@ -1,35 +0,0 @@
part of '../../../neon.dart';
class ServerStatus extends StatefulWidget {
const ServerStatus({
required this.account,
super.key,
});
final Account account;
@override
State<ServerStatus> createState() => _ServerStatusState();
}
class _ServerStatusState extends State<ServerStatus> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((final _) async {
try {
final status = await widget.account.client.core.getStatus();
if (status.maintenance && mounted) {
ExceptionWidget.showSnackbar(context, AppLocalizations.of(context).errorServerInMaintenanceMode);
}
} catch (e) {
debugPrint(e.toString());
ExceptionWidget.showSnackbar(context, e);
}
});
}
@override
Widget build(final BuildContext context) => Container();
}
Loading…
Cancel
Save