Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package net.thunderbird.core.preference

/**
* Publishes changes of preferences to all subscribers.
* The change can be scoped to a specific category of preferences or applied globally.
* @see PreferenceScope for available scopes of preference changes.
*/
interface PreferenceChangePublisher {

/**
* Publish a change in the preferences.
* @param scope Defines which category of preferences has changed.
* By default, [PreferenceScope.ALL] is used, indicating a global change affecting all preferences.
*/
fun publish()
fun publish(scope: PreferenceScope = PreferenceScope.ALL)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package net.thunderbird.core.preference
fun interface PreferenceChangeSubscriber {

/**
* Called when preferences change.
* Called when preferences within a given scope have changed.
* @param scope The [PreferenceScope] indicating which category of preferences
* has been updated.
*/
fun receive()
fun receive(scope: PreferenceScope)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.thunderbird.core.preference

enum class PreferenceScope {
ALL,
DEBUGGING,
DISPLAY_CORE,
DISPLAY_INBOX,
DISPLAY_MISC,
DISPLAY_VISUAL,
DISPLAY_VISUAL_MESSAGE_LIST,
INTERACTION,
NETWORK,
NOTIFICATION,
PRIVACY,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.thunderbird.core.preference

import net.thunderbird.core.preference.debugging.DebugSettingKey
import net.thunderbird.core.preference.display.coreSettings.DisplayCoreSettingKey
import net.thunderbird.core.preference.display.inboxSettings.DisplayInboxSettingKey
import net.thunderbird.core.preference.display.miscSettings.DisplayMiscSettingKey
import net.thunderbird.core.preference.display.visualSettings.DisplayVisualSettingKey
import net.thunderbird.core.preference.display.visualSettings.message.list.DisplayMessageListSettingKey
import net.thunderbird.core.preference.interaction.InteractionSettingKey
import net.thunderbird.core.preference.network.NetworkSettingKey
import net.thunderbird.core.preference.notification.NotificationSettingKey
import net.thunderbird.core.preference.privacy.PrivacySettingKey

object PreferenceScopeRegistry {

private val map: Map<String, PreferenceScope> = buildMap {

DebugSettingKey.entries.forEach { put(it.value, PreferenceScope.DEBUGGING) }
InteractionSettingKey.entries.forEach { put(it.value, PreferenceScope.INTERACTION) }
NetworkSettingKey.entries.forEach { put(it.value, PreferenceScope.NETWORK) }
NotificationSettingKey.entries.forEach { put(it.value, PreferenceScope.NOTIFICATION) }
PrivacySettingKey.entries.forEach { put(it.value, PreferenceScope.PRIVACY) }

DisplayCoreSettingKey.entries.forEach {
put(it.value, PreferenceScope.DISPLAY_CORE)
}

DisplayInboxSettingKey.entries.forEach {
put(it.value, PreferenceScope.DISPLAY_INBOX)
}

DisplayMiscSettingKey.entries.forEach {
put(it.value, PreferenceScope.DISPLAY_MISC)
}

DisplayVisualSettingKey.entries.forEach {
put(it.value, PreferenceScope.DISPLAY_VISUAL)
}

DisplayMessageListSettingKey.entries.forEach {
put(it.value, PreferenceScope.DISPLAY_VISUAL_MESSAGE_LIST)
}
}

fun getScope(key: String): PreferenceScope =
map[key] ?: PreferenceScope.ALL
}

fun getPreferenceScope(changedKey: String): PreferenceScope {
return PreferenceScopeRegistry.getScope(changedKey)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package net.thunderbird.core.preference.debugging

import net.thunderbird.core.preference.PreferenceManager

const val KEY_ENABLE_DEBUG_LOGGING = "enableDebugLogging"
const val KEY_ENABLE_SYNC_DEBUG_LOGGING = "enableSyncDebugLogging"
const val KEY_ENABLE_SENSITIVE_LOGGING = "enableSensitiveLogging"
enum class DebugSettingKey(val value: String) {

EnableDebugLogging("enableDebugLogging"),
EnableSyncDebugLogging("enableSyncDebugLogging"),
EnableSensitiveLogging("enableSensitiveLogging"),
}

interface DebuggingSettingsPreferenceManager : PreferenceManager<DebuggingSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package net.thunderbird.core.preference.display.coreSettings

import net.thunderbird.core.preference.PreferenceManager

const val KEY_FIXED_MESSAGE_VIEW_THEME = "fixedMessageViewTheme"
const val KEY_MESSAGE_VIEW_THEME = "messageViewTheme"
const val KEY_MESSAGE_COMPOSE_THEME = "messageComposeTheme"
const val KEY_APP_LANGUAGE = "language"
const val KEY_SPLIT_VIEW_MODE = "splitViewMode"
const val KEY_THEME = "theme"
enum class DisplayCoreSettingKey(val value: String) {

FixedMessageViewTheme("fixedMessageViewTheme"),
MessageViewTheme("messageViewTheme"),
MessageComposeTheme("messageComposeTheme"),
AppLanguage("language"),
SplitViewMode("splitViewMode"),
Theme("theme"),
}

interface DisplayCoreSettingsPreferenceManager : PreferenceManager<DisplayCoreSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package net.thunderbird.core.preference.display.inboxSettings

import net.thunderbird.core.preference.PreferenceManager

const val KEY_MESSAGE_LIST_SENDER_ABOVE_SUBJECT = "messageListSenderAboveSubject"
const val KEY_SHOW_COMPOSE_BUTTON_ON_MESSAGE_LIST = "showComposeButtonOnMessageList"
const val KEY_SHOW_MESSAGE_LIST_STARS = "messageListStars"
const val KEY_SHOW_STAR_COUNT = "showStarredCount"
const val KEY_SHOW_UNIFIED_INBOX = "showUnifiedInbox"
const val KEY_THREAD_VIEW_ENABLED = "isThreadedViewEnabled"
enum class DisplayInboxSettingKey(val value: String) {

MessageListSenderAboveSubject("messageListSenderAboveSubject"),
ShowComposeButtonOnMessageList("showComposeButtonOnMessageList"),
ShowMessageListStars("messageListStars"),
ShowStarCount("showStarredCount"),
ShowUnifiedInbox("showUnifiedInbox"),
ThreadViewEnabled("isThreadedViewEnabled"),
}

interface DisplayInboxSettingsPreferenceManager : PreferenceManager<DisplayInboxSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package net.thunderbird.core.preference.display.miscSettings

import net.thunderbird.core.preference.PreferenceManager

const val KEY_SHOW_RECENT_CHANGES = "showRecentChanges"
const val KEY_SHOULD_SHOW_SETUP_ARCHIVE_FOLDER_DIALOG = "shouldShowSetupArchiveFolderDialog"
enum class DisplayMiscSettingKey(val value: String) {

ShowRecentChanges("showRecentChanges"),
ShouldShowSetupArchiveFolderDialog("shouldShowSetupArchiveFolderDialog"),
}

interface DisplayMiscSettingsPreferenceManager : PreferenceManager<DisplayMiscSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package net.thunderbird.core.preference.display.visualSettings

import net.thunderbird.core.preference.PreferenceManager

const val KEY_ANIMATION = "animations"
const val KEY_MESSAGE_VIEW_FIXED_WIDTH_FONT = "messageViewFixedWidthFont"
const val KEY_AUTO_FIT_WIDTH = "autofitWidth"
const val KEY_MESSAGE_VIEW_BODY_CONTENT_TYPE = "messageViewBodyContentType"
const val KEY_DRAWER_EXPAND_ALL_FOLDER = "drawerExpandAllFolder"
const val KEY_MESSAGE_VIEW_ARCHIVE_ACTION_VISIBLE = "messageViewArchiveActionVisible"
const val KEY_MESSAGE_VIEW_DELETE_ACTION_VISIBLE = "messageViewDeleteActionVisible"
const val KEY_MESSAGE_VIEW_MOVE_ACTION_VISIBLE = "messageViewMoveActionVisible"
const val KEY_MESSAGE_VIEW_COPY_ACTION_VISIBLE = "messageViewCopyActionVisible"
const val KEY_MESSAGE_VIEW_SPAM_ACTION_VISIBLE = "messageViewSpamActionVisible"
enum class DisplayVisualSettingKey(val value: String) {

Animation("animations"),
MessageViewFixedWidthFont("messageViewFixedWidthFont"),
AutoFitWidth("autofitWidth"),
MessageViewBodyContentType("messageViewBodyContentType"),
DrawerExpandAllFolder("drawerExpandAllFolder"),
MessageViewArchiveActionVisible("messageViewArchiveActionVisible"),
MessageViewDeleteActionVisible("messageViewDeleteActionVisible"),
MessageViewMoveActionVisible("messageViewMoveActionVisible"),
MessageViewCopyActionVisible("messageViewCopyActionVisible"),
MessageViewSpamActionVisible("messageViewSpamActionVisible"),
}

interface DisplayVisualSettingsPreferenceManager : PreferenceManager<DisplayVisualSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package net.thunderbird.core.preference.display.visualSettings.message.list

import net.thunderbird.core.preference.PreferenceManager

const val KEY_COLORIZE_MISSING_CONTACT_PICTURE = "colorizeMissingContactPictures"
const val KEY_CHANGE_REGISTERED_NAME_COLOR = "changeRegisteredNameColor"
const val KEY_USE_BACKGROUND_AS_UNREAD_INDICATOR = "isUseBackgroundAsUnreadIndicator"
const val KEY_SHOW_CORRESPONDENT_NAMES = "showCorrespondentNames"
const val KEY_SHOW_CONTACT_NAME = "showContactName"
const val KEY_SHOW_CONTACT_PICTURE = "showContactPicture"
const val KEY_MESSAGE_LIST_VIEW_PREVIEW_LINES = "messageListPreviewLines"
const val KEY_MESSAGE_LIST_VIEW_DENSITY = "messageListDensity"
const val KEY_REGISTERED_NAME_COLOR = "registeredNameColor"
const val KEY_MESSAGE_LIST_DATE_TIME_FORMAT = "messageListDateTimeFormat"
enum class DisplayMessageListSettingKey(val value: String) {

ColorizeMissingContactPicture("colorizeMissingContactPictures"),
ChangeRegisteredNameColor("changeRegisteredNameColor"),
UseBackgroundAsUnreadIndicator("isUseBackgroundAsUnreadIndicator"),
ShowCorrespondentNames("showCorrespondentNames"),
ShowContactName("showContactName"),
ShowContactPicture("showContactPicture"),
MessageListPreviewLines("messageListPreviewLines"),
MessageListDensity("messageListDensity"),
RegisteredNameColor("registeredNameColor"),
MessageListDateTimeFormat("messageListDateTimeFormat"),
}

interface MessageListPreferencesManager : PreferenceManager<DisplayMessageListSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package net.thunderbird.core.preference.interaction

import net.thunderbird.core.preference.PreferenceManager

const val KEY_USE_VOLUME_KEYS_FOR_NAVIGATION = "useVolumeKeysForNavigation"
const val KEY_MESSAGE_VIEW_POST_DELETE_ACTION = "messageViewPostDeleteAction"
const val KEY_MESSAGE_VIEW_POST_MARK_AS_UNREAD_ACTION = "messageViewPostMarkAsReadAction"
const val KEY_SWIPE_ACTION_LEFT = "swipeLeftAction"
const val KEY_SWIPE_ACTION_RIGHT = "swipeRightAction"
const val KEY_CONFIRM_DELETE = "confirmDelete"
const val KEY_CONFIRM_DISCARD_MESSAGE = "confirmDiscardMessage"
const val KEY_CONFIRM_DELETE_STARRED = "confirmDeleteStarred"
const val KEY_CONFIRM_SPAM = "confirmSpam"
const val KEY_CONFIRM_DELETE_FROM_NOTIFICATION = "confirmDeleteFromNotification"
const val KEY_CONFIRM_MARK_ALL_READ = "confirmMarkAllRead"
enum class InteractionSettingKey(val value: String) {

UseVolumeKeysForNavigation("useVolumeKeysForNavigation"),
MessageViewPostDeleteAction("messageViewPostDeleteAction"),
SwipeActionLeft("swipeLeftAction"),
SwipeActionRight("swipeRightAction"),
ConfirmDelete("confirmDelete"),
ConfirmDiscardMessage("confirmDiscardMessage"),
ConfirmDeleteStarred("confirmDeleteStarred"),
ConfirmSpam("confirmSpam"),
ConfirmDeleteFromNotification("confirmDeleteFromNotification"),
ConfirmMarkAllRead("confirmMarkAllRead"),
MessageViewPostMarkAsRead("messageViewPostMarkAsReadAction"),
}

interface InteractionSettingsPreferenceManager : PreferenceManager<InteractionSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package net.thunderbird.core.preference.network

import net.thunderbird.core.preference.PreferenceManager

const val KEY_BG_OPS = "backgroundOperations"
enum class NetworkSettingKey(val value: String) {
BackgroundOperations("backgroundOperations"),
}

interface NetworkSettingsPreferenceManager : PreferenceManager<NetworkSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package net.thunderbird.core.preference.notification

import net.thunderbird.core.preference.PreferenceManager

const val KEY_QUIET_TIME_ENDS = "quietTimeEnds"
const val KEY_QUIET_TIME_STARTS = "quietTimeStarts"
const val KEY_QUIET_TIME_ENABLED = "quietTimeEnabled"
const val KEY_NOTIFICATION_DURING_QUIET_TIME_ENABLED = "notificationDuringQuietTimeEnabled"
const val KEY_MESSAGE_ACTIONS_ORDER = "messageActionsOrder"
const val KEY_MESSAGE_ACTIONS_CUTOFF = "messageActionsCutoff"
const val KEY_IS_SUMMARY_DELETE_ACTION_ENABLED = "isSummaryDeleteActionEnabled"

const val KEY_NOTIFICATION_QUICK_DELETE_BEHAVIOUR = "notificationQuickDelete"
const val KEY_LOCK_SCREEN_NOTIFICATION_VISIBILITY = "lockScreenNotificationVisibility"
enum class NotificationSettingKey(val value: String) {

QuietTimeEnds("quietTimeEnds"),
QuietTimeStarts("quietTimeStarts"),
QuietTimeEnabled("quietTimeEnabled"),
NotificationDuringQuietTimeEnabled("notificationDuringQuietTimeEnabled"),
MessageActionsOrder("messageActionsOrder"),
MessageActionsCutoff("messageActionsCutoff"),
IsSummaryDeleteActionEnabled("isSummaryDeleteActionEnabled"),
NotificationQuickDeleteBehaviour("notificationQuickDelete"),
LockScreenNotificationVisibility("lockScreenNotificationVisibility"),
}
interface NotificationPreferenceManager : PreferenceManager<NotificationPreference>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package net.thunderbird.core.preference.privacy

import net.thunderbird.core.preference.PreferenceManager

const val KEY_HIDE_TIME_ZONE = "hideTimeZone"
const val KEY_HIDE_USER_AGENT = "hideUserAgent"
enum class PrivacySettingKey(val value: String) {

HideTimeZone("hideTimeZone"),
HideUserAgent("hideUserAgent"),
}

interface PrivacySettingsPreferenceManager : PreferenceManager<PrivacySettings>
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class DefaultPreferenceChangeBroker(
}
}

override fun publish() {
override fun publish(scope: PreferenceScope) {
val currentSubscribers = synchronized(lock) { HashSet(subscribers) }

for (subscriber in currentSubscribers) {
subscriber.receive()
subscriber.receive(scope)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import net.thunderbird.core.common.appConfig.PlatformConfigProvider
import net.thunderbird.core.logging.LogLevel
import net.thunderbird.core.logging.LogLevelManager
import net.thunderbird.core.logging.Logger
import net.thunderbird.core.preference.PreferenceChangeBroker
import net.thunderbird.core.preference.PreferenceChangeSubscriber
import net.thunderbird.core.preference.PreferenceScope
import net.thunderbird.core.preference.storage.Storage
import net.thunderbird.core.preference.storage.StorageEditor
import net.thunderbird.core.preference.storage.StoragePersister
Expand All @@ -28,7 +31,12 @@ class DefaultDebuggingSettingsPreferenceManager(
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
private var scope: CoroutineScope = CoroutineScope(SupervisorJob()),
private val platformConfigProvider: PlatformConfigProvider,
) : DebuggingSettingsPreferenceManager {
preferenceChangeBroker: PreferenceChangeBroker,
) : DebuggingSettingsPreferenceManager, PreferenceChangeSubscriber {

init {
preferenceChangeBroker.subscribe(this)
}
private val configState: MutableStateFlow<DebuggingSettings> = MutableStateFlow(value = loadConfig())
private val mutex = Mutex()
private val storage: Storage
Expand All @@ -45,15 +53,15 @@ class DefaultDebuggingSettingsPreferenceManager(

private fun loadConfig(): DebuggingSettings = DebuggingSettings(
isDebugLoggingEnabled = storage.getBoolean(
KEY_ENABLE_DEBUG_LOGGING,
DebugSettingKey.EnableDebugLogging.value,
platformConfigProvider.isDebug,
),
isSyncLoggingEnabled = storage.getBoolean(
KEY_ENABLE_SYNC_DEBUG_LOGGING,
DebugSettingKey.EnableSyncDebugLogging.value,
DEBUGGING_SETTINGS_DEFAULT_IS_SYNC_LOGGING_ENABLED,
),
isSensitiveLoggingEnabled = storage.getBoolean(
key = KEY_ENABLE_SENSITIVE_LOGGING,
key = DebugSettingKey.EnableSensitiveLogging.value,
defValue = DEBUGGING_SETTINGS_DEFAULT_SENSITIVE_LOGGING_ENABLED,
),
).also(::updateDebugLogLevel)
Expand All @@ -62,9 +70,9 @@ class DefaultDebuggingSettingsPreferenceManager(
logger.debug(TAG) { "writeConfig() called with: config = $config" }
scope.launch(ioDispatcher) {
mutex.withLock {
storageEditor.putBoolean(KEY_ENABLE_DEBUG_LOGGING, config.isDebugLoggingEnabled)
storageEditor.putBoolean(KEY_ENABLE_SYNC_DEBUG_LOGGING, config.isSyncLoggingEnabled)
storageEditor.putBoolean(KEY_ENABLE_SENSITIVE_LOGGING, config.isSensitiveLoggingEnabled)
storageEditor.putBoolean(DebugSettingKey.EnableDebugLogging.value, config.isDebugLoggingEnabled)
storageEditor.putBoolean(DebugSettingKey.EnableSyncDebugLogging.value, config.isSyncLoggingEnabled)
storageEditor.putBoolean(DebugSettingKey.EnableSensitiveLogging.value, config.isSensitiveLoggingEnabled)
storageEditor.commit().also { commited ->
logger.verbose(TAG) { "writeConfig: storageEditor.commit() resulted in: $commited" }
}
Expand All @@ -79,4 +87,10 @@ class DefaultDebuggingSettingsPreferenceManager(
logLevelManager.restoreDefault()
}
}

override fun receive(scope: PreferenceScope) {
if (scope == PreferenceScope.ALL || scope == PreferenceScope.DEBUGGING) {
configState.update { loadConfig() }
}
}
}
Loading
Loading