2022-06-11 23:12:06 +02:00
import ' package:flutter/gestures.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:hooks_riverpod/hooks_riverpod.dart ' ;
import ' package:immich_mobile/shared/providers/release_info.provider.dart ' ;
import ' package:url_launcher/url_launcher.dart ' ;
class VersionAnnouncementOverlay extends HookConsumerWidget {
const VersionAnnouncementOverlay ( {
Key ? key ,
} ) : super ( key: key ) ;
@ override
Widget build ( BuildContext context , WidgetRef ref ) {
void goToReleaseNote ( ) async {
2022-06-22 07:23:35 +02:00
final Uri url =
Uri . parse ( ' https://github.com/alextran1502/immich/releases/latest ' ) ;
await launchUrl ( url ) ;
2022-06-11 23:12:06 +02:00
}
void onAcknowledgeTapped ( ) {
ref . watch ( releaseInfoProvider . notifier ) . acknowledgeNewVersion ( ) ;
}
return ValueListenableBuilder < bool > (
2022-06-22 07:23:35 +02:00
valueListenable:
VersionAnnouncementOverlayController . appLoader . loaderShowingNotifier ,
2022-06-11 23:12:06 +02:00
builder: ( context , shouldShow , child ) {
if ( shouldShow ) {
return Scaffold (
backgroundColor: Colors . black38 ,
body: Center (
child: ConstrainedBox (
constraints: const BoxConstraints ( maxWidth: 307 ) ,
child: Wrap (
children: [
Card (
child: Padding (
padding: const EdgeInsets . all ( 30.0 ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
const Text (
" New Server Version Available 🎉 " ,
style: TextStyle (
fontSize: 16 ,
fontFamily: ' WorkSans ' ,
fontWeight: FontWeight . bold ,
color: Colors . indigo ,
) ,
) ,
Padding (
padding: const EdgeInsets . only ( top: 16.0 ) ,
child: RichText (
text: TextSpan (
style: const TextStyle (
2022-06-22 07:23:35 +02:00
fontSize: 14 ,
fontFamily: ' WorkSans ' ,
color: Colors . black87 ,
height: 1.2 ) ,
2022-06-11 23:12:06 +02:00
children: < TextSpan > [
const TextSpan (
2022-06-22 07:23:35 +02:00
text:
' Hi friend, there is a new release of ' ,
2022-06-11 23:12:06 +02:00
) ,
const TextSpan (
text: ' Immich ' ,
style: TextStyle (
fontFamily: " SnowBurstOne " ,
color: Colors . indigo ,
fontWeight: FontWeight . bold ,
) ,
) ,
const TextSpan (
2022-06-22 07:23:35 +02:00
text:
" please take your time to visit the " ,
2022-06-11 23:12:06 +02:00
) ,
TextSpan (
text: " release note " ,
style: const TextStyle (
decoration: TextDecoration . underline ,
) ,
2022-06-22 07:23:35 +02:00
recognizer: TapGestureRecognizer ( )
. . onTap = goToReleaseNote ,
2022-06-11 23:12:06 +02:00
) ,
const TextSpan (
text:
" and ensure your docker-compose and .env setup is up-to-date to prevent any misconfigurations, especially if you use WatchTower or any mechanism that handles updating your server application automatically. " ,
2022-06-23 06:14:14 +02:00
) ,
2022-06-11 23:12:06 +02:00
] ,
) ,
) ,
) ,
Padding (
padding: const EdgeInsets . only ( top: 16.0 ) ,
child: ElevatedButton (
2022-06-23 06:14:14 +02:00
style: ElevatedButton . styleFrom (
shape: const StadiumBorder ( ) ,
visualDensity: VisualDensity . standard ,
primary: Colors . indigo ,
onPrimary: Colors . grey [ 50 ] ,
elevation: 2 ,
padding: const EdgeInsets . symmetric (
vertical: 10 , horizontal: 25 ) ,
) ,
onPressed: onAcknowledgeTapped ,
child: const Text (
" Acknowledge " ,
style: TextStyle (
fontSize: 14 ,
2022-06-11 23:12:06 +02:00
) ,
2022-06-23 06:14:14 +02:00
) ,
) ,
) ,
2022-06-11 23:12:06 +02:00
] ,
) ,
) ,
) ,
] ,
) ,
) ,
) ,
) ;
} else {
2022-07-01 03:08:49 +02:00
return const SizedBox ( ) ;
2022-06-11 23:12:06 +02:00
}
} ,
) ;
}
}
class VersionAnnouncementOverlayController {
2022-06-22 07:23:35 +02:00
static final VersionAnnouncementOverlayController appLoader =
VersionAnnouncementOverlayController ( ) ;
2022-06-11 23:12:06 +02:00
ValueNotifier < bool > loaderShowingNotifier = ValueNotifier ( false ) ;
ValueNotifier < String > loaderTextNotifier = ValueNotifier ( ' error message ' ) ;
void show ( ) {
loaderShowingNotifier . value = true ;
}
void hide ( ) {
loaderShowingNotifier . value = false ;
}
}