Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_local_notifications_linux] migrate to xdg-desktop-portal for notifications #1987

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions flutter_local_notifications/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';
// ignore: unnecessary_import
import 'dart:typed_data';
import 'dart:ui';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/cupertino.dart';
Expand All @@ -12,7 +13,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:http/http.dart' as http;
import 'package:image/image.dart' as image;
import 'package:path_provider/path_provider.dart';
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
Expand Down Expand Up @@ -52,10 +52,10 @@ class ReceivedNotification {
String? selectedNotificationPayload;

/// A notification action which triggers a url launch event
const String urlLaunchActionId = 'id_1';
const String urlLaunchActionId = 'id1';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what the reason behind this change? i wasn't expecting example app to require this kind of the change given the intent behind the PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, forgot to document that. I believe it didn't work, and troubleshooting indicated it was when it had an underscore.


/// A notification action which triggers a App navigation event
const String navigationActionId = 'id_3';
const String navigationActionId = 'id3';

/// Defines a iOS/MacOS notification category for text input actions.
const String darwinNotificationCategoryText = 'textCategory';
Expand Down Expand Up @@ -1153,8 +1153,12 @@ class _HomePageState extends State<HomePage> {
linux: linuxNotificationDetails,
);
await flutterLocalNotificationsPlugin.show(
id++, 'plain title', 'plain body', notificationDetails,
payload: 'item z');
id++,
'plain title',
'plain body',
notificationDetails,
payload: 'item z',
);
}

Future<void> _showNotificationWithTextAction() async {
Expand Down Expand Up @@ -2831,17 +2835,20 @@ Future<void> _showLinuxNotificationWithByteDataIcon() async {
final ByteData assetIcon = await rootBundle.load(
'icons/app_icon_density.png',
);
final image.Image? iconData = image.decodePng(
assetIcon.buffer.asUint8List().toList(),
);
final Uint8List iconBytes = iconData!.getBytes();

final Uint8List iconBytes = assetIcon.buffer.asUint8List();
final ImmutableBuffer buffer = await ImmutableBuffer.fromUint8List(iconBytes);
final ImageDescriptor descriptor = await ImageDescriptor.encoded(buffer);
final int width = descriptor.width;
final int height = descriptor.height;

final LinuxNotificationDetails linuxPlatformChannelSpecifics =
LinuxNotificationDetails(
icon: ByteDataLinuxIcon(
LinuxRawIconData(
data: iconBytes,
width: iconData.width,
height: iconData.height,
width: width,
height: height,
channels: 4, // The icon has an alpha channel
hasAlpha: true,
),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// The Linux implementation of `flutter_local_notifications`.
library flutter_local_notifications_linux;

// flutter_local_notifications_linux depends on dbus and posix
// flutter_local_notifications_linux depends on posix
// which uses FFI internally; export a stub for platforms that don't
// support FFI (e.g., web) to avoid having transitive dependencies
// break web compilation.
Expand Down
52 changes: 0 additions & 52 deletions flutter_local_notifications_linux/lib/src/dbus_wrapper.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,4 @@ class LinuxFlutterLocalNotificationsPlugin
@override
Future<LinuxServerCapabilities> getCapabilities() =>
_manager.getCapabilities();

/// Returns a [Map] with the specified notification id as the key
/// and the id, assigned by the system, as the value.
///
/// Note: the system ID is unique only within the current user session,
/// so it's undesirable to save it to persistable storage without any
/// invalidation/update. For more information, please see
/// Desktop Notifications Specification https://specifications.freedesktop.org/notification-spec/latest/ar01s02.html
@override
Future<Map<int, int>> getSystemIdMap() => _manager.getSystemIdMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,4 @@ abstract class FlutterLocalNotificationsPlatformLinux
/// Some functionality may not be implemented by the notification server,
/// conforming clients should check if it is available before using it.
Future<LinuxServerCapabilities> getCapabilities();

/// Returns a [Map] with the specified notification id as the key
/// and the id, assigned by the system, as the value.
///
/// Note: the system ID is unique only within the current user session,
/// so it's undesirable to save it to persistable storage without any
/// invalidation/update. For more information, please see
/// Desktop Notifications Specification https://specifications.freedesktop.org/notification-spec/latest/ar01s02.html
Future<Map<int, int>> getSystemIdMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,4 @@ class LinuxFlutterLocalNotificationsPlugin
assert(false);
throw UnimplementedError();
}

/// Errors on attempted calling of the stub. It exists only to satisfy
/// compile-time dependencies, and should never actually be called.
@override
Future<Map<int, int>> getSystemIdMap() async {
assert(false);
throw UnimplementedError();
}
}
61 changes: 0 additions & 61 deletions flutter_local_notifications_linux/lib/src/helpers.dart

This file was deleted.

12 changes: 1 addition & 11 deletions flutter_local_notifications_linux/lib/src/notification_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class LinuxNotificationInfo {
/// Constructs an instance of [LinuxPlatformInfoData].
const LinuxNotificationInfo({
required this.id,
required this.systemId,
this.payload,
this.actions = const <LinuxNotificationActionInfo>[],
});
Expand All @@ -21,7 +20,6 @@ class LinuxNotificationInfo {
.toList();
return LinuxNotificationInfo(
id: json['id'] as int,
systemId: json['systemId'] as int,
payload: json['payload'] as String?,
actions: actions ?? <LinuxNotificationActionInfo>[],
);
Expand All @@ -30,10 +28,6 @@ class LinuxNotificationInfo {
/// Notification id
final int id;

/// Notification id, which is returned by the system,
/// see Desktop Notifications Specification https://specifications.freedesktop.org/notification-spec/latest/
final int systemId;

/// Notification payload, that will be passed back to the app
/// when a notification is tapped on.
final String? payload;
Expand All @@ -44,7 +38,6 @@ class LinuxNotificationInfo {
/// Returns the object as a key-value map
Map<String, dynamic> toJson() => <String, dynamic>{
'id': id,
'systemId': systemId,
'payload': payload,
'actions':
actions.map((LinuxNotificationActionInfo a) => a.toJson()).toList(),
Expand All @@ -60,7 +53,6 @@ class LinuxNotificationInfo {
}) =>
LinuxNotificationInfo(
id: id ?? this.id,
systemId: systemId ?? this.systemId,
payload: payload ?? this.payload,
actions: actions ?? this.actions,
);
Expand All @@ -73,14 +65,12 @@ class LinuxNotificationInfo {

return other is LinuxNotificationInfo &&
other.id == id &&
other.systemId == systemId &&
other.payload == payload &&
listEquals(other.actions, actions);
}

@override
int get hashCode =>
id.hashCode ^ systemId.hashCode ^ payload.hashCode ^ actions.hashCode;
int get hashCode => id.hashCode ^ payload.hashCode ^ actions.hashCode;
}

/// Represents a Linux notification action information
Expand Down
Loading