Skip to content

Commit

Permalink
Bug Fixes (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Jan 5, 2025
2 parents d792572 + 0971028 commit 7cc7a4c
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 135 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ jobs:
submodules: recursive

- name: Install dependencies
# https://docs.flutter.dev/platform-integration/linux/building#prepare-linux-apps-for-distribution
# https://pub.dev/packages/flutter_secure_storage#configure-linux-version
run: |
sudo apt-get update -y
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev mpv libmpv-dev dpkg-dev p7zip-full p7zip-rar
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev mpv libmpv-dev dpkg-dev p7zip-full p7zip-rar libsecret-1-dev libjsoncpp-dev
- name: Install Flutter
uses: subosito/[email protected]
Expand Down Expand Up @@ -381,7 +383,7 @@ jobs:
uses: subosito/[email protected]
with:
channel: "stable"
flutter-version: 3.24.0
flutter-version: 3.27.0
cache: false

- name: Initiate Flutter
Expand Down
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
Loading

0 comments on commit 7cc7a4c

Please sign in to comment.