✨ Tray icon basis
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:croppy/croppy.dart';
|
||||
@ -10,6 +11,7 @@ import 'package:easy_localization_loader/easy_localization_loader.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
@ -43,6 +45,7 @@ import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:version/version.dart';
|
||||
import 'package:workmanager/workmanager.dart';
|
||||
import 'package:in_app_review/in_app_review.dart';
|
||||
import 'package:system_tray/system_tray.dart';
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void appBackgroundDispatcher() {
|
||||
@ -294,9 +297,51 @@ class _AppSplashScreenState extends State<_AppSplashScreen> {
|
||||
await widgetUpdateRandomPost();
|
||||
}
|
||||
|
||||
Future<void> _trayInitialization() async {
|
||||
if (kIsWeb || Platform.isAndroid || Platform.isIOS) return;
|
||||
|
||||
final icon = Platform.isWindows ? 'assets/icon/tray-icon.ico' : 'assets/icon/tray-icon.png';
|
||||
final SystemTray systemTray = SystemTray();
|
||||
|
||||
await systemTray.initSystemTray(
|
||||
title: "",
|
||||
iconPath: icon,
|
||||
);
|
||||
|
||||
await systemTray.setContextMenu([
|
||||
MenuItem(label: 'trayMenuShow'.tr(), onClicked: () => appWindow.show()),
|
||||
MenuItem(label: 'trayMenuHide'.tr(), onClicked: () => appWindow.hide()),
|
||||
MenuItem(
|
||||
label: 'trayMenuExit'.tr(),
|
||||
onClicked: () {
|
||||
_appLifecycleListener?.dispose();
|
||||
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
|
||||
},
|
||||
),
|
||||
]);
|
||||
|
||||
systemTray.registerSystemTrayEventHandler((eventName) {
|
||||
if (eventName == "leftMouseDown") {
|
||||
Platform.isWindows ? appWindow.show() : systemTray.popUpContextMenu();
|
||||
} else if (eventName == "rightMouseDown") {
|
||||
Platform.isWindows ? systemTray.popUpContextMenu() : appWindow.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
AppLifecycleListener? _appLifecycleListener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (!kIsWeb && !(Platform.isIOS || Platform.isAndroid)) {
|
||||
_appLifecycleListener = AppLifecycleListener(
|
||||
onExitRequested: _onExitRequested,
|
||||
);
|
||||
}
|
||||
|
||||
_trayInitialization();
|
||||
_initialize().then((_) {
|
||||
_postInitialization();
|
||||
_tryRequestRating();
|
||||
@ -304,6 +349,11 @@ class _AppSplashScreenState extends State<_AppSplashScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<AppExitResponse> _onExitRequested() async {
|
||||
appWindow.hide();
|
||||
return AppExitResponse.cancel;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cfg = context.read<ConfigProvider>();
|
||||
|
@ -47,6 +47,7 @@ class HomeWidgetProvider {
|
||||
}
|
||||
|
||||
Future<void> widgetUpdateRandomPost() async {
|
||||
if (kIsWeb || (!Platform.isAndroid && !Platform.isIOS)) return;
|
||||
final snc = await SnNetworkProvider.createOffContextClient();
|
||||
final resp = await snc.get('/cgi/co/recommendations/shuffle?take=1');
|
||||
final post = SnPost.fromJson(resp.data['data'][0]);
|
||||
|
@ -154,7 +154,6 @@ class ChatMessageInputState extends State<ChatMessageInput> {
|
||||
|
||||
void _showEmojiPicker(BuildContext context) {
|
||||
final overlay = Overlay.of(context);
|
||||
final sticker = context.read<SnStickerProvider>();
|
||||
_overlayEntry = OverlayEntry(
|
||||
builder: (context) => Positioned(
|
||||
bottom: 16 + MediaQuery.of(context).padding.bottom,
|
||||
@ -363,7 +362,7 @@ class _StickerPicker extends StatelessWidget {
|
||||
final Function? onDismiss;
|
||||
final Function(String)? onInsert;
|
||||
|
||||
const _StickerPicker({super.key, this.onDismiss, required this.originalText, this.onInsert});
|
||||
const _StickerPicker({this.onDismiss, required this.originalText, this.onInsert});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
Reference in New Issue
Block a user