diff --git a/lib/main.dart b/lib/main.dart index 072815c..7daf734 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -89,14 +89,16 @@ void main() async { await EasyLocalization.ensureInitialized(); if (!kIsWeb && !Platform.isLinux) { - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform); } GoRouter.optionURLReflectsImperativeAPIs = true; usePathUrlStrategy(); if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) { - Workmanager().initialize(appBackgroundDispatcher, isInDebugMode: kDebugMode); + Workmanager() + .initialize(appBackgroundDispatcher, isInDebugMode: kDebugMode); if (Platform.isAndroid) { Workmanager().registerPeriodicTask( "widget-update-random-post", @@ -109,7 +111,8 @@ void main() async { } if (!kIsWeb && Platform.isAndroid) { - final ImagePickerPlatform imagePickerImplementation = ImagePickerPlatform.instance; + final ImagePickerPlatform imagePickerImplementation = + ImagePickerPlatform.instance; if (imagePickerImplementation is ImagePickerAndroid) { imagePickerImplementation.useAndroidPhotoPicker = true; } @@ -126,7 +129,12 @@ class SolianApp extends StatelessWidget { return ResponsiveBreakpoints.builder( child: EasyLocalization( path: 'assets/translations', - supportedLocales: [Locale('en', 'US'), Locale('zh', 'CN'), Locale('zh', 'TW'), Locale('zh', 'HK')], + supportedLocales: [ + Locale('en', 'US'), + Locale('zh', 'CN'), + Locale('zh', 'TW'), + Locale('zh', 'HK') + ], fallbackLocale: Locale('en', 'US'), useFallbackTranslations: true, assetLoader: JsonAssetLoader(), @@ -201,7 +209,8 @@ class _AppDelegate extends StatelessWidget { ], routerConfig: appRouter, builder: (context, child) { - return _AppSplashScreen(key: const Key('global-splash-screen'), child: child!); + return _AppSplashScreen( + key: const Key('global-splash-screen'), child: child!); }, ); } @@ -225,7 +234,8 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { if (prefs.containsKey('first_boot_time')) { final rawTime = prefs.getString('first_boot_time'); final time = DateTime.tryParse(rawTime ?? ''); - if (time != null && time.isBefore(DateTime.now().subtract(const Duration(days: 3)))) { + if (time != null && + time.isBefore(DateTime.now().subtract(const Duration(days: 3)))) { final inAppReview = InAppReview.instance; if (prefs.getBool('rating_requested') == true) return; if (await inAppReview.isAvailable()) { @@ -246,17 +256,26 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { final info = await PackageInfo.fromPlatform(); final localVersionString = '${info.version}+${info.buildNumber}'; final resp = await Dio( - BaseOptions(sendTimeout: const Duration(seconds: 60), receiveTimeout: const Duration(seconds: 60)), - ).get('https://api.github.com/repos/Solsynth/HyperNet.Surface/releases/latest'); + BaseOptions( + sendTimeout: const Duration(seconds: 60), + receiveTimeout: const Duration(seconds: 60)), + ).get( + 'https://api.github.com/repos/Solsynth/HyperNet.Surface/releases/latest'); final remoteVersionString = resp.data?['tag_name'] ?? '0.0.0+0'; final remoteVersion = Version.parse(remoteVersionString.split('+').first); final localVersion = Version.parse(localVersionString.split('+').first); - final remoteBuildNumber = int.tryParse(remoteVersionString.split('+').last) ?? 0; - final localBuildNumber = int.tryParse(localVersionString.split('+').last) ?? 0; - logging.info("[Update] Local: $localVersionString, Remote: $remoteVersionString"); - if ((remoteVersion > localVersion || remoteBuildNumber > localBuildNumber) && mounted) { + final remoteBuildNumber = + int.tryParse(remoteVersionString.split('+').last) ?? 0; + final localBuildNumber = + int.tryParse(localVersionString.split('+').last) ?? 0; + logging.info( + "[Update] Local: $localVersionString, Remote: $remoteVersionString"); + if ((remoteVersion > localVersion || + remoteBuildNumber > localBuildNumber) && + mounted) { final config = context.read(); - config.setUpdate(remoteVersionString, resp.data?['body'] ?? 'No changelog'); + config.setUpdate( + remoteVersionString, resp.data?['body'] ?? 'No changelog'); logging.info("[Update] Update available: $remoteVersionString"); } } catch (e) { @@ -307,7 +326,7 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { final notify = context.read(); notify.listen(); try { - await notify.registerPushNotifications(); + notify.registerPushNotifications(); } catch (_) {} if (!mounted) return; _setPhaseText('stickers'); @@ -346,7 +365,10 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { items: [ MenuItem(key: 'version_label', label: 'Solian', disabled: true), MenuItem.separator(), - MenuItem.checkbox(checked: false, key: 'mute_notification', label: 'trayMenuMuteNotification'.tr()), + MenuItem.checkbox( + checked: false, + key: 'mute_notification', + label: 'trayMenuMuteNotification'.tr()), MenuItem.separator(), MenuItem(key: 'window_show', label: 'trayMenuShow'.tr()), MenuItem(key: 'exit', label: 'trayMenuExit'.tr()), @@ -356,7 +378,9 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { Future _trayInitialization() async { if (kIsWeb || Platform.isAndroid || Platform.isIOS) return; - final icon = Platform.isWindows ? 'assets/icon/tray-icon.ico' : 'assets/icon/tray-icon.png'; + final icon = Platform.isWindows + ? 'assets/icon/tray-icon.ico' + : 'assets/icon/tray-icon.png'; final appVersion = await PackageInfo.fromPlatform(); trayManager.addListener(this); @@ -374,7 +398,8 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { Future _notifyInitialization() async { if (kIsWeb || Platform.isAndroid || Platform.isIOS) return; - await localNotifier.setup(appName: 'Solian', shortcutPolicy: ShortcutPolicy.requireCreate); + await localNotifier.setup( + appName: 'Solian', shortcutPolicy: ShortcutPolicy.requireCreate); } AppLifecycleListener? _appLifecycleListener; @@ -385,7 +410,8 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { _isBusy = true; if (!kIsWeb && !(Platform.isIOS || Platform.isAndroid)) { - _appLifecycleListener = AppLifecycleListener(onExitRequested: _onExitRequested); + _appLifecycleListener = + AppLifecycleListener(onExitRequested: _onExitRequested); } _trayInitialization(); @@ -485,49 +511,49 @@ class _AppSplashScreenState extends State<_AppSplashScreen> with TrayListener { } }); return SizeChangedLayoutNotifier( - child: - _isBusy - ? Material( - key: Key('app-splash-screen-$_isBusy'), - child: Stack( - children: [ - Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/icon/kanban-1st.jpg'), - fit: BoxFit.cover, - opacity: 0.1, - ), - color: Theme.of(context).colorScheme.surface, - backgroundBlendMode: BlendMode.darken, + child: _isBusy + ? Material( + key: Key('app-splash-screen-$_isBusy'), + child: Stack( + children: [ + Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/icon/kanban-1st.jpg'), + fit: BoxFit.cover, + opacity: 0.1, + ), + color: Theme.of(context).colorScheme.surface, + backgroundBlendMode: BlendMode.darken, + ), + ), + Center( + child: Container( + constraints: const BoxConstraints(maxWidth: 240), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Image.asset( + 'assets/icon/icon.png', + width: 64, + height: 64, + color: + Theme.of(context).colorScheme.onSurface, + ), + Text('Solar Network').bold(), + AppVersionLabel(), + Gap(8), + Text(_phaseText, textAlign: TextAlign.center), + Gap(16), + const LinearProgressIndicator(), + ], ), ), - Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 240), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Image.asset( - 'assets/icon/icon.png', - width: 64, - height: 64, - color: Theme.of(context).colorScheme.onSurface, - ), - Text('Solar Network').bold(), - AppVersionLabel(), - Gap(8), - Text(_phaseText, textAlign: TextAlign.center), - Gap(16), - const LinearProgressIndicator(), - ], - ), - ), - ), - ], - ), - ) - : widget.child, + ), + ], + ), + ) + : widget.child, ); }, ),