Remove notification service
This commit is contained in:
@@ -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,
|
|
||||||
);
|
|
||||||
@@ -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<void> 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<void> _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<void> _initChannels() async {
|
|
||||||
await flutterLocalNotificationsPlugin
|
|
||||||
.resolvePlatformSpecificImplementation<
|
|
||||||
AndroidFlutterLocalNotificationsPlugin>()
|
|
||||||
?.createNotificationChannel(mainChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onDidReceiveNotificationResponse(
|
|
||||||
NotificationResponse notificationResponse,
|
|
||||||
) {
|
|
||||||
// TODO: complete
|
|
||||||
loggy.debug('received notification response, $notificationResponse');
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> 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<void> removeNotification(int id) async {
|
|
||||||
loggy.debug('removing notification');
|
|
||||||
await flutterLocalNotificationsPlugin.cancel(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> grantPermission() async {
|
|
||||||
final result = await flutterLocalNotificationsPlugin
|
|
||||||
.resolvePlatformSpecificImplementation<
|
|
||||||
AndroidFlutterLocalNotificationsPlugin>()
|
|
||||||
?.requestPermission();
|
|
||||||
return result ?? false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export 'notification_service.dart';
|
|
||||||
@@ -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<void> init();
|
|
||||||
|
|
||||||
void onDidReceiveNotificationResponse(
|
|
||||||
NotificationResponse notificationResponse,
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<bool> grantPermission();
|
|
||||||
|
|
||||||
Future<void> showNotification({
|
|
||||||
required int id,
|
|
||||||
required String title,
|
|
||||||
String? body,
|
|
||||||
NotificationDetails? details,
|
|
||||||
String? payload,
|
|
||||||
});
|
|
||||||
|
|
||||||
Future<void> removeNotification(int id);
|
|
||||||
}
|
|
||||||
@@ -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<void> init() async {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void onDidReceiveNotificationResponse(
|
|
||||||
NotificationResponse notificationResponse,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> removeNotification(int id) async {}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> showNotification({
|
|
||||||
required int id,
|
|
||||||
required String title,
|
|
||||||
String? body,
|
|
||||||
NotificationDetails? details,
|
|
||||||
String? payload,
|
|
||||||
}) async {}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<bool> grantPermission() async {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user