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

[macos] Feature to set labeled badge on taskbar aka dock #305

Merged
merged 4 commits into from
Apr 8, 2023
Merged
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
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