remove notification debugging and linux notifier

flutter3_notify
Dan Ballard 3 months ago
parent 9857dff9a3
commit 531595e9e9
  1. 75
      lib/notification_manager.dart

@ -57,52 +57,6 @@ class WindowsNotificationManager implements NotificationsManager {
}
}
// LinuxNotificationsManager uses the desktop_notifications package to implement
// the standard dbus-powered linux desktop notifications.
class LinuxNotificationsManager implements NotificationsManager {
int previous_id = 0;
late linux_notifications.NotificationsClient client;
late Future<void> Function(String, int) notificationSelectConvo;
late String assetsPath;
LinuxNotificationsManager(Future<void> Function(String, int) notificationSelectConvo) {
this.client = linux_notifications.NotificationsClient();
this.notificationSelectConvo = notificationSelectConvo;
scheduleMicrotask(() async {
assetsPath = await detectLinuxAssetsPath();
});
}
// Cwtch can install in non flutter supported ways on linux, this code detects where the assets are on Linux
Future<String> detectLinuxAssetsPath() async {
var devStat = FileStat.stat("assets");
var localStat = FileStat.stat("data/flutter_assets");
var homeStat = FileStat.stat((Platform.environment["HOME"] ?? "") + "/.local/share/cwtch/data/flutter_assets");
var rootStat = FileStat.stat("/usr/share/cwtch/data/flutter_assets");
if ((await devStat).type == FileSystemEntityType.directory) {
return Directory.current.path; //appPath;
} else if ((await localStat).type == FileSystemEntityType.directory) {
return path.join(Directory.current.path, "data/flutter_assets/");
} else if ((await homeStat).type == FileSystemEntityType.directory) {
return (Platform.environment["HOME"] ?? "") + "/.local/share/cwtch/data/flutter_assets/";
} else if ((await rootStat).type == FileSystemEntityType.directory) {
return "/usr/share/cwtch/data/flutter_assets/";
}
return "";
}
Future<void> notify(String message, String profile, int conversationId) async {
var iconPath = Uri.file(path.join(assetsPath, "assets/knott.png"));
client.notify(message, appName: "cwtch", appIcon: iconPath.toString(), replacesId: this.previous_id).then((linux_notifications.Notification value) async {
previous_id = value.id;
if ((await value.closeReason) == linux_notifications.NotificationClosedReason.dismissed) {
this.notificationSelectConvo(profile, conversationId);
}
});
}
}
class NotificationPayload {
late String profileOnion;
late int convoId;
@ -122,9 +76,8 @@ class NotificationPayload {
};
}
// FlutterLocalNotificationsPlugin based NotificationManager that handles MacOS
// Todo: work with author to allow settings of asset_path so we can use this for Linux and deprecate the LinuxNotificationManager
// Todo: it can also handle Android, do we want to migrate away from our manual solution?
// FlutterLocalNotificationsPlugin based NotificationManager that handles MacOS and Linux
// TODO: Windows support is being worked on, check back and migrate to that too when it lands
class NixNotificationManager implements NotificationsManager {
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
late Future<void> Function(String, int) notificationSelectConvo;
@ -133,16 +86,16 @@ class NixNotificationManager implements NotificationsManager {
// Cwtch can install in non flutter supported ways on linux, this code detects where the assets are on Linux
Future<String> detectLinuxAssetsPath() async {
//var devStat = FileStat.stat("assets");
//var localStat = FileStat.stat("data/flutter_assets");
var devStat = FileStat.stat("assets");
var localStat = FileStat.stat("data/flutter_assets");
var homeStat = FileStat.stat((Platform.environment["HOME"] ?? "") + "/.local/share/cwtch/data/flutter_assets");
var rootStat = FileStat.stat("/usr/share/cwtch/data/flutter_assets");
/*if ((await devStat).type == FileSystemEntityType.directory) {
if ((await devStat).type == FileSystemEntityType.directory) {
return Directory.current.path; //appPath;
} else if ((await localStat).type == FileSystemEntityType.directory) {
return path.join(Directory.current.path, "data/flutter_assets/");
} else */if ((await homeStat).type == FileSystemEntityType.directory) {
} else if ((await homeStat).type == FileSystemEntityType.directory) {
return (Platform.environment["HOME"] ?? "") + "/.local/share/cwtch/data/flutter_assets/";
} else if ((await rootStat).type == FileSystemEntityType.directory) {
return "/usr/share/cwtch/data/flutter_assets/";
@ -154,54 +107,38 @@ class NixNotificationManager implements NotificationsManager {
this.notificationSelectConvo = notificationSelectConvo;
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
scheduleMicrotask(() async {
if (Platform.isLinux) {
linuxAssetsPath = await detectLinuxAssetsPath();
print("NixNotificationManager found LinuxAssetsPath!: $linuxAssetsPath");
} else {
linuxAssetsPath = "";
}
final MacOSInitializationSettings initializationSettingsMacOS = MacOSInitializationSettings(defaultPresentSound: false);
var linuxIcon = FilePathLinuxIcon( path.join(linuxAssetsPath, 'assets/knott.png'));
print("NixNotificationManager make linux settings");
final LinuxInitializationSettings initializationSettingsLinux =
LinuxInitializationSettings(defaultActionName: 'Open notification', defaultIcon: linuxIcon, defaultSuppressSound: true);
print("NixNotificationManager InitializationSettings");
final InitializationSettings initializationSettings = InitializationSettings(android: null, iOS: null, macOS: initializationSettingsMacOS, linux: initializationSettingsLinux);
print("NixNotificationManager mac req perms");
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<MacOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
alert: true,
badge: false,
sound: false,
);
print("NixNotificationManager initialize...");
await flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: selectNotification);
print("NixNotificationManager initialized!!!");
});
}
Future<void> notify(String message, String profile, int conversationId) async {
print("notify if !globalAppState.focus so do? ${!globalAppState.focus}");
if (!globalAppState.focus) {
print("do notify!");
// Warning: Only use title field on Linux, body field will render links as clickable
await flutterLocalNotificationsPlugin.show(0, message, '',
NotificationDetails(linux: LinuxNotificationDetails(suppressSound: true, category: LinuxNotificationCategory.imReceived(), icon: FilePathLinuxIcon(path.join(linuxAssetsPath, 'assets/knott.png')))),
payload: jsonEncode(NotificationPayload(profile, conversationId)));
print("done notify");
}
}

Loading…
Cancel
Save