perf: reduce queue and extension runtime overhead

This commit is contained in:
zarzet
2026-08-28 01:47:51 +07:00
parent a744514e10
commit 433f8ed685
16 changed files with 251 additions and 90 deletions
@@ -571,6 +571,7 @@ class MainActivity: FlutterFragmentActivity() {
file.lastModified() < cutoff &&
(file.name.startsWith("bridge_json_") ||
file.name.startsWith("saf_") ||
file.name.startsWith("native_saf_") ||
file.name.startsWith("ms_"))
if (stale) file.delete()
}
@@ -303,6 +303,7 @@ object SafDownloadHandler {
}
fun copyContentUriToTemp(context: Context, uriStr: String): String? {
var temp: File? = null
return try {
val uri = Uri.parse(uriStr)
val extension = DocumentFile.fromSingleUri(context, uri)
@@ -311,14 +312,19 @@ object SafDownloadHandler {
?.takeIf { it.isNotBlank() }
?.let { ".$it" }
?: ".tmp"
val temp = File.createTempFile("native_saf_", extension, context.cacheDir)
val createdTemp = File.createTempFile("native_saf_", extension, context.cacheDir)
temp = createdTemp
context.contentResolver.openInputStream(uri)?.use { input ->
temp.outputStream().use { output ->
createdTemp.outputStream().use { output ->
input.copyTo(output)
}
} ?: return null
temp.absolutePath
} ?: run {
createdTemp.delete()
return null
}
createdTemp.absolutePath
} catch (e: Exception) {
try { temp?.delete() } catch (_: Exception) {}
android.util.Log.w("SpotiFLAC", "Failed to copy SAF URI to temp: ${e.message}")
null
}