Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -39,6 +39,7 @@
import com.owlplug.auth.model.UserAccountProvider;
import com.owlplug.auth.utils.AuthenticationException;
import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.ApplicationDefaults.Prefs;
import com.owlplug.core.services.BaseService;
import jakarta.transaction.Transactional;
import java.io.IOException;
Expand Down Expand Up @@ -114,7 +115,7 @@ public void createAccountAndAuth() throws AuthenticationException {
userAccount.setCredential(googleCredentialRepository.findByKey(userAccount.getKey()));

userAccountRepository.save(userAccount);
this.getPreferences().putLong(ApplicationDefaults.SELECTED_ACCOUNT_KEY, userAccount.getId());
this.getPreferences().putLong(Prefs.Auth.SELECTED_ACCOUNT, userAccount.getId());
publisher.publishEvent(new AccountUpdateEvent());

} catch (GeneralSecurityException | IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,59 @@ public class ApplicationDefaults {

// CHECKSTYLE:ON

public static final String VST_DIRECTORY_KEY = "VST_DIRECTORY";
public static final String VST2_DISCOVERY_ENABLED_KEY = "VST2_DISCOVERY_ENABLED";
public static final String VST2_EXTRA_DIRECTORY_KEY = "VST2_EXTRA_DIRECTORY_KEY";
public static final String VST3_DIRECTORY_KEY = "VST3_DIRECTORY";
public static final String VST3_DISCOVERY_ENABLED_KEY = "VST3_DISCOVERY_ENABLED";
public static final String VST3_EXTRA_DIRECTORY_KEY = "VST3_EXTRA_DIRECTORY_KEY";
public static final String AU_DIRECTORY_KEY = "AU_DIRECTORY_KEY";
public static final String AU_DISCOVERY_ENABLED_KEY = "AU_DISCOVERY_ENABLED_KEY";
public static final String AU_EXTRA_DIRECTORY_KEY = "AU_EXTRA_DIRECTORY_KEY";
public static final String LV2_DIRECTORY_KEY = "LV2_DIRECTORY_KEY";
public static final String LV2_DISCOVERY_ENABLED_KEY = "LV2_DISCOVERY_ENABLED_KEY";
public static final String LV2_EXTRA_DIRECTORY_KEY = "LV2_EXTRA_DIRECTORY_KEY";
public static final String NATIVE_HOST_ENABLED_KEY = "NATIVE_HOST_ENABLED_KEY";
public static final String PREFERRED_NATIVE_LOADER = "PREFERRED_NATIVE_LOADER";
public static final String NATIVE_LOADER_TIMEOUT_KEY = "NATIVE_LOADER_TIMEOUT_KEY";
public static final String SELECTED_ACCOUNT_KEY = "SELECTED_ACCOUNT_KEY";
public static final String SYNC_PLUGINS_STARTUP_KEY = "SYNC_PLUGINS_STARTUP_KEY";
public static final String STORE_DIRECTORY_ENABLED_KEY = "STORE_DIRECTORY_ENABLED_KEY";
public static final String STORE_BY_CREATOR_ENABLED_KEY = "STORE_BY_CREATOR_ENABLED_KEY";
public static final String STORE_DIRECTORY_KEY = "STORE_DIRECTORY_KEY";
public static final String STORE_SUBDIRECTORY_ENABLED = "STORE_SUBDIRECTORY_ENABLED";
public static final String FIRST_LAUNCH_KEY = "FIRST_LAUNCH_KEY";
public static final String APPLICATION_STATE_KEY = "APPLICATION_STATE_KEY";
public static final String SHOW_DIALOG_DISABLE_PLUGIN_KEY = "SHOW_DIALOG_DISABLE_PLUGIN_KEY";
public static final String PROJECT_DIRECTORY_KEY = "PROJECT_DIRECTORY_KEY";
public static final String PLUGIN_PREFERRED_DISPLAY_KEY = "PLUGIN_PREFERRED_DISPLAY_KEY";
public static final String SYNC_FILE_STAT_KEY = "SYNC_FILE_STAT_KEY";
public static final String TELEMETRY_ENABLED_KEY = "TELEMETRY_ENABLED_KEY";
public static final String TELEMETRY_USER_ID_KEY = "TELEMETRY_USER_ID_KEY";
public static final String LAST_PLUGIN_SCAN_DATE_KEY = "LAST_PLUGIN_SCAN_DATE_KEY";
public static final class Prefs {

public static final class Plugins {
public static final String VST2_DIRECTORY = "plugins.vst2.directory";
public static final String VST2_DISCOVERY_ENABLED = "plugins.vst2.discovery_enabled";
public static final String VST2_EXTRA_DIRECTORY = "plugins.vst2.extra_directory";
public static final String VST3_DIRECTORY = "plugins.vst3.directory";
public static final String VST3_DISCOVERY_ENABLED = "plugins.vst3.discovery_enabled";
public static final String VST3_EXTRA_DIRECTORY = "plugins.vst3.extra_directory";
public static final String AU_DIRECTORY = "plugins.au.directory";
public static final String AU_DISCOVERY_ENABLED = "plugins.au.discovery_enabled";
public static final String AU_EXTRA_DIRECTORY = "plugins.au.extra_directory";
public static final String LV2_DIRECTORY = "plugins.lv2.directory";
public static final String LV2_DISCOVERY_ENABLED = "plugins.lv2.discovery_enabled";
public static final String LV2_EXTRA_DIRECTORY = "plugins.lv2.extra_directory";
public static final String PREFERRED_DISPLAY = "plugins.preferred_display";
public static final String LAST_SCAN_DATE = "plugins.last_scan_date";

public static final class NativeHost {
public static final String ENABLED = "plugins.native_host.enabled";
public static final String PREFERRED_LOADER = "plugins.native_host.preferred_loader";
public static final String LOADER_TIMEOUT = "plugins.native_host.loader_timeout";
}
}

public static final class Explore {
public static final String STORE_DIRECTORY_ENABLED = "explore.store_directory_enabled";
public static final String STORE_BY_CREATOR_ENABLED = "explore.store_by_creator_enabled";
public static final String STORE_DIRECTORY = "explore.store_directory";
public static final String STORE_SUBDIRECTORY_ENABLED = "explore.store_subdirectory_enabled";
}

public static final class Auth {
public static final String SELECTED_ACCOUNT = "auth.selected_account";
}

public static final class Projects {
public static final String DIRECTORY = "projects.directory";
}

public static final class Telemetry {
public static final String ENABLED = "telemetry.enabled";
public static final String USER_ID = "telemetry.user_id";
}

public static final class App {
public static final String FIRST_LAUNCH = "app.first_launch";
public static final String STATE = "app.state";
public static final String SYNC_PLUGINS_ON_STARTUP = "app.sync_plugins_on_startup";
public static final String SYNC_FILE_STAT = "app.sync_file_stat";
public static final String SHOW_DIALOG_DISABLE_PLUGIN = "app.show_dialog_disable_plugin";
}
}

/**
* Creates a new ApplicationDefaults.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ private void initialize() {
previousExecutionSafelyTerminated = false;
}

preferences.put(ApplicationDefaults.APPLICATION_STATE_KEY, ApplicationState.RUNNING.getText());
preferences.put(ApplicationDefaults.Prefs.App.STATE, ApplicationState.RUNNING.getText());
}

@PreDestroy
private void destroy() {
log.info("Application monitor received shutdown event");
preferences.put(ApplicationDefaults.APPLICATION_STATE_KEY, ApplicationState.TERMINATED.getText());
preferences.put(ApplicationDefaults.Prefs.App.STATE, ApplicationState.TERMINATED.getText());

}

Expand All @@ -61,7 +61,7 @@ private void destroy() {
* @return state
*/
public ApplicationState getState() {
String stateValue = preferences.get(ApplicationDefaults.APPLICATION_STATE_KEY, "UNKNOWN");
String stateValue = preferences.get(ApplicationDefaults.Prefs.App.STATE, "UNKNOWN");
return ApplicationState.fromString(stateValue);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import java.util.prefs.Preferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

/**
* Preferences wrapper supporting string list persistence.
*/
@Component
@DependsOn("preferencesMigration")
public class ApplicationPreferences {

private final Logger log = LoggerFactory.getLogger(this.getClass());
Expand Down Expand Up @@ -61,6 +63,14 @@ public void putBoolean(String key, boolean value) {
basePreferences.putBoolean(key, value);
}

public int getInt(String key, int def) {
return basePreferences.getInt(key, def);
}

public void putInt(String key, int value) {
basePreferences.putInt(key, value);
}

public long getLong(String key, long def) {
return basePreferences.getLong(key, def);
}
Expand Down Expand Up @@ -101,6 +111,10 @@ public void putList(String key, List<String> value) {
}
}

public void remove(String key) {
basePreferences.remove(key);
}

public void clear() throws BackingStoreException {
this.basePreferences.clear();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* OwlPlug
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
*
* This file is part of OwlPlug.
*
* OwlPlug is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* OwlPlug 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owlplug.core.components;

import com.owlplug.core.components.ApplicationDefaults.Prefs;
import jakarta.annotation.PostConstruct;
import java.util.Map;
import java.util.prefs.Preferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
* Migrates legacy flat preference keys to the current hierarchical key scheme.
* Runs once at startup before OptionsService initializes defaults.
* Bump MIGRATION_VERSION whenever new entries are added to MIGRATIONS.
*/
@Component
public class PreferencesMigration {

private final Logger log = LoggerFactory.getLogger(this.getClass());

private static final String MIGRATION_VERSION_KEY = "app.migration_version";
private static final int MIGRATION_VERSION = 2;

private static final Map<String, String> MIGRATIONS = Map.ofEntries(
Map.entry("VST_DIRECTORY", Prefs.Plugins.VST2_DIRECTORY),
Map.entry("VST2_DISCOVERY_ENABLED", Prefs.Plugins.VST2_DISCOVERY_ENABLED),
Map.entry("VST2_EXTRA_DIRECTORY_KEY", Prefs.Plugins.VST2_EXTRA_DIRECTORY),
Map.entry("VST3_DIRECTORY", Prefs.Plugins.VST3_DIRECTORY),
Map.entry("VST3_DISCOVERY_ENABLED", Prefs.Plugins.VST3_DISCOVERY_ENABLED),
Map.entry("VST3_EXTRA_DIRECTORY_KEY", Prefs.Plugins.VST3_EXTRA_DIRECTORY),
Map.entry("AU_DIRECTORY_KEY", Prefs.Plugins.AU_DIRECTORY),
Map.entry("AU_DISCOVERY_ENABLED_KEY", Prefs.Plugins.AU_DISCOVERY_ENABLED),
Map.entry("AU_EXTRA_DIRECTORY_KEY", Prefs.Plugins.AU_EXTRA_DIRECTORY),
Map.entry("LV2_DIRECTORY_KEY", Prefs.Plugins.LV2_DIRECTORY),
Map.entry("LV2_DISCOVERY_ENABLED_KEY", Prefs.Plugins.LV2_DISCOVERY_ENABLED),
Map.entry("LV2_EXTRA_DIRECTORY_KEY", Prefs.Plugins.LV2_EXTRA_DIRECTORY),
Map.entry("NATIVE_HOST_ENABLED_KEY", Prefs.Plugins.NativeHost.ENABLED),
Map.entry("PREFERRED_NATIVE_LOADER", Prefs.Plugins.NativeHost.PREFERRED_LOADER),
Map.entry("NATIVE_LOADER_TIMEOUT_KEY", Prefs.Plugins.NativeHost.LOADER_TIMEOUT),
Map.entry("SELECTED_ACCOUNT_KEY", Prefs.Auth.SELECTED_ACCOUNT),
Map.entry("SYNC_PLUGINS_STARTUP_KEY", Prefs.App.SYNC_PLUGINS_ON_STARTUP),
Map.entry("STORE_DIRECTORY_ENABLED_KEY", Prefs.Explore.STORE_DIRECTORY_ENABLED),
Map.entry("STORE_BY_CREATOR_ENABLED_KEY", Prefs.Explore.STORE_BY_CREATOR_ENABLED),
Map.entry("STORE_DIRECTORY_KEY", Prefs.Explore.STORE_DIRECTORY),
Map.entry("STORE_SUBDIRECTORY_ENABLED", Prefs.Explore.STORE_SUBDIRECTORY_ENABLED),
Map.entry("FIRST_LAUNCH_KEY", Prefs.App.FIRST_LAUNCH),
Map.entry("APPLICATION_STATE_KEY", Prefs.App.STATE),
Map.entry("SHOW_DIALOG_DISABLE_PLUGIN_KEY", Prefs.App.SHOW_DIALOG_DISABLE_PLUGIN),
Map.entry("PROJECT_DIRECTORY_KEY", Prefs.Projects.DIRECTORY),
Map.entry("PLUGIN_PREFERRED_DISPLAY_KEY", Prefs.Plugins.PREFERRED_DISPLAY),
Map.entry("SYNC_FILE_STAT_KEY", Prefs.App.SYNC_FILE_STAT),
Map.entry("TELEMETRY_ENABLED_KEY", Prefs.Telemetry.ENABLED),
Map.entry("TELEMETRY_USER_ID_KEY", Prefs.Telemetry.USER_ID),
Map.entry("LAST_PLUGIN_SCAN_DATE_KEY", Prefs.Plugins.LAST_SCAN_DATE)
);

private final Preferences prefs = Preferences.userRoot().node("com.owlplug.user");

@PostConstruct
public void migrate() {
int appliedVersion = prefs.getInt(MIGRATION_VERSION_KEY, 0);
if (appliedVersion >= MIGRATION_VERSION) {
return;
}

MIGRATIONS.forEach((oldKey, newKey) -> {
String value = prefs.get(oldKey, null);
if (value != null && prefs.get(newKey, null) == null) {
prefs.put(newKey, value);
prefs.remove(oldKey);
log.debug("Migrated preference key {} -> {}", oldKey, newKey);
}
});

prefs.putInt(MIGRATION_VERSION_KEY, MIGRATION_VERSION);
log.info("Preferences migrated to version {}", MIGRATION_VERSION);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.owlplug.core.controllers;

import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.ApplicationDefaults.Prefs;
import com.owlplug.core.utils.Async;
import com.owlplug.core.utils.FX;
import com.owlplug.core.utils.TimeUtils;
Expand Down Expand Up @@ -242,7 +243,7 @@ public void refresh() {
pluginService.getDirectoriesExplorationSet().size(),
projectService.getProjectDirectories().size(),
fileStatRepository.findTop5ByParentIsNullOrderByLengthDesc(),
getPreferences().getLong(ApplicationDefaults.LAST_PLUGIN_SCAN_DATE_KEY, 0L)
getPreferences().getLong(Prefs.Plugins.LAST_SCAN_DATE, 0L)
)).thenAccept(data -> FX.run(() -> {
lastScanLabel.setText(data.lastScanTimestamp() == 0L ? "Never scanned"
: "Last scan: " + TimeUtils.getHumanReadableDurationFrom(new Date(data.lastScanTimestamp())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.owlplug.controls.Drawer;
import com.owlplug.controls.transitions.AnimatedTabListener;
import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.ApplicationDefaults.Prefs;
import com.owlplug.core.components.ApplicationMonitor;
import com.owlplug.core.components.ImageCache;
import com.owlplug.core.components.LazyViewRegistry;
Expand Down Expand Up @@ -145,7 +146,7 @@ public void initialize() {

}
if (newValue instanceof UserAccount userAccount) {
this.getPreferences().putLong(ApplicationDefaults.SELECTED_ACCOUNT_KEY, userAccount.getId());
this.getPreferences().putLong(Prefs.Auth.SELECTED_ACCOUNT, userAccount.getId());
Comment thread
coderabbitai[bot] marked this conversation as resolved.

}
accountComboBox.hide();
Expand Down Expand Up @@ -183,14 +184,14 @@ public void dispatchPostInitialize() {

refreshAccounts();

boolean firstLaunch = this.getPreferences().getBoolean(ApplicationDefaults.FIRST_LAUNCH_KEY, true);
boolean firstLaunch = this.getPreferences().getBoolean(Prefs.App.FIRST_LAUNCH, true);
if (!this.applicationMonitor.isPreviousExecutionSafelyTerminated()) {
log.info("Previous execution not terminated safely, opening crash recovery dialog");
crashRecoveryDialogController.show();
} else if (firstLaunch) {
welcomeDialogController.show();
exploreTaskFactory.createSourceSyncTask().schedule();
this.getPreferences().putBoolean(ApplicationDefaults.FIRST_LAUNCH_KEY, false);
this.getPreferences().putBoolean(Prefs.App.FIRST_LAUNCH, false);
publisher.publishEvent(new PreferencesChangedEvent());
}

Expand All @@ -201,7 +202,7 @@ public void dispatchPostInitialize() {
// Startup plugin sync only triggered if configured and previous application
// instance safely terminated
if (this.applicationMonitor.isPreviousExecutionSafelyTerminated()
&& this.getPreferences().getBoolean(ApplicationDefaults.SYNC_PLUGINS_STARTUP_KEY, false)) {
&& this.getPreferences().getBoolean(Prefs.App.SYNC_PLUGINS_ON_STARTUP, false)) {
log.info("Starting auto plugin sync");
pluginService.scanPlugins(false);
}
Expand All @@ -228,7 +229,7 @@ public void refreshAccounts() {
accountComboBox.getItems().setAll(accounts);
accountComboBox.getItems().add(new AccountMenuItem(" + New Account"));

long selectedAccountId = this.getPreferences().getLong(ApplicationDefaults.SELECTED_ACCOUNT_KEY, -1);
long selectedAccountId = this.getPreferences().getLong(Prefs.Auth.SELECTED_ACCOUNT, -1);
if (selectedAccountId != -1) {
Optional<UserAccount> selectedAccount = authenticationService.getUserAccountById(selectedAccountId);
if (selectedAccount.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.owlplug.controls.DialogLayout;
import com.owlplug.core.components.ApplicationDefaults;
import com.owlplug.core.components.ApplicationDefaults.Prefs;
import com.owlplug.core.components.LazyViewRegistry;
import com.owlplug.core.events.PreferencesChangedEvent;
import com.owlplug.core.utils.PlatformUtils;
Expand Down Expand Up @@ -90,10 +91,10 @@ public void initialize() {

nativeDiscoveryCheckbox.setDisable(!nativeHostService.isNativeHostAvailable());
nativeDiscoveryCheckbox.setSelected(this.getPreferences().getBoolean(
ApplicationDefaults.NATIVE_HOST_ENABLED_KEY, false));
Prefs.Plugins.NativeHost.ENABLED, false));

nativeDiscoveryCheckbox.selectedProperty().addListener((observable, oldValue, newValue) -> {
this.getPreferences().putBoolean(ApplicationDefaults.NATIVE_HOST_ENABLED_KEY, newValue);
this.getPreferences().putBoolean(Prefs.Plugins.NativeHost.ENABLED, newValue);
this.pluginNativeComboBox.setDisable(!newValue);
});

Expand All @@ -103,7 +104,7 @@ public void initialize() {

pluginNativeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
this.getPreferences().put(ApplicationDefaults.PREFERRED_NATIVE_LOADER, newValue.getId());
this.getPreferences().put(Prefs.Plugins.NativeHost.PREFERRED_LOADER, newValue.getId());
nativeHostService.setCurrentPluginLoader(newValue);
}
});
Expand Down Expand Up @@ -139,7 +140,7 @@ public void initialize() {

this.getTelemetryService().event("/Error/PluginScanIncomplete", p -> {
p.put("nativeDiscoveryLoader", this.getPreferences().get(
ApplicationDefaults.PREFERRED_NATIVE_LOADER, "unknown"));
Prefs.Plugins.NativeHost.PREFERRED_LOADER, "unknown"));
p.put("pluginName", plugin.getName());
p.put("pluginFormat", plugin.getFormat().getText());
});
Expand Down
Loading
Loading