add desktoasts windows notifications #336
|
@ -70,7 +70,7 @@ class FlwtchState extends State<Flwtch> {
|
||||||
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, newDesktopNotificationsManager(), globalAppState, globalServersList);
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, newDesktopNotificationsManager(), globalAppState, globalServersList);
|
||||||
cwtch = CwtchFfi(cwtchNotifier);
|
cwtch = CwtchFfi(cwtchNotifier);
|
||||||
} else {
|
} else {
|
||||||
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState, globalServersList);
|
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, newDesktopNotificationsManager(), globalAppState, globalServersList);
|
||||||
cwtch = CwtchFfi(cwtchNotifier);
|
cwtch = CwtchFfi(cwtchNotifier);
|
||||||
}
|
}
|
||||||
print("initState: invoking cwtch.Start()");
|
print("initState: invoking cwtch.Start()");
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:desktoasts/desktoasts.dart';
|
||||||
import 'package:desktop_notifications/desktop_notifications.dart';
|
import 'package:desktop_notifications/desktop_notifications.dart';
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
|
import 'config.dart';
|
||||||
|
|
||||||
// NotificationsManager provides a wrapper around platform specific notifications logic.
|
// NotificationsManager provides a wrapper around platform specific notifications logic.
|
||||||
abstract class NotificationsManager {
|
abstract class NotificationsManager {
|
||||||
Future<void> notify(String message);
|
Future<void> notify(String message);
|
||||||
|
@ -26,15 +31,47 @@ class LinuxNotificationsManager implements NotificationsManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows Notification Manager uses https://pub.dev/packages/desktoasts to implement
|
||||||
|
// windows notifications
|
||||||
|
class WindowsNotificationManager implements NotificationsManager {
|
||||||
|
late ToastService service;
|
||||||
|
|
||||||
|
WindowsNotificationManager() {
|
||||||
|
service = new ToastService(
|
||||||
|
appName: 'Cwtch',
|
||||||
|
companyName: 'Open Privacy Research Society',
|
||||||
|
productName: 'Cwtch',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> notify(String message) async {
|
||||||
|
Toast toast = new Toast(
|
||||||
|
type: ToastType.text01,
|
||||||
|
title: 'Cwtch',
|
||||||
|
subtitle: message,
|
||||||
|
);
|
||||||
|
service.show(toast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NotificationsManager newDesktopNotificationsManager() {
|
NotificationsManager newDesktopNotificationsManager() {
|
||||||
try {
|
if (Platform.isLinux) {
|
||||||
// Test that we can actually access DBUS. Otherwise return a null
|
try {
|
||||||
// notifications manager...
|
// Test that we can actually access DBUS. Otherwise return a null
|
||||||
NotificationsClient client = NotificationsClient();
|
// notifications manager...
|
||||||
client.getCapabilities();
|
NotificationsClient client = NotificationsClient();
|
||||||
return LinuxNotificationsManager(client);
|
client.getCapabilities();
|
||||||
} catch (e) {
|
return LinuxNotificationsManager(client);
|
||||||
print("Attempted to access DBUS for notifications but failed. Switching off notifications.");
|
} catch (e) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NullNotificationsManager();
|
return NullNotificationsManager();
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.2"
|
version: "0.5.2"
|
||||||
|
desktoasts:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: desktoasts
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.0.2"
|
||||||
desktop_notifications:
|
desktop_notifications:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -44,6 +44,7 @@ dependencies:
|
||||||
file_picker: ^4.3.2
|
file_picker: ^4.3.2
|
||||||
file_picker_desktop: ^1.1.0
|
file_picker_desktop: ^1.1.0
|
||||||
url_launcher: ^6.0.12
|
url_launcher: ^6.0.12
|
||||||
|
desktoasts: ^0.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
msix: ^2.1.3
|
msix: ^2.1.3
|
||||||
|
|
|
@ -6,9 +6,12 @@
|
||||||
|
|
||||||
#include "generated_plugin_registrant.h"
|
#include "generated_plugin_registrant.h"
|
||||||
|
|
||||||
|
#include <desktoasts/desktoasts_plugin.h>
|
||||||
#include <url_launcher_windows/url_launcher_windows.h>
|
#include <url_launcher_windows/url_launcher_windows.h>
|
||||||
|
|
||||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||||
|
DesktoastsPluginRegisterWithRegistrar(
|
||||||
|
registry->GetRegistrarForPlugin("DesktoastsPlugin"));
|
||||||
UrlLauncherWindowsRegisterWithRegistrar(
|
UrlLauncherWindowsRegisterWithRegistrar(
|
||||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
list(APPEND FLUTTER_PLUGIN_LIST
|
list(APPEND FLUTTER_PLUGIN_LIST
|
||||||
|
desktoasts
|
||||||
url_launcher_windows
|
url_launcher_windows
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue