From f303cf7e2446367ebc6372917a61eeea27667c1e Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Sun, 10 Sep 2023 20:20:46 +0330 Subject: [PATCH] Remove notification service --- lib/services/notification/constants.dart | 9 -- .../local_notification_service.dart | 107 ------------------ lib/services/notification/notification.dart | 1 - .../notification/notification_service.dart | 33 ------ .../stub_notification_service.dart | 31 ----- 5 files changed, 181 deletions(-) delete mode 100644 lib/services/notification/constants.dart delete mode 100644 lib/services/notification/local_notification_service.dart delete mode 100644 lib/services/notification/notification.dart delete mode 100644 lib/services/notification/notification_service.dart delete mode 100644 lib/services/notification/stub_notification_service.dart diff --git a/lib/services/notification/constants.dart b/lib/services/notification/constants.dart deleted file mode 100644 index 5d1b2357..00000000 --- a/lib/services/notification/constants.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:flutter_local_notifications/flutter_local_notifications.dart'; - -const mainChannel = AndroidNotificationChannel( - "com.hiddify.hiddify", - "Hiddify Next", - importance: Importance.high, - enableVibration: false, - playSound: false, -); diff --git a/lib/services/notification/local_notification_service.dart b/lib/services/notification/local_notification_service.dart deleted file mode 100644 index 9fa473b3..00000000 --- a/lib/services/notification/local_notification_service.dart +++ /dev/null @@ -1,107 +0,0 @@ -import 'dart:io'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter_local_notifications/flutter_local_notifications.dart'; -import 'package:hiddify/services/notification/constants.dart'; -import 'package:hiddify/services/notification/notification_service.dart'; -import 'package:hiddify/utils/utils.dart'; - -// TODO: rewrite - -@pragma('vm:entry-point') -void notificationTapBackground(NotificationResponse notificationResponse) { - // TODO: handle action -} - -// ignore: unreachable_from_main -class LocalNotificationService with InfraLogger implements NotificationService { - LocalNotificationService(this.flutterLocalNotificationsPlugin); - - final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; - String? payload; - - @override - Future init() async { - loggy.debug('initializing'); - const initializationSettings = InitializationSettings( - android: AndroidInitializationSettings('mipmap/ic_launcher'), - linux: LinuxInitializationSettings(defaultActionName: "open"), - macOS: DarwinInitializationSettings(), - ); - - await _initDetails(); - await _initChannels(); - - await flutterLocalNotificationsPlugin.initialize( - initializationSettings, - onDidReceiveNotificationResponse: onDidReceiveNotificationResponse, - onDidReceiveBackgroundNotificationResponse: notificationTapBackground, - ); - } - - Future _initDetails() async { - if (kIsWeb || Platform.isLinux) return; - final initialDetails = - await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); - - if (initialDetails?.didNotificationLaunchApp ?? false) { - payload = initialDetails!.notificationResponse?.payload; - loggy.debug('app launched from notification, payload: $payload'); - // TODO: use payload - } - } - - Future _initChannels() async { - await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() - ?.createNotificationChannel(mainChannel); - } - - @override - void onDidReceiveNotificationResponse( - NotificationResponse notificationResponse, - ) { - // TODO: complete - loggy.debug('received notification response, $notificationResponse'); - } - - @override - Future showNotification({ - required int id, - required String title, - String? body, - NotificationDetails? details, - String? payload, - }) async { - loggy.debug('showing notification'); - await flutterLocalNotificationsPlugin.show( - id, - title, - body, - details ?? - NotificationDetails( - android: AndroidNotificationDetails( - mainChannel.id, - mainChannel.name, - ), - ), - payload: payload, - ); - } - - @override - Future removeNotification(int id) async { - loggy.debug('removing notification'); - await flutterLocalNotificationsPlugin.cancel(id); - } - - @override - Future grantPermission() async { - final result = await flutterLocalNotificationsPlugin - .resolvePlatformSpecificImplementation< - AndroidFlutterLocalNotificationsPlugin>() - ?.requestPermission(); - return result ?? false; - } -} diff --git a/lib/services/notification/notification.dart b/lib/services/notification/notification.dart deleted file mode 100644 index 7dcf27d0..00000000 --- a/lib/services/notification/notification.dart +++ /dev/null @@ -1 +0,0 @@ -export 'notification_service.dart'; diff --git a/lib/services/notification/notification_service.dart b/lib/services/notification/notification_service.dart deleted file mode 100644 index 7bda4d63..00000000 --- a/lib/services/notification/notification_service.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'dart:io'; - -import 'package:flutter_local_notifications/flutter_local_notifications.dart'; -import 'package:hiddify/services/notification/local_notification_service.dart'; -import 'package:hiddify/services/notification/stub_notification_service.dart'; - -abstract class NotificationService { - factory NotificationService() { - // HACK temporarily return stub for linux and mac as well - if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) { - return StubNotificationService(); - } - return LocalNotificationService(FlutterLocalNotificationsPlugin()); - } - - Future init(); - - void onDidReceiveNotificationResponse( - NotificationResponse notificationResponse, - ); - - Future grantPermission(); - - Future showNotification({ - required int id, - required String title, - String? body, - NotificationDetails? details, - String? payload, - }); - - Future removeNotification(int id); -} diff --git a/lib/services/notification/stub_notification_service.dart b/lib/services/notification/stub_notification_service.dart deleted file mode 100644 index ab445c29..00000000 --- a/lib/services/notification/stub_notification_service.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:flutter_local_notifications/flutter_local_notifications.dart'; -import 'package:hiddify/services/notification/notification_service.dart'; - -class StubNotificationService implements NotificationService { - @override - Future init() async { - return; - } - - @override - void onDidReceiveNotificationResponse( - NotificationResponse notificationResponse, - ) {} - - @override - Future removeNotification(int id) async {} - - @override - Future showNotification({ - required int id, - required String title, - String? body, - NotificationDetails? details, - String? payload, - }) async {} - - @override - Future grantPermission() async { - return true; - } -}