From b89a90fa9cf5a192a8da6f9e170412fb7edfaa2b Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 16 Mar 2023 16:37:38 -0700 Subject: [PATCH] Update Cwtch. Make File Download Consistent on Android --- LIBCWTCH-GO.version | 2 +- .../app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt | 8 ++++++-- lib/cwtch/cwtch.dart | 2 +- lib/cwtch/cwtchNotifier.dart | 2 +- lib/cwtch/ffi.dart | 2 +- lib/cwtch/gomobile.dart | 5 +++-- lib/widgets/filebubble.dart | 4 +++- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index 04d496b7..53bd43c9 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -2023-03-14-11-33-v0.0.3 \ No newline at end of file +2023-03-16-15-07-v0.0.3-1-g50c853a \ No newline at end of file diff --git a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt index ba1f987b..225796d0 100644 --- a/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt +++ b/android/app/src/main/kotlin/im/cwtch/flwtch/MainActivity.kt @@ -68,6 +68,7 @@ class MainActivity: FlutterActivity() { private val PROFILE_EXPORT_REQUEST_CODE = 236 private val REQUEST_DOZE_WHITELISTING_CODE:Int = 9 private var dlToProfile = "" + private var dlManifestPath = "" private var dlToHandle = 0 private var dlToFileKey = "" private var exportFromPath = "" @@ -127,13 +128,14 @@ class MainActivity: FlutterActivity() { if (requestCode == FILEPICKER_REQUEST_CODE) { val filePath = intent!!.getData().toString(); - val manifestPath = StringBuilder().append(this.applicationContext.cacheDir).append("/").append(this.dlToFileKey).toString(); Log.d("MainActivity:FILEPICKER_REQUEST_CODE", "DownloadableFileCreated"); + Log.d("MainActivity:FILEPICKER_REQUEST_CODE", this.dlManifestPath); + Log.d("MainActivity:FILEPICKER_REQUEST_CODE", filePath); handleCwtch(MethodCall("DownloadFile", mapOf( "ProfileOnion" to this.dlToProfile, "conversation" to this.dlToHandle.toInt(), "filepath" to filePath, - "manifestpath" to manifestPath, + "manifestpath" to this.dlManifestPath, "filekey" to this.dlToFileKey )), ErrorLogResult(""));//placeholder; this Result is never actually invoked } else if (requestCode == PREVIEW_EXPORT_REQUEST_CODE) { @@ -257,6 +259,7 @@ class MainActivity: FlutterActivity() { "CreateDownloadableFile" -> { this.dlToProfile = argmap["ProfileOnion"] ?: "" this.dlToHandle = call.argument("conversation")!! + this.dlManifestPath = argmap["manifestpath"] ?: "" val suggestedName = argmap["filename"] ?: "filename.ext" this.dlToFileKey = argmap["filekey"] ?: "" val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply { @@ -429,6 +432,7 @@ class MainActivity: FlutterActivity() { val filekey: String = call.argument("filekey") ?: "" // FIXME: Prevent spurious calls by Intent if (profile != "") { + Log.d("MainActivity.kt", "Cwtch Download File Calling...") Cwtch.downloadFileDefaultLimit(profile, conversation.toLong(), filepath, manifestpath, filekey) } } diff --git a/lib/cwtch/cwtch.dart b/lib/cwtch/cwtch.dart index e58ae768..a287baac 100644 --- a/lib/cwtch/cwtch.dart +++ b/lib/cwtch/cwtch.dart @@ -74,7 +74,7 @@ abstract class Cwtch { void DownloadFile(String profile, int handle, String filepath, String manifestpath, String filekey); // android-only // ignore: non_constant_identifier_names - void CreateDownloadableFile(String profile, int handle, String filenameSuggestion, String filekey); + void CreateDownloadableFile(String profile, int handle, String filenameSuggestion, String filekey, String manifestPath); // ignore: non_constant_identifier_names void CheckDownloadStatus(String profile, String fileKey); // ignore: non_constant_identifier_names diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index bdd4d1c3..d55cdea2 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -70,7 +70,7 @@ class CwtchNotifier { if (data["Online"] == null) { break; } - // EnvironmentConfig.debugLog("NewPeer $data"); + // EnvironmentConfig.debugLog("NewPeer $data"); // if tag != v1-defaultPassword then it is either encrypted OR it is an unencrypted account created during pre-beta... profileCN.add(data["Identity"], data["name"], data["picture"], data["defaultPicture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["autostart"] == "true", data["tag"] != "v1-defaultPassword"); diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 2e3ecbd2..c7f25be4 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -460,7 +460,7 @@ class CwtchFfi implements Cwtch { @override // ignore: non_constant_identifier_names - void CreateDownloadableFile(String profileOnion, int contactHandle, String filenameSuggestion, String filekey) { + void CreateDownloadableFile(String profileOnion, int contactHandle, String filenameSuggestion, String filekey, String manifestPath) { // android only - do nothing } diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index e928ce30..24477318 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -168,8 +168,9 @@ class CwtchGomobile implements Cwtch { } // ignore: non_constant_identifier_names - void CreateDownloadableFile(String profileOnion, int conversation, String filenameSuggestion, String filekey) { - cwtchPlatform.invokeMethod("CreateDownloadableFile", {"ProfileOnion": profileOnion, "conversation": conversation, "filename": filenameSuggestion, "filekey": filekey}); + void CreateDownloadableFile(String profileOnion, int conversation, String filenameSuggestion, String filekey, String manifestpath) { + cwtchPlatform + .invokeMethod("CreateDownloadableFile", {"ProfileOnion": profileOnion, "conversation": conversation, "manifestpath": manifestpath, "filename": filenameSuggestion, "filekey": filekey}); } // ignore: non_constant_identifier_names diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index e1181414..0b2dade2 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -265,7 +265,9 @@ class FileBubbleState extends State { Provider.of(context, listen: false).cwtch.SetMessageAttribute(profileOnion, conversation, 0, idx, "file-downloaded", "true"); ContactInfoState? contact = Provider.of(context, listen: false).contactList.findContact(Provider.of(context, listen: false).senderHandle); if (contact != null) { - Provider.of(context, listen: false).cwtch.CreateDownloadableFile(profileOnion, contact.identifier, widget.nameSuggestion, widget.fileKey()); + var manifestPath = Provider.of(context, listen: false).downloadPath + "/" + widget.fileKey() + ".manifest"; + + Provider.of(context, listen: false).cwtch.CreateDownloadableFile(profileOnion, contact.identifier, widget.nameSuggestion, widget.fileKey(), manifestPath); } } else { try {