DatabaseBackupViewModel

class DatabaseBackupViewModel(backupService: DatabaseBackupOperations, fileService: FileService, nodeRepository: NodeRepository, radioController: RadioController, radioPrefs: RadioPrefs, alertManager: AlertManager) : ViewModel(source)

Backs up the app database for the connected device, and stages a restore that applies on the next launch.

Constructors

Link copied to clipboard
constructor(backupService: DatabaseBackupOperations, fileService: FileService, nodeRepository: NodeRepository, radioController: RadioController, radioPrefs: RadioPrefs, alertManager: AlertManager)

Properties

Link copied to clipboard
val hasDeviceDatabase: StateFlow<Boolean>

False until some device has a database, so there is nothing to back up or restore into.

Functions

Link copied to clipboard
expect open fun addCloseable(closeable: AutoCloseable)
expect fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
fun backup(uri: CommonUri)
Link copied to clipboard
fun confirmRestore(onConfirmed: () -> Unit)

Asks for confirmation, then calls onConfirmed so the caller can open its file picker.

Link copied to clipboard
expect fun <T : AutoCloseable> getCloseable(key: String): T?
Link copied to clipboard
fun restore(uri: CommonUri)
Link copied to clipboard
fun runWhenDisconnected(onReady: () -> Unit)

Runs onReady now when the radio is disconnected. Otherwise, including while it sleeps or connects, asks first and, once confirmed, disconnects the radio the same way the Connections screen does, then runs onReady. The backup or restore binds to the device database active before the disconnect or, already disconnected, to the last device's; with no device database it does not proceed.

Link copied to clipboard

File name offered by the save picker: device id and today's date.