An open-source cross-platform alternative to AirDrop
fix(macos): `setMethodCallHandler` shadowing (#1759)
Shlomof2e895820fb0
diff --git a/app/lib/config/init.dart b/app/lib/config/init.dartindex 054862d5..3b070b9c 100644--- a/app/lib/config/init.dart+++ b/app/lib/config/init.dart@@ -183,6 +183,8 @@ Future<void> postInit(BuildContext context, Ref ref, bool appStart) async {if (appStart) {if (defaultTargetPlatform == TargetPlatform.macOS) {+ setupMethodCallHandler();+final pendingFiles = await getPendingFiles();if (pendingFiles.isNotEmpty) {await ref.global.dispatchAsync(_HandleAppStartArgumentsAction(@@ -191,7 +193,7 @@ Future<void> postInit(BuildContext context, Ref ref, bool appStart) async {}// handle future dropped files- getPendingFilesStream().listen((files) {+ pendingFilesStreamController.stream.listen((files) {ref.global.dispatchAsync(_HandleAppStartArgumentsAction(args: files,));@@ -207,7 +209,7 @@ Future<void> postInit(BuildContext context, Ref ref, bool appStart) async {}// handle future dropped strings- getPendingStringsStream().listen((pendingStrings) {+ pendingStringsStreamController.stream.listen((pendingStrings) {for (final string in pendingStrings) {ref.redux(selectedSendingFilesProvider).dispatch(AddMessageAction(message: string));ref.redux(homePageControllerProvider).dispatch(ChangeTabAction(HomeTab.send));diff --git a/app/lib/util/native/macos_channel.dart b/app/lib/util/native/macos_channel.dartindex 3cf55203..70b5515c 100644--- a/app/lib/util/native/macos_channel.dart+++ b/app/lib/util/native/macos_channel.dart@@ -39,21 +39,6 @@ Future<List<String>> getPendingFiles() async {return files.cast<String>();}-Stream<List<String>> getPendingFilesStream() {- if (defaultTargetPlatform != TargetPlatform.macOS) {- return Stream.value(<String>[]).asBroadcastStream();- }-- final controller = StreamController<List<String>>();- _methodChannel.setMethodCallHandler((call) async {- if (call.method == 'onPendingFiles') {- controller.add((call.arguments as List).cast<String>());- }- });-- return controller.stream.asBroadcastStream();-}-/// Returns a list of pending strings from the native swift runner./// This happens:/// - on macOS when text is dropped onto the app Dock icon@@ -75,17 +60,18 @@ Future<List<String>> getPendingStrings() async {return strings.cast<String>();}-Stream<List<String>> getPendingStringsStream() {- if (defaultTargetPlatform != TargetPlatform.macOS) {- return Stream.value(<String>[]).asBroadcastStream();- }+final pendingFilesStreamController = StreamController<List<String>>.broadcast();+final pendingStringsStreamController = StreamController<List<String>>.broadcast();- final controller = StreamController<List<String>>();+void setupMethodCallHandler() {_methodChannel.setMethodCallHandler((call) async {- if (call.method == 'onPendingStrings') {- controller.add((call.arguments as List).cast<String>());+ switch (call.method) {+ case 'onPendingFiles':+ pendingFilesStreamController.add((call.arguments as List).cast<String>());+ break;+ case 'onPendingStrings':+ pendingStringsStreamController.add((call.arguments as List).cast<String>());+ break;}});-- return controller.stream.asBroadcastStream();}