An open-source cross-platform alternative to AirDrop
fix: GPU usage when hidden to tray (#626)
Tien Do Nam657e9c924866
diff --git a/lib/pages/tabs/receive_tab.dart b/lib/pages/tabs/receive_tab.dartindex f7b9e054..88fcac29 100644--- a/lib/pages/tabs/receive_tab.dart+++ b/lib/pages/tabs/receive_tab.dart@@ -1,6 +1,7 @@import 'package:flutter/material.dart';import 'package:localsend_app/gen/strings.g.dart';import 'package:localsend_app/pages/receive_history_page.dart';+import 'package:localsend_app/provider/animation_provider.dart';import 'package:localsend_app/provider/network/server/server_provider.dart';import 'package:localsend_app/provider/network_info_provider.dart';import 'package:localsend_app/provider/settings_provider.dart';@@ -36,6 +37,8 @@ class _ReceiveTagState extends State<ReceiveTab> with AutomaticKeepAliveClientMifinal settings = ref.watch(settingsProvider);final networkInfo = ref.watch(networkStateProvider);final serverState = ref.watch(serverProvider);+ final animations = ref.watch(animationProvider);+return Stack(children: [Center(@@ -61,7 +64,7 @@ class _ReceiveTagState extends State<ReceiveTab> with AutomaticKeepAliveClientMidelay: const Duration(milliseconds: 200),child: RotatingWidget(duration: const Duration(seconds: 15),- spinning: serverState != null,+ spinning: serverState != null && animations,child: const LocalSendLogo(withText: false),),),diff --git a/lib/pages/tabs/send_tab.dart b/lib/pages/tabs/send_tab.dartindex cca85067..3c5033fc 100644--- a/lib/pages/tabs/send_tab.dart+++ b/lib/pages/tabs/send_tab.dart@@ -9,6 +9,7 @@ import 'package:localsend_app/pages/selected_files_page.dart';import 'package:localsend_app/pages/send_page.dart';import 'package:localsend_app/pages/troubleshoot_page.dart';import 'package:localsend_app/pages/web_send_page.dart';+import 'package:localsend_app/provider/animation_provider.dart';import 'package:localsend_app/provider/network/nearby_devices_provider.dart';import 'package:localsend_app/provider/network/scan_provider.dart';import 'package:localsend_app/provider/network/send_provider.dart';@@ -283,13 +284,19 @@ class _SendTabState extends State<SendTab> with Riverpie {const SizedBox(height: 20),Padding(padding: const EdgeInsets.symmetric(horizontal: _horizontalPadding),- child: OpacitySlideshow(- durationMillis: 6000,- children: [- Text(t.sendTab.help, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),- if (checkPlatformCanReceiveShareIntent())- Text(t.sendTab.shareIntentInfo, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),- ],+ child: Consumer(+ builder: (context, ref) {+ final animations = ref.watch(animationProvider);+ return OpacitySlideshow(+ durationMillis: 6000,+ running: animations,+ children: [+ Text(t.sendTab.help, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),+ if (checkPlatformCanReceiveShareIntent())+ Text(t.sendTab.shareIntentInfo, style: const TextStyle(color: Colors.grey), textAlign: TextAlign.center),+ ],+ );+ }),),const SizedBox(height: 50),diff --git a/lib/provider/animation_provider.dart b/lib/provider/animation_provider.dartnew file mode 100644index 00000000..28d33808--- /dev/null+++ b/lib/provider/animation_provider.dart@@ -0,0 +1,6 @@+import 'package:riverpie_flutter/riverpie_flutter.dart';++/// If false, then animations are disabled.+final animationProvider = StateProvider<bool>((ref) {+ return true;+});diff --git a/lib/util/native/tray_helper.dart b/lib/util/native/tray_helper.dartindex 78235cd6..a5a5dbfb 100644--- a/lib/util/native/tray_helper.dart+++ b/lib/util/native/tray_helper.dart@@ -2,8 +2,10 @@ import 'dart:io';import 'package:flutter/foundation.dart';import 'package:localsend_app/gen/assets.gen.dart';import 'package:localsend_app/gen/strings.g.dart';+import 'package:localsend_app/provider/animation_provider.dart';import 'package:localsend_app/util/native/platform_check.dart';import 'package:logging/logging.dart';+import 'package:riverpie_flutter/riverpie_flutter.dart';import 'package:system_tray/system_tray.dart';import 'package:tray_manager/tray_manager.dart' as tm;import 'package:window_manager/window_manager.dart';@@ -86,6 +88,9 @@ Future<void> hideToTray() async {// https://github.com/localsend/localsend/issues/32await windowManager.setSkipTaskbar(true);}++ // Disable animations+ RiverpieScope.defaultRef.notifier(animationProvider).setState((_) => false);}Future<void> showFromTray() async {@@ -96,4 +101,7 @@ Future<void> showFromTray() async {// https://github.com/localsend/localsend/issues/32await windowManager.setSkipTaskbar(false);}++ // Enable animations+ RiverpieScope.defaultRef.notifier(animationProvider).setState((_) => true);}diff --git a/lib/widget/list_tile/device_placeholder_list_tile.dart b/lib/widget/list_tile/device_placeholder_list_tile.dartindex f6bd57ee..7601a0b5 100644--- a/lib/widget/list_tile/device_placeholder_list_tile.dart+++ b/lib/widget/list_tile/device_placeholder_list_tile.dart@@ -1,17 +1,21 @@import 'package:flutter/material.dart';import 'package:localsend_app/model/device.dart';+import 'package:localsend_app/provider/animation_provider.dart';import 'package:localsend_app/widget/device_bage.dart';import 'package:localsend_app/widget/list_tile/custom_list_tile.dart';import 'package:localsend_app/widget/opacity_slideshow.dart';+import 'package:riverpie_flutter/riverpie_flutter.dart';class DevicePlaceholderListTile extends StatelessWidget {const DevicePlaceholderListTile();@overrideWidget build(BuildContext context) {+ final animations = context.ref.watch(animationProvider);return CustomListTile(icon: OpacitySlideshow(durationMillis: 3000,+ running: animations,children: [...DeviceType.values.map((d) => Icon(d.icon, size: 46)),],diff --git a/lib/widget/opacity_slideshow.dart b/lib/widget/opacity_slideshow.dartindex 1ddbd341..419acc27 100644--- a/lib/widget/opacity_slideshow.dart+++ b/lib/widget/opacity_slideshow.dart@@ -8,11 +8,13 @@ class OpacitySlideshow extends StatefulWidget {final List<Widget> children;final int durationMillis;final int switchDurationMillis;+ final bool running;const OpacitySlideshow({required this.children,required this.durationMillis,this.switchDurationMillis = 300,+ this.running = true,super.key,});@@ -28,9 +30,7 @@ class _OpacitySlideshowState extends State<OpacitySlideshow> {@overridevoid initState() {super.initState();- if (widget.children.length > 1) {- _startTimer();- }+ _startTimer();}@override@@ -39,7 +39,21 @@ class _OpacitySlideshowState extends State<OpacitySlideshow> {_timer?.cancel();}+ @override+ void didUpdateWidget(OpacitySlideshow oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.running && !widget.running) {+ _timer?.cancel();+ } else if (!oldWidget.running && widget.running) {+ _startTimer();+ }+ }+void _startTimer() {+ if (widget.children.length <= 1) {+ return;+ }+_timer = Timer.periodic(Duration(milliseconds: widget.durationMillis), (_) async {if (!mounted) return;setState(() {