windows notifications: switch from desktoats to win_toats #350

Merged
sarah merged 2 commits from wintoasts into trunk 2022-02-04 02:01:22 +00:00
1 changed files with 6 additions and 17 deletions
Showing only changes of commit 19a202a04c - Show all commits

View File

@ -31,12 +31,7 @@ class LinuxNotificationsManager implements NotificationsManager {
Future<void> notify(String message) async {
var iconPath = Uri.file(path.join(path.current, "cwtch.png"));
client
.notify(message,
appName: "cwtch",
appIcon: iconPath.toString(),
replacesId: this.previous_id)
.then((Notification value) => previous_id = value.id);
client.notify(message, appName: "cwtch", appIcon: iconPath.toString(), replacesId: this.previous_id).then((Notification value) => previous_id = value.id);
}
}
@ -48,20 +43,16 @@ class WindowsNotificationManager implements NotificationsManager {
WindowsNotificationManager() {
scheduleMicrotask(() async {
initialized = await WinToast.instance().initialize(
appName: 'cwtch',
productName: 'Cwtch',
companyName: 'Open Privacy Research Society');
initialized = await WinToast.instance().initialize(appName: 'cwtch', productName: 'Cwtch', companyName: 'Open Privacy Research Society');
});
}
Future<void> notify(String message) async {
if (initialized && !globalAppState.focus) {
if (!active) {
WinToast.instance().clear();
final toast = await WinToast.instance()
.showToast(type: ToastType.text01, title: message);
active = true;
WinToast.instance().clear();
final toast = await WinToast.instance().showToast(type: ToastType.text01, title: message);
toast?.eventStream.listen((event) {
if (event is ActivatedEvent) {
WinToast.instance().bringWindowToFront();
@ -82,15 +73,13 @@ NotificationsManager newDesktopNotificationsManager() {
client.getCapabilities();
return LinuxNotificationsManager(client);
} catch (e) {
EnvironmentConfig.debugLog(
"Attempted to access DBUS for notifications but failed. Switching off notifications.");
EnvironmentConfig.debugLog("Attempted to access DBUS for notifications but failed. Switching off notifications.");
}
} else if (Platform.isWindows) {
try {
return WindowsNotificationManager();
} catch (e) {
EnvironmentConfig.debugLog(
"Failed to create Windows desktoasts notification manager");
EnvironmentConfig.debugLog("Failed to create Windows desktoasts notification manager");
}
}
return NullNotificationsManager();