Skip to content

Commit

Permalink
[macos] Feature to set labeled badge on taskbar aka dock (#305)
Browse files Browse the repository at this point in the history
* [Linux] implementation of methods: setIcon, isFocused

* [macos] feature to set badge with text on app icon at taskbar
  • Loading branch information
nikitatg committed Apr 8, 2023
1 parent cc5d754 commit d3987ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/src/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,19 @@ class WindowManager {
await _channel.invokeMethod('setIcon', arguments);
}

/// Set/unset label on taskbar(dock) app icon
///
/// Note that it's required to request access at your AppDelegate.swift like this:
/// UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge]) <...>
/// ^---
/// @platforms macos
Future<void> setBadgeLabel([String? label]) async {
final Map<String, dynamic> arguments = {
'label': label ?? '',
};
await _channel.invokeMethod('setBadgeLabel', arguments);
}

/// Returns `bool` - Whether the window has a shadow. On Windows, always returns true unless window is frameless.
///
/// @platforms macos,windows
Expand Down
5 changes: 5 additions & 0 deletions macos/Classes/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ public class WindowManager: NSObject, NSWindowDelegate {
let isSkipTaskbar: Bool = args["isSkipTaskbar"] as! Bool
NSApplication.shared.setActivationPolicy(isSkipTaskbar ? .accessory : .regular)
}

public func setBadgeLabel(_ args: [String: Any]) {
let label: String = args["label"] as! String
NSApplication.shared.dockTile.badgeLabel = label
}

public func setProgressBar(_ args: [String: Any]) {
let progress: CGFloat = CGFloat(truncating: args["progress"] as! NSNumber)
Expand Down
4 changes: 4 additions & 0 deletions macos/Classes/WindowManagerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public class WindowManagerPlugin: NSObject, FlutterPlugin {
windowManager.setSkipTaskbar(args)
result(true)
break
case "setBadgeLabel":
windowManager.setBadgeLabel(args)
result(true)
break
case "setProgressBar":
windowManager.setProgressBar(args)
result(true)
Expand Down

0 comments on commit d3987ad

Please sign in to comment.