Compare commits
7 changed files with 78 additions and 133 deletions
|
|
@ -1,13 +1,10 @@
|
||||||
import "dart:io";
|
import "dart:io";
|
||||||
|
|
||||||
import "package:flutter/foundation.dart";
|
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:nexus/controllers/portal.dart";
|
|
||||||
import "package:nexus/main.dart";
|
import "package:nexus/main.dart";
|
||||||
import "package:flutter_local_notifications/flutter_local_notifications.dart";
|
import "package:flutter_local_notifications/flutter_local_notifications.dart";
|
||||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||||
import "package:nexus/pages/notifications.dart";
|
import "package:nexus/pages/notifications.dart";
|
||||||
import "package:xdg_desktop_portal/xdg_desktop_portal.dart";
|
|
||||||
|
|
||||||
class NotificationController
|
class NotificationController
|
||||||
extends AsyncNotifier<FlutterLocalNotificationsPlugin> {
|
extends AsyncNotifier<FlutterLocalNotificationsPlugin> {
|
||||||
|
|
@ -15,77 +12,40 @@ class NotificationController
|
||||||
Future<FlutterLocalNotificationsPlugin> build() async {
|
Future<FlutterLocalNotificationsPlugin> build() async {
|
||||||
final notifications = FlutterLocalNotificationsPlugin();
|
final notifications = FlutterLocalNotificationsPlugin();
|
||||||
|
|
||||||
if (!Platform.isLinux) {
|
final darwin = DarwinInitializationSettings();
|
||||||
final darwin = DarwinInitializationSettings();
|
|
||||||
|
|
||||||
await notifications.initialize(
|
await notifications.initialize(
|
||||||
settings: .new(
|
settings: .new(
|
||||||
windows: .new(
|
windows: .new(
|
||||||
appName: "Nexus",
|
appName: "Nexus",
|
||||||
appUserModelId: "nexus.federated.nexus",
|
appUserModelId: "nexus.federated.nexus",
|
||||||
guid: "dde78daf-130f-4e46-a80a-e31deeab45d7",
|
guid: "dde78daf-130f-4e46-a80a-e31deeab45d7",
|
||||||
),
|
|
||||||
android: .new("ic_launcher_foreground"),
|
|
||||||
iOS: darwin,
|
|
||||||
macOS: darwin,
|
|
||||||
),
|
),
|
||||||
onDidReceiveNotificationResponse: (details) {
|
android: .new("ic_launcher_foreground"),
|
||||||
if (details.payload case final eventId?) {
|
iOS: darwin,
|
||||||
if (navigatorKey.currentContext case final context?) {
|
macOS: darwin,
|
||||||
Navigator.of(context).push(
|
linux: .new(defaultActionName: "Open"),
|
||||||
MaterialPageRoute(
|
),
|
||||||
builder: (_) => NotificationsPage(
|
onDidReceiveNotificationResponse: (details) {
|
||||||
highlightedEventId: eventId,
|
if (details.payload case final eventId?) {
|
||||||
defaultToAllNotifications: true,
|
if (navigatorKey.currentContext case final context?) {
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isLinux) {
|
|
||||||
final portal = await ref.watch(PortalController.provider.future);
|
|
||||||
|
|
||||||
portal.notification.actionInvoked.listen((event) {
|
|
||||||
if (event.action != "app.event") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (navigatorKey.currentContext case final context?) {
|
|
||||||
if (context.mounted) {
|
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => NotificationsPage(
|
builder: (_) => NotificationsPage(
|
||||||
highlightedEventId: event.id,
|
highlightedEventId: eventId,
|
||||||
defaultToAllNotifications: true,
|
defaultToAllNotifications: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
}
|
);
|
||||||
|
|
||||||
ref.onDispose(() {
|
|
||||||
// The portal client owns its D-Bus connection.
|
|
||||||
if (Platform.isLinux) {
|
|
||||||
ref.read(PortalController.provider.future).then((portal) {
|
|
||||||
portal.close();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return notifications;
|
return notifications;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> requestPermissions() async {
|
Future<bool> requestPermissions() async {
|
||||||
if (Platform.isLinux) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final controller = await future;
|
final controller = await future;
|
||||||
|
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
|
|
@ -122,41 +82,31 @@ class NotificationController
|
||||||
String? payload,
|
String? payload,
|
||||||
}) async {
|
}) async {
|
||||||
debugPrint("Sending notification for $id");
|
debugPrint("Sending notification for $id");
|
||||||
|
final notificationDetails = NotificationDetails(
|
||||||
|
android: .new(
|
||||||
|
"messages",
|
||||||
|
"Messages",
|
||||||
|
largeIcon: icon == null ? null : FilePathAndroidBitmap(icon.path),
|
||||||
|
),
|
||||||
|
linux: .new(
|
||||||
|
category: LinuxNotificationCategory.imReceived,
|
||||||
|
defaultActionName: "app.event",
|
||||||
|
icon: icon == null ? null : FilePathLinuxIcon(icon.path),
|
||||||
|
),
|
||||||
|
// TODO: See if icons can be added to iOS, macOS, and Windows notifications (#68)
|
||||||
|
iOS: .new(),
|
||||||
|
macOS: .new(),
|
||||||
|
windows: .new(),
|
||||||
|
);
|
||||||
|
|
||||||
if (Platform.isLinux) {
|
final controller = await future;
|
||||||
final portal = await ref.read(PortalController.provider.future);
|
await controller.show(
|
||||||
|
id: id,
|
||||||
await portal.notification.addNotification(
|
title: title,
|
||||||
id.toString(),
|
body: body,
|
||||||
title: title,
|
notificationDetails: notificationDetails,
|
||||||
body: body,
|
payload: payload,
|
||||||
icon: icon == null ? null : XdgNotificationIconFile(icon.path),
|
);
|
||||||
defaultAction: "app.event",
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
final notificationDetails = NotificationDetails(
|
|
||||||
android: .new(
|
|
||||||
"messages",
|
|
||||||
"Messages",
|
|
||||||
largeIcon: icon == null ? null : FilePathAndroidBitmap(icon.path),
|
|
||||||
),
|
|
||||||
// TODO: See if icons can be added to iOS, macOS, and Windows
|
|
||||||
// notifications (#68)
|
|
||||||
iOS: .new(),
|
|
||||||
macOS: .new(),
|
|
||||||
windows: .new(),
|
|
||||||
);
|
|
||||||
|
|
||||||
final controller = await future;
|
|
||||||
|
|
||||||
await controller.show(
|
|
||||||
id: id,
|
|
||||||
title: title,
|
|
||||||
body: body,
|
|
||||||
notificationDetails: notificationDetails,
|
|
||||||
payload: payload,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final provider =
|
static final provider =
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
|
||||||
import "package:xdg_desktop_portal/xdg_desktop_portal.dart";
|
|
||||||
|
|
||||||
class PortalController extends AsyncNotifier<XdgDesktopPortalClient> {
|
|
||||||
@override
|
|
||||||
Future<XdgDesktopPortalClient> build() async {
|
|
||||||
final portal = XdgDesktopPortalClient();
|
|
||||||
await portal.registerApplication("nexus.federated.nexus");
|
|
||||||
|
|
||||||
return portal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static final provider =
|
|
||||||
AsyncNotifierProvider<PortalController, XdgDesktopPortalClient>(
|
|
||||||
PortalController.new,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -8,4 +8,6 @@ Terminal=false
|
||||||
Type=Application
|
Type=Application
|
||||||
Categories=Chat;Network;InstantMessaging;
|
Categories=Chat;Network;InstantMessaging;
|
||||||
MimeType=x-scheme-handler/nexus.federated.nexus;
|
MimeType=x-scheme-handler/nexus.federated.nexus;
|
||||||
DBusActivatable=true
|
StartupNotify=true
|
||||||
|
DBusActivatable=true
|
||||||
|
X-GNOME-UsesNotifications=true
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
[D-BUS Service]
|
[D-BUS Service]
|
||||||
Name=nexus.federated.nexus
|
Name=nexus.federated.nexus
|
||||||
Exec=/usr/bin/env nexus
|
Exec=/usr/bin/env FLUTTER_HEADLESS=1 nexus
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ flutter.buildFlutterApplication {
|
||||||
navigation_rail_m3e = "sha256-+2awDTQnK58gGRY1nuHckG/jjxarsYSRu9ovR4i4TEc=";
|
navigation_rail_m3e = "sha256-+2awDTQnK58gGRY1nuHckG/jjxarsYSRu9ovR4i4TEc=";
|
||||||
unifiedpush_linux = "sha256-aIF/8oabSuuZo7K6qr4r7UBmf57qgoGAXyJ40fdntuQ=";
|
unifiedpush_linux = "sha256-aIF/8oabSuuZo7K6qr4r7UBmf57qgoGAXyJ40fdntuQ=";
|
||||||
unifiedpush_platform_interface = "sha256-aIF/8oabSuuZo7K6qr4r7UBmf57qgoGAXyJ40fdntuQ=";
|
unifiedpush_platform_interface = "sha256-aIF/8oabSuuZo7K6qr4r7UBmf57qgoGAXyJ40fdntuQ=";
|
||||||
xdg_desktop_portal = "sha256-S6AHWHg1TDT4RoBm6S5E9D1yWy7nYnuqzPTy735M6Xw=";
|
flutter_local_notifications_linux = "sha256-I1X+Taw4+hxDHOUxCcqiWoJbZJqbrdVUXUC0vj1Adjc=";
|
||||||
|
flutter_local_notifications_platform_interface = "sha256-I1X+Taw4+hxDHOUxCcqiWoJbZJqbrdVUXUC0vj1Adjc=";
|
||||||
};
|
};
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
|
|
|
||||||
37
pubspec.lock
37
pubspec.lock
|
|
@ -495,21 +495,23 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "22.3.0"
|
version: "22.3.0"
|
||||||
flutter_local_notifications_linux:
|
flutter_local_notifications_linux:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_local_notifications_linux
|
path: flutter_local_notifications_linux
|
||||||
sha256: "9ca97e63776f29ab1b955725c09999fc2c150523269db150c39274f2a43c5a8b"
|
ref: "quad/feat/xdg-portal-notifs"
|
||||||
url: "https://pub.dev"
|
resolved-ref: d853ff4997f6dd2b9ecdc53d37fb337cebe63863
|
||||||
source: hosted
|
url: "https://github.com/Henry-Hiles/flutter_local_notifications"
|
||||||
version: "8.0.1"
|
source: git
|
||||||
|
version: "9.0.0-dev.1"
|
||||||
flutter_local_notifications_platform_interface:
|
flutter_local_notifications_platform_interface:
|
||||||
dependency: transitive
|
dependency: "direct overridden"
|
||||||
description:
|
description:
|
||||||
name: flutter_local_notifications_platform_interface
|
path: flutter_local_notifications_platform_interface
|
||||||
sha256: "43c3761d916c9bd3d5c7ebbc44d82f4990329840c0c5d62ad5260cc1b5d399bd"
|
ref: "quad/feat/xdg-portal-notifs"
|
||||||
url: "https://pub.dev"
|
resolved-ref: d853ff4997f6dd2b9ecdc53d37fb337cebe63863
|
||||||
source: hosted
|
url: "https://github.com/Henry-Hiles/flutter_local_notifications"
|
||||||
version: "12.2.0"
|
source: git
|
||||||
|
version: "13.0.0-dev.1"
|
||||||
flutter_local_notifications_web:
|
flutter_local_notifications_web:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -1743,13 +1745,12 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.2"
|
version: "0.5.2"
|
||||||
xdg_desktop_portal:
|
xdg_desktop_portal:
|
||||||
dependency: "direct main"
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
path: "."
|
name: xdg_desktop_portal
|
||||||
ref: HEAD
|
sha256: "4fae74b6ed63a449d4c796a74265cebdd912c390336dedc06d705142f3b939d7"
|
||||||
resolved-ref: "6d070b677f908b01065b4dce79ddc9a208daadbf"
|
url: "https://pub.dev"
|
||||||
url: "https://github.com/Henry-Hiles/xdg_desktop_portal.dart"
|
source: hosted
|
||||||
source: git
|
|
||||||
version: "0.1.14"
|
version: "0.1.14"
|
||||||
xdg_directories:
|
xdg_directories:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
|
|
|
||||||
14
pubspec.yaml
14
pubspec.yaml
|
|
@ -35,6 +35,16 @@ dependency_overrides:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/appelladev/linkify
|
url: https://github.com/appelladev/linkify
|
||||||
ref: fix/consecutive-periods-loose-url
|
ref: fix/consecutive-periods-loose-url
|
||||||
|
flutter_local_notifications_linux:
|
||||||
|
git:
|
||||||
|
url: https://github.com/Henry-Hiles/flutter_local_notifications
|
||||||
|
ref: quad/feat/xdg-portal-notifs
|
||||||
|
path: flutter_local_notifications_linux
|
||||||
|
flutter_local_notifications_platform_interface:
|
||||||
|
git:
|
||||||
|
url: https://github.com/Henry-Hiles/flutter_local_notifications
|
||||||
|
ref: quad/feat/xdg-portal-notifs
|
||||||
|
path: flutter_local_notifications_platform_interface
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|
@ -89,10 +99,8 @@ dependencies:
|
||||||
unifiedpush: 6.2.0
|
unifiedpush: 6.2.0
|
||||||
unifiedpush_storage_shared_preferences: 1.0.0
|
unifiedpush_storage_shared_preferences: 1.0.0
|
||||||
flutter_local_notifications: 22.3.0
|
flutter_local_notifications: 22.3.0
|
||||||
|
flutter_local_notifications_linux: 8.0.1
|
||||||
material_emoji_picker: 1.1.1
|
material_emoji_picker: 1.1.1
|
||||||
xdg_desktop_portal:
|
|
||||||
git:
|
|
||||||
url: https://github.com/Henry-Hiles/xdg_desktop_portal.dart
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: 2.16.1
|
build_runner: 2.16.1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue