Skip to content

Commit

Permalink
Certificates and Devices Parsing (bluecherrydvr#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Apr 23, 2024
2 parents 3697975 + 8ec08f6 commit 2af0fb2
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 43 deletions.
8 changes: 4 additions & 4 deletions lib/models/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ class Device {

factory Device.fromServerJson(Map map, Server server) {
return Device(
name: map['device_name'],
id: int.tryParse(map['id']) ?? 0,
name: map['device_name'] ?? map['device'] ?? 'Unkown Device',
id: int.tryParse('${map['id']}') ?? 0,
status: map['status'] == 'OK',
resolutionX: int.tryParse(map['resolutionX']),
resolutionY: int.tryParse(map['resolutionY']),
resolutionX: int.tryParse('${map['resolutionX']}'),
resolutionY: int.tryParse('${map['resolutionY']}'),
server: server,
hasPTZ: map['ptz_control_protocol'] != null,
);
Expand Down
13 changes: 13 additions & 0 deletions lib/providers/settings_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import 'dart:io';

import 'package:bluecherry_client/models/server.dart';
import 'package:bluecherry_client/providers/app_provider_interface.dart';
import 'package:bluecherry_client/providers/downloads_provider.dart';
import 'package:bluecherry_client/providers/update_provider.dart';
Expand Down Expand Up @@ -573,6 +574,18 @@ class SettingsProvider extends UnityProvider {
await settings.delete();
await initialize();
}

/// Check if the server certificates passes
///
/// If [kAllowUntrustedCertificates] is enabled, it will return true.
/// Otherwise, it will return the server's [Server.passedCertificates] value.
bool checkServerCertificates(Server server) {
if (kAllowUntrustedCertificates.value) {
return true;
}

return server.passedCertificates;
}
}

enum NotificationClickBehavior {
Expand Down
16 changes: 11 additions & 5 deletions lib/screens/direct_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import 'package:bluecherry_client/models/device.dart';
import 'package:bluecherry_client/models/server.dart';
import 'package:bluecherry_client/providers/server_provider.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
import 'package:bluecherry_client/utils/constants.dart';
import 'package:bluecherry_client/utils/extensions.dart';
import 'package:bluecherry_client/utils/theme.dart';
Expand Down Expand Up @@ -108,17 +109,22 @@ class _DevicesForServer extends StatelessWidget {
final theme = Theme.of(context);
final loc = AppLocalizations.of(context);
final servers = context.watch<ServersProvider>();
final settings = context.watch<SettingsProvider>();

final isLoading = servers.isServerLoading(server);

final serverIndicator = SubHeader(
server.name,
materialType: MaterialType.canvas,
subtext: !server.passedCertificates
? loc.certificateNotPassed
: server.online
? loc.nDevices(server.devices.length)
: loc.offline,
subtext: () {
if (!settings.checkServerCertificates(server)) {
return loc.certificateNotPassed;
} else if (server.online) {
return loc.nDevices(server.devices.length);
} else {
return loc.offline;
}
}(),
subtextStyle: TextStyle(
color: !server.online ? theme.colorScheme.error : null,
),
Expand Down
15 changes: 10 additions & 5 deletions lib/screens/events_browser/events_screen_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class _EventsScreenMobileState extends State<EventsScreenMobile> {
final theme = Theme.of(context);
final servers = context.watch<ServersProvider>();
final loc = AppLocalizations.of(context);
final settings = context.watch<SettingsProvider>();

final isLoading = context.watch<HomeProvider>().isLoadingFor(
UnityLoadingReason.fetchingEventsHistory,
Expand Down Expand Up @@ -137,11 +138,15 @@ class _EventsScreenMobileState extends State<EventsScreenMobile> {
style: const TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(
!server.passedCertificates
? loc.certificateNotPassed
: server.online
? loc.nEvents(serverEvents.length)
: loc.offline,
() {
if (!settings.checkServerCertificates(server)) {
return loc.certificateNotPassed;
} else if (server.online) {
return loc.nEvents(serverEvents.length);
} else {
return loc.offline;
}
}(),
),
trailing: !server.online
? Icon(
Expand Down
8 changes: 6 additions & 2 deletions lib/screens/layouts/desktop/device_info_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ class _DeviceInfoDialogState extends State<DeviceInfoDialog> {
),
),
_buildInfoTile(loc.uri, widget.device.uri),
_buildInfoTile(loc.resolution,
'${widget.device.resolutionX}x${widget.device.resolutionY}'),
_buildInfoTile(
loc.resolution,
'${widget.device.resolutionX ?? '${loc.unknown} '}'
'x'
'${widget.device.resolutionY ?? ' ${loc.unknown}'}',
),
_buildInfoTile(
loc.isPtzSupported, widget.device.hasPTZ ? loc.yes : loc.no),
_buildInfoTileWidget(
Expand Down
15 changes: 10 additions & 5 deletions lib/screens/layouts/desktop/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class _DesktopSidebarState extends State<DesktopSidebar> {

final servers = context.watch<ServersProvider>();
final view = context.watch<DesktopViewProvider>();
final settings = context.watch<SettingsProvider>();

return SafeArea(
top: false,
Expand Down Expand Up @@ -99,11 +100,15 @@ class _DesktopSidebarState extends State<DesktopSidebar> {
child: SubHeader(
server.name,
materialType: MaterialType.canvas,
subtext: !server.passedCertificates
? loc.certificateNotPassed
: server.online
? loc.nDevices(devices.length)
: loc.offline,
subtext: () {
if (!settings.checkServerCertificates(server)) {
return loc.certificateNotPassed;
} else if (server.online) {
return loc.nDevices(devices.length);
} else {
return loc.offline;
}
}(),
subtextStyle: TextStyle(
color: !server.online
? theme.colorScheme.error
Expand Down
5 changes: 2 additions & 3 deletions lib/screens/layouts/desktop/stream_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ class _StreamDataState extends State<StreamData> {

const borderSize = 4.0;

//This, basically, would
// contain all the information about this stream - and provide
// more options, such as adding/changing overlays.
// This, basically, would contain all the information about this stream -
// and provide more options, such as adding/changing overlays.
return AlertDialog(
title: RichText(
text: TextSpan(
Expand Down
37 changes: 24 additions & 13 deletions lib/screens/settings/shared/server_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,11 @@ class ServerTile extends StatelessWidget {
!isLoading
? [
if (server.name != server.ip) server.ip,
if (!server.passedCertificates)
loc.certificateNotPassed
else if (server.online)
if (server.online)
loc.nDevices(server.devices.length)
else
loc.offline,
if (!server.passedCertificates) loc.certificateNotPassed
].join(' • ')
: loc.gettingDevices,
overflow: TextOverflow.ellipsis,
Expand Down Expand Up @@ -246,6 +245,7 @@ class ServerCard extends StatelessWidget {
final loc = AppLocalizations.of(context);
final theme = Theme.of(context);
final servers = context.watch<ServersProvider>();
final settings = context.watch<SettingsProvider>();

final isLoading = servers.isServerLoading(server);

Expand Down Expand Up @@ -299,17 +299,28 @@ class ServerCard extends StatelessWidget {
style: theme.textTheme.bodySmall,
),
Text(
!server.passedCertificates
? loc.certificateNotPassed
: !server.online
? loc.offline
: !isLoading
? loc.nDevices(server.devices.length)
: '',
() {
if (!settings.checkServerCertificates(server)) {
return loc.certificateNotPassed;
} else if (!server.online) {
return loc.offline;
} else if (!isLoading) {
return loc.nDevices(server.devices.length);
}

return '';
}(),
style: TextStyle(
color: !server.online || !server.passedCertificates
? theme.colorScheme.error
: null,
color: () {
if (settings.checkServerCertificates(server)) {
return theme.colorScheme.error;
}
if (!server.online) {
return theme.colorScheme.error;
}

return null;
}(),
),
textAlign: TextAlign.center,
),
Expand Down
18 changes: 12 additions & 6 deletions lib/widgets/device_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import 'package:bluecherry_client/models/device.dart';
import 'package:bluecherry_client/providers/server_provider.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
import 'package:bluecherry_client/utils/extensions.dart';
import 'package:bluecherry_client/utils/theme.dart';
import 'package:bluecherry_client/widgets/error_warning.dart';
Expand Down Expand Up @@ -80,9 +81,10 @@ class DeviceSelector extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final servers = context.watch<ServersProvider>();
final loc = AppLocalizations.of(context);
final viewPadding = MediaQuery.viewPaddingOf(context);
final servers = context.watch<ServersProvider>();
final settings = context.watch<SettingsProvider>();

return Scaffold(
appBar: AppBar(
Expand All @@ -109,11 +111,15 @@ class DeviceSelector extends StatelessWidget {
child: SubHeader(
server.name,
materialType: MaterialType.canvas,
subtext: !server.passedCertificates
? loc.certificateNotPassed
: server.online
? loc.nDevices(server.devices.length)
: loc.offline,
subtext: () {
if (!settings.checkServerCertificates(server)) {
return loc.certificateNotPassed;
} else if (server.online) {
return loc.nDevices(server.devices.length);
} else {
return loc.offline;
}
}(),
subtextStyle: TextStyle(
color: !server.online || !server.passedCertificates
? theme.colorScheme.error
Expand Down

0 comments on commit 2af0fb2

Please sign in to comment.