Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fixes #309

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
41 changes: 15 additions & 26 deletions lib/providers/layouts_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class LayoutsProvider extends UnityProvider {
double? get layoutManagerHeight => _layoutManagerHeight;
set layoutManagerHeight(double? value) {
_layoutManagerHeight = value;
notifyListeners();
save();
}

Expand All @@ -89,7 +88,8 @@ class LayoutsProvider extends UnityProvider {
}

@override
Future<void> save({bool notifyListeners = true}) async {
Future<void> save({bool notifyListeners = false}) async {
this.notifyListeners();
await write({
kStorageDesktopLayouts:
jsonEncode(layouts.map((layout) => layout.toMap()).toList()),
Expand Down Expand Up @@ -161,20 +161,20 @@ class LayoutsProvider extends UnityProvider {
var previousDevice = layout.devices.firstOrNull;
if (previousDevice != null) {
layout.devices.clear();
await _releaseDevice(device);
await maybeReleaseDevice(device);
}
}

UnityPlayers.players[device.uuid] ??= UnityPlayers.forDevice(device);
layout.devices.add(device);
debugPrint('Added $device');

notifyListeners();
await save();
}
}

Future<void> _releaseDevice(Device device) async {
/// Releases the device if it's not used in any layout.
Future<void> maybeReleaseDevice(Device device) async {
if (!UnityPlayers.players.containsKey(device.uuid)) return;
if (!layouts
.any((layout) => layout.devices.any((d) => d.uuid == device.uuid))) {
Expand All @@ -188,9 +188,8 @@ class LayoutsProvider extends UnityProvider {
debugPrint('Removed $device');

currentLayout.devices.remove(device);
_releaseDevice(device);
maybeReleaseDevice(device);
}
notifyListeners();
await save();
}

Expand All @@ -206,10 +205,9 @@ class LayoutsProvider extends UnityProvider {
}

for (final device in devices) {
_releaseDevice(device);
maybeReleaseDevice(device);
}

notifyListeners();
await save();
}

Expand All @@ -221,10 +219,9 @@ class LayoutsProvider extends UnityProvider {
(d1) => devices.any((d2) => d1.uri == d2.uri),
);
for (final device in devices) {
_releaseDevice(device);
maybeReleaseDevice(device);
}

notifyListeners();
await save();
}

Expand All @@ -233,7 +230,6 @@ class LayoutsProvider extends UnityProvider {
if (isLayoutLocked(currentLayout)) return;

currentLayout.devices.insert(end, currentLayout.devices.removeAt(initial));
notifyListeners();
await save();
}

Expand All @@ -244,7 +240,6 @@ class LayoutsProvider extends UnityProvider {
} else {
debugPrint('$layout already exists');
}
notifyListeners();
await save();
return layouts.indexOf(layout);
}
Expand All @@ -258,10 +253,9 @@ class LayoutsProvider extends UnityProvider {
layouts.remove(layout);

for (final device in layout.devices) {
_releaseDevice(device);
maybeReleaseDevice(device);
}
}
notifyListeners();
await save();
}

Expand All @@ -273,15 +267,14 @@ class LayoutsProvider extends UnityProvider {
..insert(layoutIndex, newLayout);
for (final device
in oldLayout.devices.where((d) => !newLayout.devices.contains(d))) {
_releaseDevice(device);
maybeReleaseDevice(device);
}

debugPrint('Replaced $oldLayout at $layoutIndex with $newLayout');
} else {
debugPrint('Layout $oldLayout not found');
}

notifyListeners();
await save();
}

Expand All @@ -291,7 +284,6 @@ class LayoutsProvider extends UnityProvider {
UnityPlayers.players[device.uuid] ??= UnityPlayers.forDevice(device);
}

notifyListeners();
await save();
}

Expand All @@ -316,7 +308,6 @@ class LayoutsProvider extends UnityProvider {
}

layouts.insert(newIndex, layouts.removeAt(oldIndex));
notifyListeners();
await save();
}

Expand Down Expand Up @@ -350,7 +341,6 @@ class LayoutsProvider extends UnityProvider {
UnityPlayers.reloadDevice(device);
}

notifyListeners();
save();

return device;
Expand All @@ -359,15 +349,13 @@ class LayoutsProvider extends UnityProvider {
Future<void> collapseServer(Server server) async {
if (!collapsedServers.contains(server.id)) {
collapsedServers.add(server.id);
notifyListeners();
await save();
}
}

Future<void> expandServer(Server server) async {
if (collapsedServers.contains(server.id)) {
collapsedServers.remove(server.id);
notifyListeners();
await save();
}
}
Expand All @@ -377,16 +365,14 @@ class LayoutsProvider extends UnityProvider {
Future<void> lockLayout(Layout layout) async {
if (!lockedLayouts.contains(layout)) {
lockedLayouts.add(layout);
notifyListeners();
await save();
await save(notifyListeners: false);
}
}

Future<void> unlockLayout(Layout layout) async {
if (lockedLayouts.contains(layout)) {
lockedLayouts.remove(layout);
notifyListeners();
await save();
await save(notifyListeners: false);
}
}

Expand All @@ -400,11 +386,14 @@ class LayoutsProvider extends UnityProvider {

bool isLayoutLocked(Layout layout) => lockedLayouts.contains(layout);

/// Sets the volume for all layouts.
void setVolume(double volume) {
for (final layout in layouts) {
layout.setVolume(volume);
}
save();
}

/// Mutes all layouts.
void mute() => setVolume(0);
}
10 changes: 7 additions & 3 deletions lib/screens/events_timeline/desktop/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,13 @@ class Timeline extends ChangeNotifier {
DateTime get currentDate => date.add(currentPosition);

void seekTo(Duration position) {
currentPosition = position;
if (position < Duration.zero) {
currentPosition = Duration.zero;
} else if (position > endPosition) {
currentPosition = endPosition;
} else {
currentPosition = position;
}
notifyListeners();

forEachEvent((tile, event) async {
Expand All @@ -375,8 +381,6 @@ class Timeline extends ChangeNotifier {
});
}

// TODO(bdlukaa): Only make it possible to seek between bounds.
// Currently, is is possible to seek before and after the day.
/// Seeks forward by [duration]
void seekForward([Duration duration = const Duration(seconds: 15)]) =>
seekTo(currentPosition + duration);
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/events_timeline/desktop/timeline_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ class _TimelineCardState extends State<TimelineCard> {
'/events',
arguments: {
'event': currentEvent.event,
'videoPlayer': widget.tile.videoController,
// Do not pass the video controller to the fullscreen
// view because we don't want to desync the video
// from the Timeline. https://github.com/bluecherrydvr/unity/issues/306
// 'videoPlayer': widget.tile.videoController,
},
);

Expand Down
18 changes: 10 additions & 8 deletions lib/screens/layouts/desktop/layout_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,7 @@ class _LayoutViewState extends State<LayoutView> {
childAspectRatio: kHorizontalAspectRatio,
reorderable: widget.onReorder != null,
onReorder: widget.onReorder ?? (a, b) {},
padding:
settings.isImmersiveMode ? EdgeInsets.zero : kGridPadding,
padding: EdgeInsets.zero,
children: devices.map((device) {
return DesktopDeviceTile(device: device);
}).toList(),
Expand Down Expand Up @@ -410,16 +409,17 @@ class _LayoutViewState extends State<LayoutView> {
SizedBox(
height: 24.0,
child: Slider(
value: widget.layout.devices
.map((device) => device.volume)
.findMaxDuplicatedElementInList()
.toDouble(),
value: volume,
divisions: 100,
label: '${(volume * 100).round()}%',
onChanged: (value) async {
widget.layout.setVolume(volume);
await widget.layout.setVolume(value);
if (mounted) setState(() {});
},
onChangeEnd: (value) async {
await widget.layout.setVolume(value);
view.save();
},
),
),
SquaredIconButton(
Expand Down Expand Up @@ -507,7 +507,9 @@ class _LayoutViewState extends State<LayoutView> {
),
),
if (devices.isNotEmpty)
Expanded(child: Center(child: child))
Expanded(
child: SizedBox.fromSize(size: Size.infinite, child: child),
)
else
Expanded(
child: Center(child: Text('Add a camera')),
Expand Down
74 changes: 42 additions & 32 deletions lib/screens/layouts/desktop/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class _DesktopSidebarState extends State<DesktopSidebar> {
var isSidebarHovering = false;
var searchQuery = '';
final Map<Server, List<Device>> _servers = <Server, List<Device>>{};
final _serversEntries = <MapEntry<Server, List<Device>>>[];

@override
void didChangeDependencies() {
Expand All @@ -51,6 +52,8 @@ class _DesktopSidebarState extends State<DesktopSidebar> {
final devices = server.devices.sorted(searchQuery: searchQuery);
_servers[server] = devices;
}
_serversEntries.clear();
_serversEntries.addAll(_servers.entries.toList(growable: false));
}

@override
Expand Down Expand Up @@ -81,26 +84,27 @@ class _DesktopSidebarState extends State<DesktopSidebar> {
child: MouseRegion(
onEnter: (e) => setState(() => isSidebarHovering = true),
onExit: (e) => setState(() => isSidebarHovering = false),
// Add another material here because its descendants must be clipped.
// Add another [Material] here because its descendants must be clipped.
child: Material(
type: MaterialType.transparency,
child: CustomScrollView(slivers: [
..._servers.entries.toList(growable: false).map((entry) {
final server = entry.key;
final devices = entry.value.where((device) {
if (!device.status &&
!settings.kListOfflineDevices.value) {
return false;
}
return true;
}).toList();
return ServerEntry(
server: server,
devices: devices,
searchQuery: searchQuery,
isSidebarHovering: isSidebarHovering,
);
}),
for (var MapEntry(key: server, value: devices)
in _serversEntries)
() {
devices = devices.where((device) {
if (!device.status &&
!settings.kListOfflineDevices.value) {
return false;
}
return true;
}).toList();
return ServerEntry(
server: server,
devices: devices,
searchQuery: searchQuery,
isSidebarHovering: isSidebarHovering,
);
}(),
]),
),
),
Expand Down Expand Up @@ -244,23 +248,29 @@ class ServerEntry extends StatelessWidget {
} else if (isSidebarHovering && devices.isNotEmpty) {
return SquaredIconButton(
icon: Icon(
isAllInView ? Icons.playlist_remove : Icons.playlist_add,
view.isLayoutLocked(view.currentLayout)
? Icons.lock
: isAllInView
? Icons.playlist_remove
: Icons.playlist_add,
),
tooltip: isAllInView ? loc.removeAllFromView : loc.addAllToView,
onPressed: () {
if (isAllInView) {
view.removeDevicesFromCurrentLayout(
devices,
);
} else {
for (final device in devices) {
if (device.status &&
!view.currentLayout.devices.contains(device)) {
view.add(device);
}
}
}
},
onPressed: view.isLayoutLocked(view.currentLayout)
? null
: () {
if (isAllInView) {
view.removeDevicesFromCurrentLayout(
devices,
);
} else {
for (final device in devices) {
if (device.status &&
!view.currentLayout.devices.contains(device)) {
view.add(device);
}
}
}
},
);
} else {
return const SizedBox.shrink();
Expand Down
1 change: 1 addition & 0 deletions lib/utils/app_links/app_links.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ Future<void> handleArgs(
if (serverResult == null) {
throw ArgumentError('Server $server not found');
} else {
await ServersProvider.instance.refreshDevices();
final deviceResult = serverResult.devices.firstWhereOrNull((d) {
return d.id.toString() == camera;
});
Expand Down
Loading
Loading