diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 71ced1d..841e29b 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -40,6 +40,8 @@ PODS: - file_picker (0.0.1): - DKImagePickerController/PhotoGallery - Flutter + - file_saver (0.0.1): + - Flutter - Firebase/Analytics (11.4.0): - Firebase/Core - Firebase/Core (11.4.0): @@ -216,6 +218,7 @@ DEPENDENCIES: - croppy (from `.symlinks/plugins/croppy/ios`) - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - file_picker (from `.symlinks/plugins/file_picker/ios`) + - file_saver (from `.symlinks/plugins/file_saver/ios`) - firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`) - firebase_core (from `.symlinks/plugins/firebase_core/ios`) - firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`) @@ -270,6 +273,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/device_info_plus/ios" file_picker: :path: ".symlinks/plugins/file_picker/ios" + file_saver: + :path: ".symlinks/plugins/file_saver/ios" firebase_analytics: :path: ".symlinks/plugins/firebase_analytics/ios" firebase_core: @@ -326,6 +331,7 @@ SPEC CHECKSUMS: DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60 file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655 + file_saver: 503e386464dbe118f630e17b4c2e1190fa0cf808 Firebase: cf1b19f21410b029b6786a54e9764a0cacad3c99 firebase_analytics: 2815af29d49c1a994652abd37a5b001a88bc7b75 firebase_core: 418aed674e9a0b8b6088aec16cde82a811f6261f diff --git a/lib/screens/chat/room.dart b/lib/screens/chat/room.dart index 26219b1..3f86961 100644 --- a/lib/screens/chat/room.dart +++ b/lib/screens/chat/room.dart @@ -69,9 +69,9 @@ class _ChatRoomScreenState extends State { {}, ); _otherMember = _channel!.members?.cast().firstWhere( - (ele) => ele?.accountId != ua.user?.id, - orElse: () => null, - ); + (ele) => ele?.accountId != ua.user?.id, + orElse: () => null, + ); } } catch (err) { if (!mounted) return; @@ -90,6 +90,8 @@ class _ChatRoomScreenState extends State { '/cgi/im/channels/${_messageController.channel!.keyPath}/calls/ongoing', options: Options( validateStatus: (status) => status != null && status < 500, + receiveTimeout: const Duration(seconds: 60), + sendTimeout: const Duration(seconds: 60), ), ); if (resp.statusCode == 200) { @@ -97,6 +99,7 @@ class _ChatRoomScreenState extends State { } } catch (err) { if (!mounted) return; + print((err as DioException).response?.data); context.showErrorDialog(err); } finally { setState(() => _isCalling = false); @@ -115,10 +118,12 @@ class _ChatRoomScreenState extends State { receiveTimeout: const Duration(seconds: 30), ), ); - log(jsonDecode(resp.data)); } catch (err) { if (!mounted) return; - context.showErrorDialog(err); + if (_ongoingCall == null) { + // ignore the error because the call is already ongoing + context.showErrorDialog(err); + } } finally { setState(() => _isCalling = false); } diff --git a/lib/widgets/attachment/attachment_zoom.dart b/lib/widgets/attachment/attachment_zoom.dart index a2670c2..38f2e61 100644 --- a/lib/widgets/attachment/attachment_zoom.dart +++ b/lib/widgets/attachment/attachment_zoom.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:dismissible_page/dismissible_page.dart'; import 'package:easy_localization/easy_localization.dart'; +import 'package:file_saver/file_saver.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:gal/gal.dart'; @@ -83,7 +84,14 @@ class _AttachmentZoomViewState extends State { bool isSuccess = false; try { - await Gal.putImage(imagePath, album: 'Solar Network'); + if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) { + await Gal.putImage(imagePath, album: 'Solar Network'); + } else { + await FileSaver.instance.saveFile( + name: item.name, + file: File(imagePath), + ); + } setState(() { isSuccess = true; _isDownloading = false; diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index fd9c6ea..65ae5b0 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'dart:math' as math; import 'package:easy_localization/easy_localization.dart'; +import 'package:file_saver/file_saver.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; @@ -97,17 +98,21 @@ class PostItem extends StatelessWidget { if (kIsWeb) return; final directory = await getTemporaryDirectory(); - final imagePath = await File( + final imageFile = await File( '${directory.path}/sn-share-via-image-${DateTime.now().millisecondsSinceEpoch}.png', ).create(); - await imagePath.writeAsBytes(capturedImage); + await imageFile.writeAsBytes(capturedImage); - await Share.shareXFiles( - [XFile(imagePath.path)], - sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size, - ); + if(!kIsWeb && (Platform.isAndroid || Platform.isIOS)) { + await Share.shareXFiles( + [XFile(imageFile.path)], + sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size, + ); + } else { + await FileSaver.instance.saveFile(name: 'Solar Network Post #${data.id}', file: imageFile); + } - await imagePath.delete(); + await imageFile.delete(); } @override diff --git a/macos/Podfile.lock b/macos/Podfile.lock index dc44053..910e066 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -8,6 +8,8 @@ PODS: - FlutterMacOS - device_info_plus (0.0.1): - FlutterMacOS + - file_saver (0.0.1): + - FlutterMacOS - file_selector_macos (0.0.1): - FlutterMacOS - Firebase/Analytics (11.4.0): @@ -175,6 +177,7 @@ DEPENDENCIES: - connectivity_plus (from `Flutter/ephemeral/.symlinks/plugins/connectivity_plus/darwin`) - croppy (from `Flutter/ephemeral/.symlinks/plugins/croppy/macos`) - device_info_plus (from `Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos`) + - file_saver (from `Flutter/ephemeral/.symlinks/plugins/file_saver/macos`) - file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`) - firebase_analytics (from `Flutter/ephemeral/.symlinks/plugins/firebase_analytics/macos`) - firebase_core (from `Flutter/ephemeral/.symlinks/plugins/firebase_core/macos`) @@ -222,6 +225,8 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/croppy/macos device_info_plus: :path: Flutter/ephemeral/.symlinks/plugins/device_info_plus/macos + file_saver: + :path: Flutter/ephemeral/.symlinks/plugins/file_saver/macos file_selector_macos: :path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos firebase_analytics: @@ -270,6 +275,7 @@ SPEC CHECKSUMS: connectivity_plus: 18382e7311ba19efcaee94442b23b32507b20695 croppy: 25a638bd7d05411d8c697f481568f261037694fc device_info_plus: 1b14eed9bf95428983aed283a8d51cce3d8c4215 + file_saver: 44e6fbf666677faf097302460e214e977fdd977b file_selector_macos: cc3858c981fe6889f364731200d6232dac1d812d Firebase: cf1b19f21410b029b6786a54e9764a0cacad3c99 firebase_analytics: a80b3d6645f2f12d626fde928b61dae12e5ea2ef diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index 8e02df2..b3c1761 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/macos/Runner/DebugProfile.entitlements b/macos/Runner/DebugProfile.entitlements index 46e6f68..910f5b3 100644 --- a/macos/Runner/DebugProfile.entitlements +++ b/macos/Runner/DebugProfile.entitlements @@ -12,6 +12,8 @@ com.apple.security.device.camera + com.apple.security.files.downloads.read-write + com.apple.security.files.user-selected.read-write com.apple.security.network.client diff --git a/macos/Runner/Release.entitlements b/macos/Runner/Release.entitlements index c7edc19..8008cdd 100644 --- a/macos/Runner/Release.entitlements +++ b/macos/Runner/Release.entitlements @@ -10,6 +10,8 @@ com.apple.security.device.camera + com.apple.security.files.downloads.read-write + com.apple.security.files.user-selected.read-write com.apple.security.network.client