Skip to content

Commit

Permalink
Rewrite UserSettings for proto files.
Browse files Browse the repository at this point in the history
  • Loading branch information
MykytaPimonovTD committed Nov 14, 2024
1 parent e75d923 commit 65817df
Showing 1 changed file with 19 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,25 @@

package io.spine.examples.pingh.client

/**
* Information about the current application settings.
*
* @property enabledDndMode Whether the user should NOT receive notifications
* for new mentions or the expiration of the snooze time.
* @property snoozeTime The interval after which the new mention notification is repeated.
*/
internal data class UserSettings(
internal var enabledDndMode: Boolean = false,
internal var snoozeTime: SnoozeTime = SnoozeTime.TWO_HOURS
) {
/**
* Saves the application settings to a file in the user's data directory.
*/
internal fun save() {
FileStorage.save(location, this)
}
import kotlin.reflect.KClass

internal companion object {
/**
* The location on disk of the file that stores the application settings.
*/
private val location = FileLocation.Settings
private val defaultUserSettings = UserSettings.newBuilder()
.setEnabledDndMode(false)
.setSnoozeTime(SnoozeTime.TWO_HOURS)
.vBuild()

/**
* Loads the application settings from a file in the user's data directory.
*
* If the file is empty, the default configured settings are returned.
*/
internal fun loadOrDefault(): UserSettings =
FileStorage.loadOrDefault(location) { UserSettings() }
}
/**
* Saves the application settings to a file in the user's data directory.
*/
internal fun UserSettings.save() {
FileStorage.save(FileLocation.Settings, this)
}

/**
* Loads the application settings from a file in the user's data directory.
*
* If the file is empty, the [default][defaultUserSettings] configured settings are returned.
*/
@Suppress("UnusedReceiverParameter" /* Associated with the class but doesn't use its data. */)
internal fun KClass<UserSettings>.loadOrDefault(): UserSettings =
FileStorage.loadOrDefault(FileLocation.Settings) { defaultUserSettings }

0 comments on commit 65817df

Please sign in to comment.