remove notification debugging and linux notifier
continuous-integration/drone/pr Build was killed
Details
continuous-integration/drone/pr Build was killed
Details
This commit is contained in:
parent
c66e3583ab
commit
dabca870fb
|
@ -57,22 +57,33 @@ class WindowsNotificationManager implements NotificationsManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinuxNotificationsManager uses the desktop_notifications package to implement
|
class NotificationPayload {
|
||||||
// the standard dbus-powered linux desktop notifications.
|
late String profileOnion;
|
||||||
class LinuxNotificationsManager implements NotificationsManager {
|
late int convoId;
|
||||||
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) {
|
NotificationPayload(String po, int cid) {
|
||||||
this.client = linux_notifications.NotificationsClient();
|
profileOnion = po;
|
||||||
this.notificationSelectConvo = notificationSelectConvo;
|
convoId = cid;
|
||||||
scheduleMicrotask(() async {
|
|
||||||
assetsPath = await detectLinuxAssetsPath();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NotificationPayload.fromJson(Map<String, dynamic> json)
|
||||||
|
: profileOnion = json['profileOnion'],
|
||||||
|
convoId = json['convoId'];
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'profileOnion': profileOnion,
|
||||||
|
'convoId': convoId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
late String linuxAssetsPath;
|
||||||
|
|
||||||
|
|
||||||
// Cwtch can install in non flutter supported ways on linux, this code detects where the assets are on Linux
|
// Cwtch can install in non flutter supported ways on linux, this code detects where the assets are on Linux
|
||||||
Future<String> detectLinuxAssetsPath() async {
|
Future<String> detectLinuxAssetsPath() async {
|
||||||
var devStat = FileStat.stat("assets");
|
var devStat = FileStat.stat("assets");
|
||||||
|
@ -92,116 +103,42 @@ class LinuxNotificationsManager implements NotificationsManager {
|
||||||
return "";
|
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;
|
|
||||||
|
|
||||||
NotificationPayload(String po, int cid) {
|
|
||||||
profileOnion = po;
|
|
||||||
convoId = cid;
|
|
||||||
}
|
|
||||||
|
|
||||||
NotificationPayload.fromJson(Map<String, dynamic> json)
|
|
||||||
: profileOnion = json['profileOnion'],
|
|
||||||
convoId = json['convoId'];
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
|
||||||
'profileOnion': profileOnion,
|
|
||||||
'convoId': convoId,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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?
|
|
||||||
class NixNotificationManager implements NotificationsManager {
|
|
||||||
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
|
|
||||||
late Future<void> Function(String, int) notificationSelectConvo;
|
|
||||||
late String linuxAssetsPath;
|
|
||||||
|
|
||||||
|
|
||||||
// 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 "";
|
|
||||||
}
|
|
||||||
|
|
||||||
NixNotificationManager(Future<void> Function(String, int) notificationSelectConvo) {
|
NixNotificationManager(Future<void> Function(String, int) notificationSelectConvo) {
|
||||||
this.notificationSelectConvo = notificationSelectConvo;
|
this.notificationSelectConvo = notificationSelectConvo;
|
||||||
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
scheduleMicrotask(() async {
|
scheduleMicrotask(() async {
|
||||||
|
|
||||||
if (Platform.isLinux) {
|
if (Platform.isLinux) {
|
||||||
linuxAssetsPath = await detectLinuxAssetsPath();
|
linuxAssetsPath = await detectLinuxAssetsPath();
|
||||||
print("NixNotificationManager found LinuxAssetsPath!: $linuxAssetsPath");
|
|
||||||
} else {
|
} else {
|
||||||
linuxAssetsPath = "";
|
linuxAssetsPath = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
final MacOSInitializationSettings initializationSettingsMacOS = MacOSInitializationSettings(defaultPresentSound: false);
|
final MacOSInitializationSettings initializationSettingsMacOS = MacOSInitializationSettings(defaultPresentSound: false);
|
||||||
var linuxIcon = FilePathLinuxIcon( path.join(linuxAssetsPath, 'assets/knott.png'));
|
var linuxIcon = FilePathLinuxIcon( path.join(linuxAssetsPath, 'assets/knott.png'));
|
||||||
print("NixNotificationManager make linux settings");
|
|
||||||
|
|
||||||
final LinuxInitializationSettings initializationSettingsLinux =
|
final LinuxInitializationSettings initializationSettingsLinux =
|
||||||
LinuxInitializationSettings(defaultActionName: 'Open notification', defaultIcon: linuxIcon, defaultSuppressSound: true);
|
LinuxInitializationSettings(defaultActionName: 'Open notification', defaultIcon: linuxIcon, defaultSuppressSound: true);
|
||||||
|
|
||||||
print("NixNotificationManager InitializationSettings");
|
|
||||||
|
|
||||||
final InitializationSettings initializationSettings = InitializationSettings(android: null, iOS: null, macOS: initializationSettingsMacOS, linux: initializationSettingsLinux);
|
final InitializationSettings initializationSettings = InitializationSettings(android: null, iOS: null, macOS: initializationSettingsMacOS, linux: initializationSettingsLinux);
|
||||||
|
|
||||||
print("NixNotificationManager mac req perms");
|
|
||||||
|
|
||||||
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<MacOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
|
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<MacOSFlutterLocalNotificationsPlugin>()?.requestPermissions(
|
||||||
alert: true,
|
alert: true,
|
||||||
badge: false,
|
badge: false,
|
||||||
sound: false,
|
sound: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
print("NixNotificationManager initialize...");
|
|
||||||
await flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: selectNotification);
|
await flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: selectNotification);
|
||||||
print("NixNotificationManager initialized!!!");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> notify(String message, String profile, int conversationId) async {
|
Future<void> notify(String message, String profile, int conversationId) async {
|
||||||
print("notify if !globalAppState.focus so do? ${!globalAppState.focus}");
|
|
||||||
if (!globalAppState.focus) {
|
if (!globalAppState.focus) {
|
||||||
|
|
||||||
print("do notify!");
|
|
||||||
|
|
||||||
// Warning: Only use title field on Linux, body field will render links as clickable
|
// Warning: Only use title field on Linux, body field will render links as clickable
|
||||||
await flutterLocalNotificationsPlugin.show(0, message, '',
|
await flutterLocalNotificationsPlugin.show(0, message, '',
|
||||||
NotificationDetails(linux: LinuxNotificationDetails(suppressSound: true, category: LinuxNotificationCategory.imReceived(), icon: FilePathLinuxIcon(path.join(linuxAssetsPath, 'assets/knott.png')))),
|
NotificationDetails(linux: LinuxNotificationDetails(suppressSound: true, category: LinuxNotificationCategory.imReceived(), icon: FilePathLinuxIcon(path.join(linuxAssetsPath, 'assets/knott.png')))),
|
||||||
payload: jsonEncode(NotificationPayload(profile, conversationId)));
|
payload: jsonEncode(NotificationPayload(profile, conversationId)));
|
||||||
|
|
||||||
print("done notify");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue