diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/DesktopCoreModule.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/DesktopCoreModule.kt index 5464f843ee4477a98454c9db2738f5579de56310..21e278a7617dd7e50afc32a87e6bcf55514a4bbc 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/DesktopCoreModule.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/DesktopCoreModule.kt @@ -60,12 +60,7 @@ import org.briarproject.briar.desktop.notification.linux.LibnotifyNotificationPr import org.briarproject.briar.desktop.notification.windows.Toast4jNotificationProvider import org.briarproject.briar.desktop.settings.Configuration import org.briarproject.briar.desktop.settings.ConfigurationImpl -import org.briarproject.briar.desktop.settings.EncryptedSettings -import org.briarproject.briar.desktop.settings.EncryptedSettingsImpl -import org.briarproject.briar.desktop.settings.EncryptedSettingsReadOnly -import org.briarproject.briar.desktop.settings.UnencryptedSettings -import org.briarproject.briar.desktop.settings.UnencryptedSettingsImpl -import org.briarproject.briar.desktop.settings.UnencryptedSettingsReadOnly +import org.briarproject.briar.desktop.settings.DesktopSettingsModule import org.briarproject.briar.desktop.threading.BriarExecutors import org.briarproject.briar.desktop.threading.BriarExecutorsImpl import org.briarproject.briar.desktop.threading.UiExecutor @@ -95,6 +90,7 @@ import javax.swing.SwingUtilities.isEventDispatchThread DefaultTaskSchedulerModule::class, DefaultWakefulIoExecutorModule::class, DesktopSecureRandomModule::class, + DesktopSettingsModule::class, JavaNetworkModule::class, JavaSystemModule::class, SocksModule::class, @@ -124,24 +120,6 @@ internal class DesktopCoreModule( return DesktopDatabaseConfig(dbDir, keyDir) } - @Provides - @Singleton - fun provideUnencryptedSettings(settings: UnencryptedSettingsImpl): UnencryptedSettings = settings - - @Provides - @Singleton - // provide [UnencryptedSettings] singleton itself as provided above to use same object - fun provideUnencryptedSettingsReadOnly(settings: UnencryptedSettings): UnencryptedSettingsReadOnly = settings - - @Provides - @Singleton - fun provideEncryptedSettings(settings: EncryptedSettingsImpl): EncryptedSettings = settings - - @Provides - @Singleton - // provide [EncryptedSettings] singleton itself as provided above to use same object - fun provideEncryptedSettingsReadOnly(settings: EncryptedSettings): EncryptedSettingsReadOnly = settings - @Provides @Singleton @EventExecutor diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/settings/DesktopSettingsModule.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/settings/DesktopSettingsModule.kt new file mode 100644 index 0000000000000000000000000000000000000000..cf44d023f38d005b9b5a6eb2510f7f6e437e539a --- /dev/null +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/settings/DesktopSettingsModule.kt @@ -0,0 +1,46 @@ +/* + * Briar Desktop + * Copyright (C) 2021-2022 The Briar Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +package org.briarproject.briar.desktop.settings + +import dagger.Module +import dagger.Provides +import javax.inject.Singleton + +@Module +class DesktopSettingsModule( + private val unencryptedSettingsPostfix: String? = null, +) { + @Provides + @Singleton + fun provideUnencryptedSettings(): UnencryptedSettings = UnencryptedSettingsImpl(unencryptedSettingsPostfix) + + @Provides + @Singleton + // provide [UnencryptedSettings] singleton itself as provided above to use same object + fun provideUnencryptedSettingsReadOnly(settings: UnencryptedSettings): UnencryptedSettingsReadOnly = settings + + @Provides + @Singleton + fun provideEncryptedSettings(settings: EncryptedSettingsImpl): EncryptedSettings = settings + + @Provides + @Singleton + // provide [EncryptedSettings] singleton itself as provided above to use same object + fun provideEncryptedSettingsReadOnly(settings: EncryptedSettings): EncryptedSettingsReadOnly = settings +} diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt index a3c9afcfd08030c36278dbc9e2a316ec82acc1ad..59873738078d4a19bf33f49dbb164af58c61f899 100644 --- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt +++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/settings/UnencryptedSettingsImpl.kt @@ -28,21 +28,26 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils import org.briarproject.briar.desktop.utils.KLoggerUtils.e import org.briarproject.briar.desktop.viewmodel.SingleStateEvent import java.util.prefs.Preferences -import javax.inject.Inject import kotlin.reflect.KProperty const val PREF_THEME = "theme" // NON-NLS const val PREF_LANG = "language" // NON-NLS const val PREF_UI_SCALE = "uiScale" // NON-NLS -class UnencryptedSettingsImpl @Inject internal constructor() : UnencryptedSettings { +class UnencryptedSettingsImpl( + unencryptedSettingsPostfix: String? = null, +) : UnencryptedSettings { companion object { private val LOG = KotlinLogging.logger {} } // used for unencrypted settings, namely theme, language and UI scale factor - private val prefs = Preferences.userNodeForPackage(this::class.java) + private val prefs = Preferences.userNodeForPackage(this::class.java).let { node -> + if (unencryptedSettingsPostfix != null) + node.node(unencryptedSettingsPostfix) + else node + } override val invalidateScreen = SingleStateEvent<Unit>() diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithMultipleTemporaryAccounts.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithMultipleTemporaryAccounts.kt index eaeb3f74fb0c1f18547861b031ac641d73a8f2c0..6a8fbe6d0242711f2e09b30fc4e57dd808b784bb 100644 --- a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithMultipleTemporaryAccounts.kt +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithMultipleTemporaryAccounts.kt @@ -28,6 +28,7 @@ import org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_CONTROL_PORT import org.briarproject.bramble.api.plugin.TorConstants.DEFAULT_SOCKS_PORT import org.briarproject.briar.BriarCoreEagerSingletons import org.briarproject.briar.desktop.TestUtils.getDataDir +import org.briarproject.briar.desktop.settings.DesktopSettingsModule import org.briarproject.briar.desktop.utils.KLoggerUtils.i import org.briarproject.briar.desktop.utils.KLoggerUtils.w import org.briarproject.briar.desktop.utils.LogUtils @@ -78,9 +79,10 @@ internal class RunWithMultipleTemporaryAccounts( LOG.i { "Using data directory '$dataDir'" } val app = - DaggerBriarDesktopTestApp.builder().desktopCoreModule( - DesktopCoreModule(dataDir, socksPort, controlPort) - ).build() + DaggerBriarDesktopTestApp.builder() + .desktopCoreModule(DesktopCoreModule(dataDir, socksPort, controlPort)) + .desktopSettingsModule(DesktopSettingsModule("test")) + .build() app.getShutdownManager().addShutdownHook { LOG.i { "deleting temporary account at $dataDir" } diff --git a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt index 7b50b7493bbf9ee3e34fdcd8324403de2ab237bf..7d37c4c0a0ab9fcbf6d4d451ec8a3f363536ae87 100644 --- a/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt +++ b/briar-desktop/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt @@ -29,6 +29,7 @@ import org.briarproject.bramble.api.lifecycle.Service import org.briarproject.bramble.api.lifecycle.ServiceException import org.briarproject.briar.BriarCoreEagerSingletons import org.briarproject.briar.desktop.TestUtils.getDataDir +import org.briarproject.briar.desktop.settings.DesktopSettingsModule import org.briarproject.briar.desktop.utils.KLoggerUtils.i import org.briarproject.briar.desktop.utils.KLoggerUtils.w import org.briarproject.briar.desktop.utils.LogUtils @@ -61,9 +62,10 @@ internal class RunWithTemporaryAccount( } val app = - DaggerBriarDesktopTestApp.builder().desktopCoreModule( - DesktopCoreModule(dataDir) - ).build() + DaggerBriarDesktopTestApp.builder() + .desktopCoreModule(DesktopCoreModule(dataDir)) + .desktopSettingsModule(DesktopSettingsModule("test")) + .build() app.getShutdownManager().addShutdownHook { LOG.i { "deleting temporary account at $dataDir" }