2021-04-13 17:45:18 +00:00
|
|
|
import 'package:comunic/ui/dialogs/alert_dialog.dart';
|
2021-04-27 08:10:13 +00:00
|
|
|
import 'package:comunic/utils/flutter_utils.dart';
|
2021-04-13 17:45:18 +00:00
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-04-13 15:56:55 +00:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
|
|
|
/// Independent push notifications helper
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
class IndependentPushNotificationsHelper {
|
|
|
|
static const platform = const MethodChannel(
|
|
|
|
"org.communiquons.comunic/independent-push-notifications-service");
|
|
|
|
|
2021-04-13 17:45:18 +00:00
|
|
|
/// Check if a pre-configuration is required for an application
|
|
|
|
static Future<bool> needPreConfiguration() async {
|
|
|
|
return await platform.invokeMethod("needPreConfiguration");
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:56:55 +00:00
|
|
|
/// Call this method to prepare the application for background refresh by
|
|
|
|
/// requesting appropriate permissions, configuring battery optimization...
|
|
|
|
///
|
|
|
|
/// Throws an Exception in case of failure
|
2021-04-13 17:45:18 +00:00
|
|
|
static Future<void> preConfigure(BuildContext context) async {
|
|
|
|
await alert(context,
|
|
|
|
tr("Battery optimization settings will appear. To make push notifications service work better, please disable battery optimization for Comunic..."));
|
|
|
|
|
2021-04-13 15:56:55 +00:00
|
|
|
await platform.invokeMethod("preConfigure");
|
|
|
|
}
|
2021-04-14 16:03:27 +00:00
|
|
|
|
|
|
|
/// Configure independent push notification services with a pull URL
|
2022-03-10 18:39:57 +00:00
|
|
|
static Future<void> configure(String? wsURL) async {
|
2021-04-14 16:03:27 +00:00
|
|
|
await platform.invokeMethod("configure", wsURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Disable independent push notifications service
|
|
|
|
static Future<void> disable() async {
|
2021-04-27 08:10:13 +00:00
|
|
|
if (isAndroid) await platform.invokeMethod("disable");
|
2021-04-14 16:03:27 +00:00
|
|
|
}
|
2021-04-13 15:56:55 +00:00
|
|
|
}
|