An open-source cross-platform alternative to AirDrop
feat(macos): show checkmark/xmark in Dock icon on transfer success/failure (#1783)
Shlomo3b1ce0756a30
diff --git a/app/lib/util/native/macos_channel.dart b/app/lib/util/native/macos_channel.dartindex 18664527..28baeb30 100644--- a/app/lib/util/native/macos_channel.dart+++ b/app/lib/util/native/macos_channel.dart@@ -3,6 +3,7 @@ import 'dart:async';import 'package:flutter/foundation.dart';import 'package:flutter/services.dart';import 'package:localsend_app/gen/strings.g.dart';+import 'package:localsend_app/util/native/taskbar_helper.dart';import 'package:localsend_app/util/native/tray_helper.dart';const _methodChannel = MethodChannel('main-delegate-channel');@@ -26,6 +27,14 @@ Future<void> updateDockProgress(double progress) async {await _methodChannel.invokeMethod('updateDockProgress', progress);}+Future<void> setDockIcon(TaskbarIcon icon) async {+ if (defaultTargetPlatform != TargetPlatform.macOS) {+ return;+ }++ await _methodChannel.invokeMethod('setDockIcon', icon.index);+}+// This happens:/// - on macOS when text is dropped onto the app Dock icon/// - on macOS when text is dropped onto the app menu bar icondiff --git a/app/lib/util/native/taskbar_helper.dart b/app/lib/util/native/taskbar_helper.dartindex 835871d7..f08d60d4 100644--- a/app/lib/util/native/taskbar_helper.dart+++ b/app/lib/util/native/taskbar_helper.dart@@ -3,6 +3,8 @@ import 'package:localsend_app/util/native/macos_channel.dart';import 'package:localsend_app/util/native/platform_check.dart';import 'package:windows_taskbar/windows_taskbar.dart';+enum TaskbarIcon { regular, error, success }+class TaskbarHelper {static final _isWindows = checkPlatform([TargetPlatform.windows]);static final _isMacos = checkPlatform([TargetPlatform.macOS]);@@ -37,6 +39,12 @@ class TaskbarHelper {await WindowsTaskbar.setProgressMode(mode);}}++ Future<void> setTaskbarIcon(TaskbarIcon icon) async {+ if (_isMacos) {+ await setDockIcon(icon);+ }+ }}(int, int) _scaleRange(int progress, int total) {diff --git a/app/macos/Runner/AppDelegate.swift b/app/macos/Runner/AppDelegate.swiftindex 04b29d08..ae79e098 100644--- a/app/macos/Runner/AppDelegate.swift+++ b/app/macos/Runner/AppDelegate.swift@@ -3,6 +3,12 @@ import FlutterMacOSimport Defaultsimport DockProgress+enum DockIcon {+ case regular+ case error+ case success+}+@mainclass AppDelegate: FlutterAppDelegate {private var statusItem: NSStatusItem?@@ -38,6 +44,20 @@ class AppDelegate: FlutterAppDelegate {}}+ private func setDockIcon(icon: DockIcon) {+ switch icon {+ case .regular:+ let newIcon = NSImage(named: "AppIcon")!+ NSApplication.shared.applicationIconImage = newIcon+ case .error:+ let newIcon = NSImage(named: "AppIconWithErrorMark")!+ NSApplication.shared.applicationIconImage = newIcon+ case .success:+ let newIcon = NSImage(named: "AppIconWithSuccessMark")!+ NSApplication.shared.applicationIconImage = newIcon+ }+ }+private func setupDockIconTextDropEventListener() {let appleEventManager = NSAppleEventManager.shared()@@ -129,6 +149,9 @@ class AppDelegate: FlutterAppDelegate {let progress = call.arguments as! DoubleDockProgress.progress = progressresult(nil)+ case "setDockIcon":+ let newIcon = call.arguments as! DockIcon+ setDockIcon(icon: newIcon)default:result(FlutterMethodNotImplemented)}diff --git a/app/macos/Runner/Assets.xcassets/AppIconWithErrorMark.imageset/Contents.json b/app/macos/Runner/Assets.xcassets/AppIconWithErrorMark.imageset/Contents.jsonnew file mode 100644index 00000000..04a20a57--- /dev/null+++ b/app/macos/Runner/Assets.xcassets/AppIconWithErrorMark.imageset/Contents.json@@ -0,0 +1,21 @@+{+ "images" : [+ {+ "idiom" : "universal",+ "scale" : "1x"+ },+ {+ "filename" : "logo-1024-mac-256.png",+ "idiom" : "universal",+ "scale" : "2x"+ },+ {+ "idiom" : "universal",+ "scale" : "3x"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/app/macos/Runner/Assets.xcassets/AppIconWithErrorMark.imageset/logo-1024-mac-256.png b/app/macos/Runner/Assets.xcassets/AppIconWithErrorMark.imageset/logo-1024-mac-256.pngnew file mode 100644index 00000000..2808ffadBinary files /dev/null and b/app/macos/Runner/Assets.xcassets/AppIconWithErrorMark.imageset/logo-1024-mac-256.png differdiff --git a/app/macos/Runner/Assets.xcassets/AppIconWithSuccessMark.imageset/Contents.json b/app/macos/Runner/Assets.xcassets/AppIconWithSuccessMark.imageset/Contents.jsonnew file mode 100644index 00000000..04a20a57--- /dev/null+++ b/app/macos/Runner/Assets.xcassets/AppIconWithSuccessMark.imageset/Contents.json@@ -0,0 +1,21 @@+{+ "images" : [+ {+ "idiom" : "universal",+ "scale" : "1x"+ },+ {+ "filename" : "logo-1024-mac-256.png",+ "idiom" : "universal",+ "scale" : "2x"+ },+ {+ "idiom" : "universal",+ "scale" : "3x"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/app/macos/Runner/Assets.xcassets/AppIconWithSuccessMark.imageset/logo-1024-mac-256.png b/app/macos/Runner/Assets.xcassets/AppIconWithSuccessMark.imageset/logo-1024-mac-256.pngnew file mode 100644index 00000000..27ad1a86Binary files /dev/null and b/app/macos/Runner/Assets.xcassets/AppIconWithSuccessMark.imageset/logo-1024-mac-256.png differ