✨ Tray
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| import 'package:easy_localization/easy_localization.dart'; | ||||
| import 'package:freezed_annotation/freezed_annotation.dart'; | ||||
| import 'package:island/models/post.dart'; | ||||
| import 'package:island/services/text.dart'; | ||||
| import 'package:island/utils/text.dart'; | ||||
|  | ||||
| part 'post_category.freezed.dart'; | ||||
| part 'post_category.g.dart'; | ||||
|   | ||||
| @@ -10,7 +10,7 @@ import 'package:island/pods/config.dart'; | ||||
| import 'package:island/pods/network.dart'; | ||||
| import 'package:island/screens/account/me/account_settings.dart'; | ||||
| import 'package:island/screens/auth/oidc.native.dart'; | ||||
| import 'package:island/services/text.dart'; | ||||
| import 'package:island/utils/text.dart'; | ||||
| import 'package:island/services/time.dart'; | ||||
| import 'package:island/widgets/alert.dart'; | ||||
| import 'package:island/widgets/content/sheet.dart'; | ||||
|   | ||||
| @@ -17,7 +17,7 @@ import 'package:island/pods/network.dart'; | ||||
| import 'package:island/pods/userinfo.dart'; | ||||
| import 'package:island/services/color.dart'; | ||||
| import 'package:island/services/responsive.dart'; | ||||
| import 'package:island/services/text.dart'; | ||||
| import 'package:island/utils/text.dart'; | ||||
| import 'package:island/services/time.dart'; | ||||
| import 'package:island/services/timezone/native.dart'; | ||||
| import 'package:island/widgets/account/account_name.dart'; | ||||
|   | ||||
| @@ -11,7 +11,7 @@ import 'package:island/models/publisher.dart'; | ||||
| import 'package:island/pods/network.dart'; | ||||
| import 'package:island/screens/creators/publishers.dart'; | ||||
| import 'package:island/services/responsive.dart'; | ||||
| import 'package:island/services/text.dart'; | ||||
| import 'package:island/utils/text.dart'; | ||||
| import 'package:island/widgets/account/account_picker.dart'; | ||||
| import 'package:island/widgets/alert.dart'; | ||||
| import 'package:island/widgets/app_scaffold.dart'; | ||||
|   | ||||
							
								
								
									
										58
									
								
								lib/screens/tray_manager.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								lib/screens/tray_manager.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| import 'dart:io'; | ||||
|  | ||||
| import 'package:bitsdojo_window/bitsdojo_window.dart'; | ||||
| import 'package:flutter/foundation.dart'; | ||||
| import 'package:tray_manager/tray_manager.dart'; | ||||
|  | ||||
| class TrayService { | ||||
|   TrayService._(); | ||||
|  | ||||
|   static final TrayService _instance = TrayService._(); | ||||
|  | ||||
|   static TrayService get instance => _instance; | ||||
|  | ||||
|   bool _checkPlatformAvalability() { | ||||
|     if (kIsWeb) return false; | ||||
|     if (Platform.isAndroid || Platform.isIOS) return false; | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   Future<void> initialize(TrayListener listener) async { | ||||
|     if (!_checkPlatformAvalability()) return; | ||||
|  | ||||
|     await trayManager.setIcon( | ||||
|       Platform.isWindows | ||||
|           ? 'assets/icons/icon.ico' | ||||
|           : 'assets/icons/icon-outline.svg', | ||||
|     ); | ||||
|  | ||||
|     final menu = Menu( | ||||
|       items: [ | ||||
|         MenuItem(key: 'show_window', label: 'Show Window'), | ||||
|         MenuItem.separator(), | ||||
|         MenuItem(key: 'exit_app', label: 'Exit App'), | ||||
|       ], | ||||
|     ); | ||||
|     await trayManager.setContextMenu(menu); | ||||
|  | ||||
|     trayManager.addListener(listener); | ||||
|   } | ||||
|  | ||||
|   Future<void> dispose(TrayListener listener) async { | ||||
|     if (!_checkPlatformAvalability()) return; | ||||
|  | ||||
|     trayManager.removeListener(listener); | ||||
|     await trayManager.destroy(); | ||||
|   } | ||||
|  | ||||
|   void handleAction(MenuItem item) { | ||||
|     switch (item.key) { | ||||
|       case 'show_window': | ||||
|         appWindow.show(); | ||||
|         break; | ||||
|       case 'exit_app': | ||||
|         appWindow.close(); | ||||
|         break; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -1,15 +1,18 @@ | ||||
| import 'dart:async'; | ||||
| import 'package:bitsdojo_window/bitsdojo_window.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:flutter_hooks/flutter_hooks.dart'; | ||||
| import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||||
| import 'package:island/pods/websocket.dart'; | ||||
| import 'package:island/screens/tray_manager.dart'; | ||||
| import 'package:island/services/notify.dart'; | ||||
| import 'package:island/services/sharing_intent.dart'; | ||||
| import 'package:island/services/update_service.dart'; | ||||
| import 'package:island/widgets/content/network_status_sheet.dart'; | ||||
| import 'package:island/widgets/tour/tour.dart'; | ||||
| import 'package:tray_manager/tray_manager.dart'; | ||||
|  | ||||
| class AppWrapper extends HookConsumerWidget { | ||||
| class AppWrapper extends HookConsumerWidget with TrayListener { | ||||
|   final Widget child; | ||||
|   const AppWrapper({super.key, required this.child}); | ||||
|  | ||||
| @@ -20,10 +23,16 @@ class AppWrapper extends HookConsumerWidget { | ||||
|       Future(() { | ||||
|         if (context.mounted) ntySubs = setupNotificationListener(context, ref); | ||||
|       }); | ||||
|  | ||||
|       final sharingService = SharingIntentService(); | ||||
|       sharingService.initialize(context); | ||||
|  | ||||
|       UpdateService().checkForUpdates(context); | ||||
|  | ||||
|       TrayService.instance.initialize(this); | ||||
|  | ||||
|       return () { | ||||
|         TrayService.instance.dispose(this); | ||||
|         sharingService.dispose(); | ||||
|         ntySubs?.cancel(); | ||||
|       }; | ||||
| @@ -52,4 +61,27 @@ class AppWrapper extends HookConsumerWidget { | ||||
|  | ||||
|     return TourTriggerWidget(key: UniqueKey(), child: child); | ||||
|   } | ||||
|  | ||||
|   void _trayIconPrimaryAction() { | ||||
|     appWindow.show(); | ||||
|   } | ||||
|  | ||||
|   void _trayIconSecondaryAction() { | ||||
|     trayManager.popUpContextMenu(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void onTrayIconMouseUp() { | ||||
|     _trayIconPrimaryAction(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void onTrayIconRightMouseDown() { | ||||
|     _trayIconSecondaryAction(); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   void onTrayMenuItemClick(MenuItem menuItem) { | ||||
|     TrayService.instance.handleAction(menuItem); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -41,6 +41,7 @@ class PostShuffleScreen extends HookConsumerWidget { | ||||
|                     ? CardSwiper( | ||||
|                       controller: cardSwiperController, | ||||
|                       cardsCount: postListState.value!.items.length, | ||||
|                       isLoop: false, | ||||
|                       cardBuilder: ( | ||||
|                         context, | ||||
|                         index, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user