Skip to content

Commit

Permalink
fix: Improve server status messages for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Oct 17, 2024
1 parent 9e126c9 commit 94c2be3
Showing 1 changed file with 75 additions and 57 deletions.
132 changes: 75 additions & 57 deletions lib/screens/settings/shared/server_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ class ServerTile extends StatelessWidget {
backgroundColor: Colors.transparent,
foregroundColor:
server.online ? theme.iconTheme.color : theme.colorScheme.error,
child:
Icon(server.online ? Icons.dns : Icons.desktop_access_disabled),
child: ServerStatusIcon(
server: server,
isLoading: isLoading,
),
),
title: Text(
server.name,
Expand Down Expand Up @@ -341,61 +343,7 @@ class ServerCard extends StatelessWidget {
start: 0,
end: 0,
child: Row(children: [
if (isLoading)
const Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: SizedBox(
height: 18.0,
width: 18.0,
child:
CircularProgressIndicator.adaptive(strokeWidth: 1.5),
),
)
else if (server.online)
Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: Tooltip(
message: 'Online',
child: Icon(Icons.check, size: 18.0, color: Colors.green),
),
)
else if (server.additionResponse ==
ServerAdditionResponse.wrongCredentials)
Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: Tooltip(
message: 'Wrong credentials',
child: Icon(
Icons.vpn_key,
size: 18.0,
color: theme.colorScheme.error,
),
),
)
else ...[
Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: Tooltip(
message: switch (server.additionResponse) {
ServerAdditionResponse.wrongCredentials =>
loc.serverWrongCredentialsShort,
ServerAdditionResponse.versionMismatch =>
loc.serverVersionMismatchShort,
_ => loc.offline,
},
child: Icon(
switch (server.additionResponse) {
ServerAdditionResponse.wrongCredentials =>
Icons.vpn_key,
ServerAdditionResponse.versionMismatch => Icons.rule,
_ => Icons.domain_disabled,
},
size: 18.0,
color: theme.colorScheme.error,
),
),
)
],
ServerStatusIcon(isLoading: isLoading, server: server),
Spacer(),
SquaredIconButton(
tooltip: loc.serverOptions,
Expand Down Expand Up @@ -522,3 +470,73 @@ class DevicesListDialog extends StatelessWidget {
);
}
}

class ServerStatusIcon extends StatelessWidget {
final bool isLoading;
final Server server;

const ServerStatusIcon({
super.key,
required this.server,
required this.isLoading,
});

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final loc = AppLocalizations.of(context);
if (isLoading) {
return const Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: SizedBox(
height: 18.0,
width: 18.0,
child: CircularProgressIndicator.adaptive(strokeWidth: 1.5),
),
);
} else if (server.online) {
return Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: Tooltip(
message: 'Online',
child: Icon(Icons.check, size: 18.0, color: Colors.green),
),
);
} else if (server.additionResponse ==
ServerAdditionResponse.wrongCredentials) {
return Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: Tooltip(
message: 'Wrong credentials',
child: Icon(
Icons.vpn_key,
size: 18.0,
color: theme.colorScheme.error,
),
),
);
} else {
return Padding(
padding: EdgeInsetsDirectional.only(start: 12.0),
child: Tooltip(
message: switch (server.additionResponse) {
ServerAdditionResponse.wrongCredentials =>
loc.serverWrongCredentialsShort,
ServerAdditionResponse.versionMismatch =>
loc.serverVersionMismatchShort,
_ => loc.offline,
},
child: Icon(
switch (server.additionResponse) {
ServerAdditionResponse.wrongCredentials => Icons.vpn_key,
ServerAdditionResponse.versionMismatch => Icons.rule,
_ => Icons.domain_disabled,
},
size: 18.0,
color: theme.colorScheme.error,
),
),
);
}
}
}

0 comments on commit 94c2be3

Please sign in to comment.