Abrova
☰ Docs menu · Computers (macOS, Windows, Linux)

Computers (macOS, Windows, Linux)

abrova_push_desktop 0.1.3Flutter 3.44+macOSWindowsLinuxView as Markdown

Push notifications and in-app messages for Flutter apps on macOS, Windows and Linux, from the same project as your phone apps. Optional tray and start with the computer.

Native notifications

Windows notifications, the Linux desktop's notifications and macOS Notification Center, with buttons

In-app messages

Shown as soon as you publish or change them in the Console

One project for every device

The same API key, users and topics as your phone apps

Background mode

Keep running in the tray when the window closes, and start with the computer

Nothing is lost

Pushes sent while the computer was off arrive when the app runs again

Opened and delivered

The Console shows deliveries and clicks for computers like for phones

Signed users

The same Abrova user token as Sync, Chat and the phone SDKs, straight from Abrova Auth

Error reports

Computers report their own errors to the Console, like phones

Before you begin#

  • An Abrova project with Push turned on, and its public API key (ab_live_...), from Abrova Console. Pick macOS, Windows or Linux in Project settings › Platforms.
  • A way to sign your users in: Abrova Auth gives the user token Push needs, or your server mints it (Signed user tokens).
  • Flutter 3.44 or later.
  • Windows: to build, Visual Studio (or its Build Tools) with Desktop development with C++ and the C++ ATL component.
  • Linux: to build, sudo apt-get install libayatana-appindicator3-dev. Users need libayatana-appindicator3-1 for the tray icon (add it to your .deb dependencies).
  • macOS: allow outgoing connections: com.apple.security.network.client set to true in macos/Runner/DebugProfile.entitlements and Release.entitlements.

For Android, iOS and the web, use the Flutter SDK.

Step 1: Installation#

Add the package from Abrova Center to pubspec.yaml:

yaml
dependencies:
  abrova_push_desktop:
    hosted: https://center.abrova.ir/api/packages/abrova/pub
    version: ^0.1.3

Then run flutter pub get.

Step 2: Register the computer#

dart
import 'package:abrova_auth/abrova_auth.dart';
import 'package:abrova_push_desktop/abrova_push_desktop.dart';

Future<void> main(List<String> args) async {
  WidgetsFlutterBinding.ensureInitialized();

  await AbrovaAuth.initialize('ab_live_...');
  await AbrovaPushDesktop.init(AbrovaPushDesktopConfig(
    apiKey: 'ab_live_...',               // the same key as your phone apps
    appIdentifier: 'com.example.app',
    tokenProvider: AbrovaAuth.instance.tokenProvider, // the signed-in user's token
  ));
  await AbrovaPushDesktop.register(userId: AbrovaAuth.instance.currentUser?.id);

  AbrovaPushDesktop.onMessage.listen((message) {
    print('${message.title}: ${message.body} ${message.data}');
  });
  AbrovaPushDesktop.onNotificationTapped.listen((message) {
    // Open the screen for message.deepLink or message.data
  });

  runApp(const MyApp());
}

Use the API key only. The server secret belongs on your server, which sends the pushes; never put it in an app.

register is safe at every start: the computer keeps its install id. With userId, a push to that user reaches all their phones and computers at once.

Signed user tokens#

The API key in your app is public, so a user id alone does not prove who the user is. The tokenProvider does: it returns the signed-in user's Abrova user token, the same token, and the same function, you give Abrova Sync, Chat and the phone Push SDK. With Abrova Auth it is AbrovaAuth.instance.tokenProvider; without it, a function that asks your server, which gets the token from https://auth.abrova.ir/users/token with the server secret.

Registering with a userId, or calling setUserId, needs it: when your project requires signed user tokens, the server answers 401 token_required without one.

The SDK waits for the token before each request, asks again once if the server says it expired, and sends the request without one if the provider fails or takes longer than 10 seconds.

dart
// Set or change it later, for example when your sign-in is ready:
AbrovaPushDesktop.setTokenProvider(AbrovaAuth.instance.tokenProvider);

// Or hand over a token you fetched yourself (call again when you refresh it):
AbrovaPushDesktop.setUserToken(token);

// Refused or expired token, or the provider failed: send the user to sign in.
AbrovaPushDesktop.onAuthError((error) => print(error.code));
error.codeMeaning
token_requiredThe project requires a user token and none was sent
token_invalidThe server did not accept the token
token_expiredThe token expired and no fresh one could be obtained
token_mismatchThe userId is not the user the token was issued for
token_provider_failedYour provider threw or did not answer in 10 seconds

Step 3: Send a push#

Send from the Console (Push › Send) or from your server, exactly as to phones: to the user, to topics, to a segment, or to everyone. In segments you can pick computers with the Platform rule (macOS, Windows, Linux).

Notifications and permission#

On macOS the SDK asks the user to allow notifications during init (once, without waiting for the answer). To ask at a better moment, set askNotificationPermission: false and call AbrovaPushDesktop.requestNotificationPermission() yourself. Windows and Linux need no permission.

dart
final permission = await AbrovaPushDesktop.notificationPermission();
// allowed, notAllowed (macOS: ask, or point the user to System Settings › Notifications), notNeeded
OptionDefault
showNotificationstrueShow a system notification for each push that is not silent
showNotificationsWhileFocusedtrueAlso when your window is in front (onMessage fires either way)
askNotificationPermissiontruemacOS: ask to allow notifications during init
appNamethe app's nameThe name on notifications
windowsAppUserModelIdappIdentifierWindows: the id notifications are grouped under
windowsNotificationGuidfrom appIdentifierWindows: keep it the same in every version of your app
tokenProvidernoneThe signed-in user's Abrova user token (Signed user tokens)
sendDiagnosticstrueSend the SDK's own error counts with its requests (Connection state and errors)

A click opens your app, fires onNotificationTapped and is counted as opened in the Console; a button click carries the button's id.

Notifications turned off#

macOS asks the user once. If they say no, or later turn notifications off in System Settings, pushes still arrive (onMessage fires) but no banner shows, and no app can switch them back on. The SDK tells you, so you can show a hint with a button:

dart
// macOS: the user turned notifications off (System Settings). The app can't turn them back on, so show a hint:
AbrovaPushDesktop.onNotificationPermissionChanged.listen((p) {
  if (p == AbrovaPushNotificationPermission.notAllowed) {
    // e.g. a bar: "Notifications are off" [Turn on] → opens this app's notification settings
    showNotificationsOffBar(onTurnOn: AbrovaPushDesktop.openNotificationSettings);
  }
});

openNotificationSettings() opens this app's page in System Settings › Notifications (macOS) or Settings › Notifications (Windows). Windows and Linux report notNeeded. On macOS the SDK also tells Abrova, so the Console marks the computer Notifications off and says why its messages were not seen.

Background mode (tray and start with the computer)#

By default the app receives pushes while it runs. To keep receiving them after the user closes the window, turn on background mode, as chat apps do:

dart
await AbrovaPushDesktop.enableBackgroundMode(
  trayIconPath: Platform.isWindows ? 'assets/tray.ico' : 'assets/tray.png',
  trayIconIsTemplate: true,  // macOS: a one-colour icon that follows the menu bar's light or dark look
  keepRunningInTray: true,   // closing the window hides it to the tray
  launchAtStartup: true,     // start with the computer…
  startHidden: true,         // …in the tray, without opening the window
  openLabel: 'Open',
  quitLabel: 'Quit',
);
if (AbrovaPushDesktop.startedHidden(args)) await AbrovaPushDesktop.hideWindow();

The SDK does the tray icon and its menu, hides the window instead of closing it, and adds the app to the computer's start-up list (Windows, macOS and Linux each in their own way). You only give it your icon (add it to your Flutter assets) and the menu's words in your app's language.

The tray menu opens the window or quits the app. When the app started at login in the tray, AbrovaPushDesktop.startedHidden(args) is true (pass main's args): call AbrovaPushDesktop.hideWindow() so the window stays hidden. AbrovaPushDesktop.showWindow() brings it back. Give your users a setting such as "Show notifications when the app is closed", and call AbrovaPushDesktop.setLaunchAtStartup(false) when they turn it off.

macOS: an app quits when its last window closes unless its AppDelegate says otherwise. For background mode, return false in macos/Runner/AppDelegate.swift, and bring the window back when the Dock icon is clicked:

swift
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
  return false
}

override func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
  if !flag { sender.windows.first?.makeKeyAndOrderFront(self) }
  return true
}

When the app is fully quit, nothing runs on the computer: pushes wait on the server and arrive the next time the app starts.

In-app messages#

Create them in the Console (Push › In-app). On computers they appear when the app opens, when a session starts, or on your own event, with the same rules as on phones. When you publish or change one, running apps show it within a minute.

dart
final navigatorKey = GlobalKey<NavigatorState>(); // the one your MaterialApp uses

AbrovaPushDesktop.showInAppMessages(
  navigatorKey: navigatorKey,
  onButtonTap: (context, message, button) {
    // url buttons open in the browser by themselves; route deep links and handle custom values here
    if (button.action == 'deep_link') Navigator.of(context).pushNamed(button.value!);
  },
);

await AbrovaPushDesktop.triggerInAppEvent('opened_settings');

The SDK shows each message in your app's window and in your app's language (the Console's "Add language"): modal, banner (top or bottom), full screen or card, with the image, colours and up to two buttons from the Console, and records impressions, clicks and dismissals. Change the look with theme: AbrovaPushInAppTheme(...), or draw a type yourself with builders: AbrovaPushInAppBuilders(modal: ...).

To draw every message yourself instead, skip showInAppMessages, listen to onInAppMessage, pick the text with message.contentFor(languageTag) and call recordInApp(message, 'button_click', buttonId: ...) / 'dismiss'.

On computers an app may run for days in the tray, so the SDK decides what "opening" means:

Console triggerFires on a computer when
App openthe app starts, or its window comes back from the tray (also by a notification click)
Session startthe app starts, or the user comes back after sessionTimeout away (default 30 minutes: window hidden, minimised or behind other apps)

Switching between windows alone is neither. minSessionCount counts these sessions.

Users and topics#

dart
await AbrovaPushDesktop.setUserId('user-42');
await AbrovaPushDesktop.clearUserId();
await AbrovaPushDesktop.subscribeTopic('news');
await AbrovaPushDesktop.unsubscribeTopic('news');

Connection state and errors#

dart
AbrovaPushDesktop.onConnectionState.listen((state) => print(state)); // connecting, connected, disconnected
AbrovaPushDesktop.onError.listen((error) => print(error));

The SDK reconnects by itself and catches up on pushes it missed. Call AbrovaPushDesktop.reconnectNow() to try at once, for example when your window comes to the front.

Like the phone SDKs, the SDK counts its own errors (connection, registration, topics) and sends the counts with its next request, so you see them in the Console next to your phones. It sends only error numbers and short fixed reasons such as timeout or http503: never a message, user or device detail. Turn it off with sendDiagnostics: false.

Common mistakes#

  • The server secret in the app. Apps use the API key only; the server secret stays on your server.
  • 401 token_required at register. You passed a userId without a tokenProvider. Pass the Auth SDK's tokenProvider (or your server's) in the config.
  • macOS: no connection. The app is missing com.apple.security.network.client in its entitlements.
  • Windows: the build fails with atlbase.h. Add the C++ ATL component in the Visual Studio Installer.
  • Linux: no tray icon. The computer is missing libayatana-appindicator3-1.
  • macOS: closing the window quits the app. applicationShouldTerminateAfterLastWindowClosed still returns true in AppDelegate.swift; return false (Background mode).
  • Expecting notifications after the app is quit. Nothing runs then; turn on background mode so the app stays in the tray, or pushes arrive at the next start.
  • macOS: delivered, but no banner. Notifications are off for the app in System Settings; see Notifications turned off.
  • A new windowsNotificationGuid in a new version. Keep it the same, or Windows treats the update as another app.

Billing#

Each computer that connects in a month counts as one device, the same as a phone.

Was this page helpful?
Report a problem

Last updated: 20 Nov 2026