Fix Android Profile Export
continuous-integration/drone/pr Build is running Details

Fix #512.
This commit is contained in:
Sarah Jamie Lewis 2022-11-28 13:35:12 -08:00
parent 059d32718b
commit 17ffe03dba
2 changed files with 38 additions and 31 deletions

View File

@ -136,30 +136,36 @@ class MainActivity: FlutterActivity() {
"filekey" to this.dlToFileKey "filekey" to this.dlToFileKey
)), ErrorLogResult(""));//placeholder; this Result is never actually invoked )), ErrorLogResult(""));//placeholder; this Result is never actually invoked
} else if (requestCode == PREVIEW_EXPORT_REQUEST_CODE) { } else if (requestCode == PREVIEW_EXPORT_REQUEST_CODE) {
val targetPath = intent!!.getData().toString() try {
val sourcePath = Paths.get(this.exportFromPath); val sourcePath = Paths.get(this.exportFromPath);
val targetUri = Uri.parse(targetPath); val targetUri = intent!!.getData();
val os = this.applicationContext.getContentResolver().openOutputStream(targetUri); val os = this.applicationContext.getContentResolver().openOutputStream(targetUri!!);
val bytesWritten = Files.copy(sourcePath, os); val bytesWritten = Files.copy(sourcePath, os);
Log.d("MainActivity:PREVIEW_EXPORT", "copied " + bytesWritten.toString() + " bytes"); Log.d("MainActivity:PREVIEW_EXPORT", "copied " + bytesWritten.toString() + " bytes");
if (bytesWritten != 0L) { if (bytesWritten != 0L) {
os?.flush(); os?.flush();
os?.close(); os?.close();
//Files.delete(sourcePath); //Files.delete(sourcePath);
}
} catch (e: Exception) {
Log.d("MainActivity:PREVIEW_EXPORT FAILED", e.toString());
} }
} else if (requestCode == PROFILE_EXPORT_REQUEST_CODE ) { } else if (requestCode == PROFILE_EXPORT_REQUEST_CODE ) {
val targetPath = intent!!.getData().toString()
val srcFile = StringBuilder().append(this.applicationContext.cacheDir).append("/").append(this.exportFromPath).toString(); val srcFile = StringBuilder().append(this.applicationContext.cacheDir).append("/").append(this.exportFromPath).toString();
Log.i("MainActivity:PREVIEW_EXPORT", "exporting previewed file " + srcFile); Log.i("MainActivity:EXPORT_PROFILE", "exporting profile: " + srcFile);
val sourcePath = Paths.get(srcFile); try {
val targetUri = Uri.parse(targetPath); val sourcePath = Paths.get(srcFile);
val os = this.applicationContext.getContentResolver().openOutputStream(targetUri); val targetUri = intent!!.getData();
val bytesWritten = Files.copy(sourcePath, os); val os = this.applicationContext.getContentResolver().openOutputStream(targetUri!!);
Log.d("MainActivity:PREVIEW_EXPORT", "copied " + bytesWritten.toString() + " bytes"); val bytesWritten = Files.copy(sourcePath, os);
if (bytesWritten != 0L) { Log.d("MainActivity:EXPORT_PROFILE", "copied " + bytesWritten.toString() + " bytes");
os?.flush(); if (bytesWritten != 0L) {
os?.close(); os?.flush();
//Files.delete(sourcePath); os?.close();
//Files.delete(sourcePath);
}
} catch (e: Exception) {
Log.d("MainActivity:EXPORT_PROFILE FAILED", e.toString());
} }
} }
} }
@ -280,6 +286,12 @@ class MainActivity: FlutterActivity() {
startActivityForResult(intent, PREVIEW_EXPORT_REQUEST_CODE) startActivityForResult(intent, PREVIEW_EXPORT_REQUEST_CODE)
} }
"ExportProfile" -> { "ExportProfile" -> {
val profileOnion: String = call.argument("ProfileOnion") ?: ""
val file: String = StringBuilder().append(this.applicationContext.cacheDir).append("/").append(call.argument("file") ?: "").toString()
Log.i("FlwtchWorker", "constructing exported file " + file);
Cwtch.exportProfile(profileOnion,file)
this.exportFromPath = argmap["file"] ?: "" this.exportFromPath = argmap["file"] ?: ""
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply { val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
@ -516,12 +528,6 @@ class MainActivity: FlutterActivity() {
val v: String = call.argument("Val") ?: "" val v: String = call.argument("Val") ?: ""
Cwtch.setServerAttribute(serverOnion, key, v) Cwtch.setServerAttribute(serverOnion, key, v)
} }
"ExportProfile" -> {
val profileOnion: String = call.argument("ProfileOnion") ?: ""
val file: String = StringBuilder().append(this.applicationContext.cacheDir).append("/").append(call.argument("file") ?: "").toString()
Log.i("FlwtchWorker", "constructing exported file " + file);
Cwtch.exportProfile(profileOnion,file)
}
"ImportProfile" -> { "ImportProfile" -> {
val file: String = call.argument("file") ?: "" val file: String = call.argument("file") ?: ""
val pass: String = call.argument("pass") ?: "" val pass: String = call.argument("pass") ?: ""
@ -585,6 +591,7 @@ class MainActivity: FlutterActivity() {
} }
} }
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
Log.i("MainActivity.kt", "onDestroy - cancelling all WORKER_TAG and pruning old work") Log.i("MainActivity.kt", "onDestroy - cancelling all WORKER_TAG and pruning old work")

View File

@ -358,8 +358,8 @@ class _ProfileMgrViewState extends State<ProfileMgrView> {
child: TextButton.icon( child: TextButton.icon(
icon: Icon(CwtchIcons.lock_open_24px, color: Provider.of<Settings>(context).current().mainTextColor), icon: Icon(CwtchIcons.lock_open_24px, color: Provider.of<Settings>(context).current().mainTextColor),
style: TextButton.styleFrom( style: TextButton.styleFrom(
minimumSize: Size(MediaQuery.of(context).size.width * 0.79, 50), minimumSize: Size(MediaQuery.of(context).size.width * 0.79, 80),
maximumSize: Size(MediaQuery.of(context).size.width * 0.8, 50), maximumSize: Size(MediaQuery.of(context).size.width * 0.8, 80),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180))), shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180))),
), ),
label: Text( label: Text(
@ -393,8 +393,8 @@ class _ProfileMgrViewState extends State<ProfileMgrView> {
child: TextButton.icon( child: TextButton.icon(
icon: Icon(Icons.add, color: Provider.of<Settings>(context).current().mainTextColor), icon: Icon(Icons.add, color: Provider.of<Settings>(context).current().mainTextColor),
style: TextButton.styleFrom( style: TextButton.styleFrom(
minimumSize: Size(MediaQuery.of(context).size.width * 0.79, 50), minimumSize: Size(MediaQuery.of(context).size.width * 0.79, 80),
maximumSize: Size(MediaQuery.of(context).size.width * 0.8, 50), maximumSize: Size(MediaQuery.of(context).size.width * 0.8, 80),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180))), shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(180), right: Radius.circular(180))),
), ),
label: Text( label: Text(