Skip to content

Commit

Permalink
General Updates (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Sep 22, 2024
2 parents 5d50337 + 0efdd16 commit d3e1c1c
Show file tree
Hide file tree
Showing 39 changed files with 1,353 additions and 962 deletions.
28 changes: 25 additions & 3 deletions lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,31 @@ class API {
);
}

server.devices
..clear()
..addAll(devices);
for (final device in devices) {
// If the device is repeated, do noting.
if (server.devices.contains(device)) {
continue;
} else
// If there is already a device with the same id, merge the two devices.
// Merging is made to ensure that some properties, such as volume and
// matrix type, for example, are restored properly for each device.
if (server.devices.any((d) => d.id == device.id)) {
final index = server.devices.indexWhere((d) => d.id == device.id);
server.devices[index] = server.devices[index].merge(device);
}
// If the device has never been seen, add it
else {
server.devices.add(device);
}
}

// If a device which id is not in the devices list, remove it.
server.devices.removeWhere((device) {
return !devices.any((d) {
return d.id == device.id;
});
});

return devices;
} catch (error, stack) {
handleError(error, stack, 'Failed to get devices on server $server');
Expand Down
14 changes: 10 additions & 4 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"addServer": "Add Server",
"settings": "Settings",
"noServersAdded": "You haven't added any servers yet :/",
"howToAddServer": "Go to the \"Add Server\" screen to add a server.",
"howToAddServer": "Go to the \"Add Server\" tab to add a server.",
"editServerInfo": "Edit server info",
"editServer": "Edit server {serverName}",
"@editServer": {
Expand Down Expand Up @@ -265,7 +265,7 @@
"layoutName": "Layout name",
"layoutNameHint": "First floor",
"layoutTypeLabel": "Layout type",
"clearLayout": "Clear {amount} devices",
"clearLayout": "Remove {amount} {amount, plural, =1{device} other{devices}}",
"@clearLayout": {
"placeholders": {
"amount": {
Expand All @@ -292,7 +292,7 @@
}
}
},
"howToDownload": "Go to the \"Events History\" screen to download events.",
"howToDownload": "Go to the \"Events History\" tab to download events.",
"downloadTitle": "{event} on {device} ({server}) at {date}",
"@downloadTitle": {
"placeholders": {
Expand Down Expand Up @@ -349,7 +349,7 @@
"toDate": "To",
"today": "Today",
"yesterday": "Yesterday",
"never": "never",
"never": "Never",
"fromToDate": "From {from} to {to}",
"@fromToDate": {
"placeholders": {
Expand Down Expand Up @@ -636,6 +636,12 @@
"devicesSettings": "Devices Settings",
"listOfflineDevices": "List Offline Devices",
"listOfflineDevicesDescriptions": "Whether to show offline devices in the devices list.",
"initialDeviceVolume": "Initial Camera Volume",
"runVideoTest": "Run Video Test",
"runVideoTestDescription": "Run a video test to check the state of video playback.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Date and Language",
"language": "Language",
Expand Down
6 changes: 6 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,12 @@
"devicesSettings": "Paramètres d'appareils",
"listOfflineDevices": "Lister les appareils hors ligne",
"listOfflineDevicesDescriptions": "Afficher ou non les appareils hors ligne dans la liste des appareils.",
"initialDeviceVolume": "Initial Camera Volume",
"runVideoTest": "Run Video Test",
"runVideoTestDescription": "Run a video test to check the state of video playback.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Date et Langue",
"language": "Langue",
Expand Down
6 changes: 6 additions & 0 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@
"devicesSettings": "Devices Settings",
"listOfflineDevices": "List Offline Devices",
"listOfflineDevicesDescriptions": "Whether to show offline devices in the devices list.",
"initialDeviceVolume": "Initial Camera Volume",
"runVideoTest": "Run Video Test",
"runVideoTestDescription": "Run a video test to check the state of video playback.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Date and Language",
"language": "Language",
Expand Down
8 changes: 7 additions & 1 deletion lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"layoutName": "Nome do layout",
"layoutNameHint": "Primeiro andar",
"layoutTypeLabel": "Tipo do layout",
"clearLayout": "Limpar {amount} câmeras",
"clearLayout": "Remover {amount} {amount, plural, =1{câmera} other{câmeras}}",
"@clearLayout": {
"placeholders": {
"amount": {
Expand Down Expand Up @@ -636,6 +636,12 @@
"devicesSettings": "Configurações de Dispositivos",
"listOfflineDevices": "Listar Dispositivos Offline",
"listOfflineDevicesDescriptions": "Se deve mostrar dispositivos offline na lista de dispositivos.",
"initialDeviceVolume": "Volume Inicial da Câmera",
"runVideoTest": "Testar Vídeo",
"runVideoTestDescription": "Teste o vídeo para verificar o estado da reprodução de vídeo.",
"showCameraName": "Show Camera Name",
"always": "Always",
"onHover": "On hover",
"@@LOCALIZATION": {},
"dateLanguage": "Data e Idioma",
"language": "Idioma",
Expand Down
69 changes: 39 additions & 30 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,16 @@ Future<void> main(List<String> args) async {
}

await initializeDateFormatting();
await configureStorage();

DevHttpOverrides.configureCertificates();
API.initialize();
await UnityVideoPlayerInterface.instance.initialize();
// if (isDesktopPlatform && Platform.isLinux) {
// if (isEmbedded) {
// UnityVideoPlayerFlutterInterface.registerWith();
// } else {
// UnityVideoPlayerMediaKitInterface.registerWith();
// }
// }
debugPrint(UnityVideoPlayerInterface.instance.runtimeType.toString());
await configureStorage();

logging.writeLogToFile('Opening app with $args');
logging.writeLogToFile(
'Running on ${UnityVideoPlayerInterface.instance.runtimeType} video playback',
);

if (isDesktopPlatform && args.isNotEmpty) {
debugPrint('FOUND ANOTHER WINDOW: $args');
Expand Down Expand Up @@ -140,27 +135,18 @@ Future<void> main(List<String> args) async {

break;
}
} catch (error, stack) {
debugPrint('error: $error');
debugPrintStack(stackTrace: stack);
} catch (error, stackTrace) {
logging.handleError(
error,
stackTrace,
'Failed to open a secondary window',
);
}

return;
}
}

// Request notifications permission for iOS, Android 13+ and Windows.
//
// permission_handler only supports these platforms
if (kIsWeb || isMobilePlatform || Platform.isWindows) {
() async {
if (await Permission.notification.isDenied) {
final state = await Permission.notification.request();
debugPrint('Notification permission state $state');
}
}();
}

// We use [Future.wait] to decrease startup time.
//
// With it, all these functions will be running at the same time, reducing the
Expand All @@ -176,15 +162,34 @@ Future<void> main(List<String> args) async {
EventsProvider.ensureInitialized(),
]);

runApp(const UnityApp());

// Request notifications permission for iOS, Android 13+ and Windows.
//
// permission_handler only supports these platforms
if (kIsWeb || isMobilePlatform || Platform.isWindows) {
() async {
if (await Permission.notification.isDenied) {
final state = await Permission.notification.request();
debugPrint('Notification permission state $state');
}
}();
}

/// Firebase messaging isn't available on windows nor linux
if (!kIsWeb && isMobilePlatform) {
FirebaseConfiguration.ensureInitialized();
try {
FirebaseConfiguration.ensureInitialized();
} catch (error, stackTrace) {
logging.handleError(
error,
stackTrace,
'Error initializing firebase messaging',
);
}
}

HomeProvider.setDefaultStatusBarStyle();

runApp(const UnityApp());

app_links.register('rtsp');
app_links.register('bluecherry');
app_links.listen();
Expand Down Expand Up @@ -309,8 +314,12 @@ class _UnityAppState extends State<UnityApp>
debugPrint('Disposing player ${player.hashCode}');
try {
await player.dispose();
} catch (e) {
debugPrint('Error disposing player: $e');
} catch (error, stackTrace) {
logging.handleError(
error,
stackTrace,
'Error disposing player $player',
);
}
}
});
Expand Down
70 changes: 53 additions & 17 deletions lib/models/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ class Device {
/// The external device data.
final ExternalDeviceData? externalData;

/// The volume of this device.
///
/// This volume is restored every time the app opens and is applied to the
/// respective video player.
double volume = defaultVolume;
static double get defaultVolume =>
SettingsProvider.instance.kInitialDevicesVolume.value;

/// Creates a device.
Device({
required this.name,
Expand Down Expand Up @@ -332,7 +340,8 @@ class Device {
matrixType.hashCode ^
overlays.hashCode ^
preferredStreamingType.hashCode ^
externalData.hashCode;
externalData.hashCode ^
volume.hashCode;
}

Device copyWith({
Expand All @@ -348,22 +357,24 @@ class Device {
Iterable<VideoOverlay>? overlays,
StreamingType? preferredStreamingType,
ExternalDeviceData? externalData,
}) =>
Device(
name: name ?? this.name,
id: id ?? this.id,
status: status ?? this.status,
resolutionX: resolutionX ?? this.resolutionX,
resolutionY: resolutionY ?? this.resolutionY,
server: server ?? this.server,
hasPTZ: hasPTZ ?? this.hasPTZ,
url: url ?? this.url,
matrixType: matrixType ?? this.matrixType,
overlays: overlays ?? this.overlays,
preferredStreamingType:
preferredStreamingType ?? this.preferredStreamingType,
externalData: externalData ?? this.externalData,
);
double? volume,
}) {
return Device(
name: name ?? this.name,
id: id ?? this.id,
status: status ?? this.status,
resolutionX: resolutionX ?? this.resolutionX,
resolutionY: resolutionY ?? this.resolutionY,
server: server ?? this.server,
hasPTZ: hasPTZ ?? this.hasPTZ,
url: url ?? this.url,
matrixType: matrixType ?? this.matrixType,
overlays: overlays ?? this.overlays,
preferredStreamingType:
preferredStreamingType ?? this.preferredStreamingType,
externalData: externalData ?? this.externalData,
)..volume = volume ?? this.volume;
}

Map<String, dynamic> toJson() {
return {
Expand All @@ -379,6 +390,7 @@ class Device {
'overlays': overlays.map((e) => e.toMap()).toList(),
'preferredStreamingType': preferredStreamingType?.name,
'externalData': externalData?.toMap(),
'volume': volume,
};
}

Expand Down Expand Up @@ -407,6 +419,30 @@ class Device {
externalData: json['externalData'] != null
? ExternalDeviceData.fromMap(json['externalData'])
: null,
)..volume = json['volume'] is double
? json['volume']
: json['volume'] is String
? double.tryParse(json['volume']) ?? defaultVolume
: defaultVolume;
}

Device merge(Device? other) {
if (other == null) return this;

return copyWith(
externalData: other.externalData,
hasPTZ: hasPTZ,
id: other.id,
matrixType: other.matrixType,
name: other.name,
overlays: other.overlays,
preferredStreamingType: other.preferredStreamingType,
resolutionX: other.resolutionX,
resolutionY: other.resolutionY,
server: other.server,
status: other.status,
url: other.url,
volume: other.volume,
);
}
}
4 changes: 3 additions & 1 deletion lib/models/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class Event {
this.category,
this.mediaID,
this.mediaURL,
}) : server = server ?? ServersProvider.instance.servers.first,
}) : server = server ??
ServersProvider.instance.servers.elementAtOrNull(0) ??
Server.dump(),
publishedRaw =
publishedRaw ?? DateTimeExtension.now().toIso8601String(),
published = published ?? DateTimeExtension.now(),
Expand Down
Loading

0 comments on commit d3e1c1c

Please sign in to comment.