P

push_aurora

Push is a flutter package designed to handle push notifications - including background notification, alert notifications and notification taps.

EN | RU

push_aurora

Description

This plugin is an implementation of the push package for the Aurora operating system and is designed to handle push notifications.

The plugin combines the c++ platform implementation and the dart component for additional interaction with the platform part.

The original ReadMe of the push plugin: README

ReadMe of the usage example: README

Quick launch

    final pushAuroraPlugin = Push.instance;
    await PushAurora.setApplicationId("example");

Features

PushAurora

PushAurora is a dart plugin class that provides additional interactions with native code through a MethodChannel. The original Push dart class does not provide all the functionality needed to interact with native code on the Aurora operating system. PushAurora provides three static methods:

ApplicationId configuration

The plugin obtains the registration identifier of the application using the setApplicationId() method of the PushAurora class. The method should be called only after initializing the plugin. If you do not send the ID to the plugin, the application will not be registered to receive push notifications from Aurora Center. If you pass multiple IDs to the plugin sequentially, the last one transmitted will be considered relevant. After launching the application the identifier is stored in the user's data directory in the PushNotificationsApplicationId file accessible only to the current user and the current application, which corresponds to Aurora::Application::filesDir(false). You can find out more about this here. Example of using the method:

    final pushAuroraPlugin = Push.instance;
    await PushAurora.setApplicationId("example");

Application Status

An application using the plugin on the Aurora OS must explicitly transmit the application state using the handleStateChange() method of the PushAurora class. This is necessary to determine the notification type: background or foreground. The current state of the application is expected as the method argument (AppLifecycleState).

If the resumed status is transmitted, the plugin will assume that the application is open in the foreground and will not show a system notification. In all other cases, the plugin will show a system notification on the device and provide the ability to process it using OnBackgroundMessage.

If you do not transmit the current state of the application to the plugin, all incoming push notifications are considered background, therefore they will be displayed and processed using OnBackgroundMessage. In this case, the onMessage handlers will not be called.

Example of using handleStateChange:

import 'package:push_aurora/push_aurora.dart';

AppLifecycleListener(
    onStateChange: (AppLifecycleState state) async =>
        await PushAurora.handleStateChange(state)
);

PushAurora.handleStateChange(AppLifecycleState.resumed);

A separate call to handleStateChange is necessary because AppLifecycleListener does not respond to the application launch and does not inform the plugin about it.

Registration errors information

The PushAurora class allows you to receive a code and description of the last known error in registering an application to receive push notifications. To do this you can use the getRegistrationFailureError() method. It accesses the error() and ErrorMessage() methods of the Aurora::PushNotifications::Client class and returns the code and description of the last error in String format in case of an error or null in case there are no errors. Note that the method returns information about only one - the latest error. Error codes and descriptions can be found in the official documentation in the Client class description.

Pigeon Platform Components

This information is for plugin developers only.

The original plugin uses code generated using Pigeon for interacting with the platform part. However, if you generate the platform part for use in the Aurora OS, compilation errors will appear.

This is because Pigeon generates the RemoteMessage class earlier than the Notification class. This leads to a compilation error because RemoteMessage uses Notification and the order of classes in the file is important in C++. You need to swap the RemoteMessage and Notification classes in the .h and .cpp files yourself to solve this problem.

Build and Install

pubspec.yaml

dependencies:
    push: ^3.3.3
    push_aurora:
        git:
            url: https://developer.auroraos.ru/git/flutter/flutter-community-plugins/push_aurora.git

main.cpp

#include "generated_plugin_registrant.h"
#include <flutter/flutter_compatibility_qt.h> // <--- enable QT

int main(int argc, char *argv[]) {
    aurora::FlutterApp app(argc, argv);
    aurora::EnableQtCompatibility(); // <--- enable QT
    return app.exec();
}

.desktop

%u argument and DBus service

By default, the app will start if a background notification has arrived. To prevent the app from launching automatically when background notifications are received, add the %u argument to the line of the app launch command. In this case, you will need to click on the notification to launch the application.

Exec=/usr/bin/ru.aurora.push_aurora_example %u

In addition, the following lines must be added to ensure that the DBus service works properly:

[X-Application]
Permissions=PushNotifications;UserDirs

ExecDBus=/usr/bin/ru.aurora.push_aurora_example
ExportDBusInterfaces=ru.aurora.NotificationTapHandler

Disabling auto-generation

To prevent the previous .desktop settings from being lost in the next app build, remove the line responsible for auto-generating the file:

# This file will be recreated at the next build. To avoid this, delete this line.

Contents

Compatibility

  • Aurora OS: 5.1.3+
  • Flutter 3.32.7

Usage Rules

  • The source code of the project is provided under the license, that allows it to be used in third-party applications.
  • To participate in the development of the project, please read the contributor agreement. If you plan to contribute your own source code to the project, you will need to accept the CLA agreement.
  • For information about contributors see AUTHORS.
  • Code of conduct is a current set of rules of the Open Mobile Platform which informs you how we expect the members of the community will interact while contributing and communicating.