mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-03 16:50:40 +02:00
perf: reduce queue and extension runtime overhead
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user