clean up logging

This commit is contained in:
mertalev 2024-11-07 17:24:37 -05:00
parent 49c4d7cff9
commit bef9a1eae7
No known key found for this signature in database
GPG Key ID: CA85EF6600C9E8AD
2 changed files with 3 additions and 42 deletions

View File

@ -93,12 +93,11 @@ class GalleryViewerPage extends HookConsumerWidget {
void onError(Object exception, StackTrace? stackTrace) { void onError(Object exception, StackTrace? stackTrace) {
// swallow error silently // swallow error silently
debugPrint('Error precaching next image: $exception, $stackTrace'); log.severe('Error precaching next image: $exception, $stackTrace');
} }
try { try {
if (index < totalAssets.value && index >= 0) { if (index < totalAssets.value && index >= 0) {
log.info('Precaching next image at index $index');
final asset = loadAsset(index); final asset = loadAsset(index);
await precacheImage( await precacheImage(
ImmichImage.imageProvider(asset: asset), ImmichImage.imageProvider(asset: asset),
@ -108,15 +107,13 @@ class GalleryViewerPage extends HookConsumerWidget {
} }
} catch (e) { } catch (e) {
// swallow error silently // swallow error silently
debugPrint('Error precaching next image: $e'); log.severe('Error precaching next image: $e');
context.maybePop(); context.maybePop();
} }
} }
// Listen provider to prevent autoDispose when navigating to other routes from within the gallery page // Listen provider to prevent autoDispose when navigating to other routes from within the gallery page
ref.listen(currentAssetProvider, (prev, cur) { ref.listen(currentAssetProvider, (prev, cur) {});
log.info('Current asset changed from ${prev?.id} to ${cur?.id}');
});
useEffect(() { useEffect(() {
ref.read(currentAssetProvider.notifier).set(asset); ref.read(currentAssetProvider.notifier).set(asset);
@ -338,7 +335,6 @@ class GalleryViewerPage extends HookConsumerWidget {
if (newAsset.isImage && !isPlayingMotionVideo.value) { if (newAsset.isImage && !isPlayingMotionVideo.value) {
return buildImage(context, newAsset); return buildImage(context, newAsset);
} }
log.info('Loading asset ${newAsset.id} (index $index) as video');
return buildVideo(context, newAsset); return buildVideo(context, newAsset);
} }
@ -386,7 +382,6 @@ class GalleryViewerPage extends HookConsumerWidget {
itemCount: totalAssets.value, itemCount: totalAssets.value,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
onPageChanged: (value) { onPageChanged: (value) {
log.info('Page changed to $value');
final next = currentIndex.value < value ? value + 1 : value - 1; final next = currentIndex.value < value ? value + 1 : value - 1;
ref.read(hapticFeedbackProvider.notifier).selectionClick(); ref.read(hapticFeedbackProvider.notifier).selectionClick();

View File

@ -24,7 +24,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
final bool showControls; final bool showControls;
final Duration hideControlsTimer; final Duration hideControlsTimer;
final Widget placeholder; final Widget placeholder;
// final ValueNotifier<bool>? doInitialize;
const NativeVideoViewerPage({ const NativeVideoViewerPage({
super.key, super.key,
@ -48,7 +47,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
final isCurrent = currentAsset.value == asset; final isCurrent = currentAsset.value == asset;
final log = Logger('NativeVideoViewerPage'); final log = Logger('NativeVideoViewerPage');
log.info('Building NativeVideoViewerPage');
final localEntity = useMemoized(() { final localEntity = useMemoized(() {
if (!asset.isLocal) { if (!asset.isLocal) {
@ -60,11 +58,9 @@ class NativeVideoViewerPage extends HookConsumerWidget {
Future<double?> calculateAspectRatio() async { Future<double?> calculateAspectRatio() async {
if (!context.mounted) { if (!context.mounted) {
log.info('calculateAspectRatio: Context is not mounted');
return null; return null;
} }
log.info('Calculating aspect ratio');
late final double? orientatedWidth; late final double? orientatedWidth;
late final double? orientatedHeight; late final double? orientatedHeight;
@ -81,7 +77,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
orientatedHeight = entity.orientatedHeight?.toDouble(); orientatedHeight = entity.orientatedHeight?.toDouble();
} }
log.info('Calculated aspect ratio');
if (orientatedWidth != null && if (orientatedWidth != null &&
orientatedHeight != null && orientatedHeight != null &&
orientatedWidth > 0 && orientatedWidth > 0 &&
@ -94,13 +89,10 @@ class NativeVideoViewerPage extends HookConsumerWidget {
Future<VideoSource?> createSource() async { Future<VideoSource?> createSource() async {
if (!context.mounted) { if (!context.mounted) {
log.info('createSource: Context is not mounted');
return null; return null;
} }
if (localEntity != null && asset.livePhotoVideoId == null) { if (localEntity != null && asset.livePhotoVideoId == null) {
log.info('Loading video from local storage');
final file = await (await localEntity)!.file; final file = await (await localEntity)!.file;
if (file == null) { if (file == null) {
throw Exception('No file found for the video'); throw Exception('No file found for the video');
@ -110,12 +102,9 @@ class NativeVideoViewerPage extends HookConsumerWidget {
path: file.path, path: file.path,
type: VideoSourceType.file, type: VideoSourceType.file,
); );
log.info('Loaded video from local storage');
return source; return source;
} }
log.info('Loading video from server');
// Use a network URL for the video player controller // Use a network URL for the video player controller
final serverEndpoint = Store.get(StoreKey.serverEndpoint); final serverEndpoint = Store.get(StoreKey.serverEndpoint);
final String videoUrl = asset.livePhotoVideoId != null final String videoUrl = asset.livePhotoVideoId != null
@ -127,7 +116,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
type: VideoSourceType.network, type: VideoSourceType.network,
headers: ApiService.getRequestHeaders(), headers: ApiService.getRequestHeaders(),
); );
log.info('Loaded video from server');
return source; return source;
} }
@ -136,14 +124,12 @@ class NativeVideoViewerPage extends HookConsumerWidget {
useMemoized( useMemoized(
() async { () async {
if (!context.mounted) { if (!context.mounted) {
log.info('combined: Context is not mounted');
return null; return null;
} }
final (videoSourceRes, aspectRatioRes) = final (videoSourceRes, aspectRatioRes) =
await (createSource(), calculateAspectRatio()).wait; await (createSource(), calculateAspectRatio()).wait;
if (videoSourceRes == null || aspectRatioRes == null) { if (videoSourceRes == null || aspectRatioRes == null) {
log.info('combined: Video source or aspect ratio is null');
return; return;
} }
@ -162,12 +148,10 @@ class NativeVideoViewerPage extends HookConsumerWidget {
return; return;
} }
log.info('Checking if buffering');
final videoPlayback = ref.read(videoPlaybackValueProvider); final videoPlayback = ref.read(videoPlaybackValueProvider);
if ((isBuffering.value || if ((isBuffering.value ||
videoPlayback.state == VideoPlaybackState.initializing) && videoPlayback.state == VideoPlaybackState.initializing) &&
videoPlayback.state != VideoPlaybackState.buffering) { videoPlayback.state != VideoPlaybackState.buffering) {
log.info('Marking video as buffering');
ref.read(videoPlaybackValueProvider.notifier).value = ref.read(videoPlaybackValueProvider.notifier).value =
videoPlayback.copyWith(state: VideoPlaybackState.buffering); videoPlayback.copyWith(state: VideoPlaybackState.buffering);
} }
@ -237,10 +221,8 @@ class NativeVideoViewerPage extends HookConsumerWidget {
try { try {
if (pause) { if (pause) {
log.info('Pausing video');
videoController.pause(); videoController.pause();
} else { } else {
log.info('Playing video');
videoController.play(); videoController.play();
} }
} catch (error) { } catch (error) {
@ -254,8 +236,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
return; return;
} }
log.info('Playback ready for video ${asset.id}');
try { try {
videoController.play(); videoController.play();
videoController.setVolume(0.9); videoController.setVolume(0.9);
@ -265,18 +245,12 @@ class NativeVideoViewerPage extends HookConsumerWidget {
} }
ref.listen(currentAssetProvider, (_, value) { ref.listen(currentAssetProvider, (_, value) {
log.info(
'Changing currentAsset from ${currentAsset.value?.id} isCurrent to ${value?.id}',
);
// Delay the video playback to avoid a stutter in the swipe animation // Delay the video playback to avoid a stutter in the swipe animation
Timer(const Duration(milliseconds: 350), () { Timer(const Duration(milliseconds: 350), () {
if (!context.mounted) { if (!context.mounted) {
return; return;
} }
log.info(
'Changed currentAsset from ${currentAsset.value?.id} isCurrent to ${value?.id}',
);
currentAsset.value = value; currentAsset.value = value;
if (currentAsset.value == asset) { if (currentAsset.value == asset) {
onPlaybackReady(); onPlaybackReady();
@ -300,11 +274,9 @@ class NativeVideoViewerPage extends HookConsumerWidget {
if (videoPlayback.state == VideoPlaybackState.playing) { if (videoPlayback.state == VideoPlaybackState.playing) {
// Sync with the controls playing // Sync with the controls playing
WakelockPlus.enable(); WakelockPlus.enable();
log.info('Video ${asset.id} is playing; enabled wakelock');
} else { } else {
// Sync with the controls pause // Sync with the controls pause
WakelockPlus.disable(); WakelockPlus.disable();
log.info('Video ${asset.id} is not playing; disabled wakelock');
} }
} }
@ -350,10 +322,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
} }
void initController(NativeVideoPlayerController nc) { void initController(NativeVideoPlayerController nc) {
log.info('initController for ${asset.id} started');
if (controller.value != null) { if (controller.value != null) {
log.info(
'initController for ${asset.id}: Controller already initialized');
return; return;
} }
ref.read(videoPlayerControlsProvider.notifier).reset(); ref.read(videoPlayerControlsProvider.notifier).reset();
@ -366,7 +335,6 @@ class NativeVideoViewerPage extends HookConsumerWidget {
nc.loadVideoSource(videoSource.value!); nc.loadVideoSource(videoSource.value!);
log.info('initController for ${asset.id}: setting controller');
controller.value = nc; controller.value = nc;
Timer(const Duration(milliseconds: 200), checkIfBuffering); Timer(const Duration(milliseconds: 200), checkIfBuffering);
} }
@ -374,10 +342,8 @@ class NativeVideoViewerPage extends HookConsumerWidget {
useEffect( useEffect(
() { () {
return () { return () {
log.info('Cleaning up video ${asset.id}');
final playerController = controller.value; final playerController = controller.value;
if (playerController == null) { if (playerController == null) {
log.info('Controller is null');
return; return;
} }