mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
Add session log management to setup diagnostics (#2099)
* feat: manage session logs in setup * fix: address session log review feedback * fix: honor device date and time settings
This commit is contained in:
1 parent
f005241549
commit
d62f017bce
5 files changed
+144
-5
No files matched your search
@@ -19,6 +19,8 @@ import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
object SessionLogShare {
|
||||
data class Details(val sizeBytes: Long, val modifiedAt: Long)
|
||||
|
||||
private val main = Handler(Looper.getMainLooper())
|
||||
|
||||
var progress by mutableStateOf<Float?>(null)
|
||||
@@ -35,7 +37,30 @@ object SessionLogShare {
|
||||
}, "share-logs").start()
|
||||
}
|
||||
|
||||
fun latest(context: Context): File? = SessionPaths.sessionFolders(context).lastOrNull()
|
||||
fun latest(context: Context): File? = sessions(context).lastOrNull()
|
||||
|
||||
fun sessions(context: Context): List<File> {
|
||||
val current = SessionPaths.current()?.takeIf { it.isDirectory && SessionPaths.isSessionFolder(it) }
|
||||
return (SessionPaths.sessionFolders(context) + listOfNotNull(current))
|
||||
.distinctBy { it.absoluteFile.toPath().normalize().toString() }
|
||||
.sortedWith(SessionPaths.chronological)
|
||||
}
|
||||
|
||||
fun details(folder: File): Details {
|
||||
var size = 0L
|
||||
var modified = folder.lastModified()
|
||||
folder.walkTopDown().filter { it.isFile }.forEach { file ->
|
||||
size += file.length()
|
||||
modified = maxOf(modified, file.lastModified())
|
||||
}
|
||||
return Details(size, modified)
|
||||
}
|
||||
|
||||
fun deleteSession(context: Context, folder: File): Boolean {
|
||||
if (runCatching { SessionPaths.current()?.canonicalFile == folder.canonicalFile }.getOrDefault(false)) return false
|
||||
val knownSession = runCatching { folder.canonicalFile }.getOrNull() in sessions(context).mapNotNull { runCatching { it.canonicalFile }.getOrNull() }
|
||||
return knownSession && folder.isDirectory && folder.deleteRecursively()
|
||||
}
|
||||
|
||||
|
||||
fun zipFolder(context: Context, folder: File, onProgress: ((Float) -> Unit)? = null): File? {
|
||||
|
||||
Reference in new issue
Block a user