diff --git a/app/src/main/kotlin/com/zugaldia/speedofsound/app/App.kt b/app/src/main/kotlin/com/zugaldia/speedofsound/app/App.kt index c610728..a2eb8d7 100644 --- a/app/src/main/kotlin/com/zugaldia/speedofsound/app/App.kt +++ b/app/src/main/kotlin/com/zugaldia/speedofsound/app/App.kt @@ -31,16 +31,12 @@ class SosApplication(applicationId: String, flags: Set) : Appl init { onStartup { - // We should update to a newer version of Adw once the new Ubuntu 26.04 LTS is out (and update - // the Flatpak + Snap targets accordingly). There are some nice widgets we could use (e.g., WrapBox - // in the preferences screen, ShortcutsDialog). val adwVersion = "${Adw.getMajorVersion()}.${Adw.getMinorVersion()}.${Adw.getMicroVersion()}" logger.info("Application started with Adw v$adwVersion.") - if (Adw.getMajorVersion() < MIN_ADW_MAJOR_VERSION || - (Adw.getMajorVersion() == MIN_ADW_MAJOR_VERSION && Adw.getMinorVersion() < MIN_ADW_MINOR_VERSION)) { + if (!isAdwVersionAtLeast(MIN_ADW_MAJOR_VERSION, MIN_ADW_MINOR_VERSION)) { logger.warn( - "Detected libadwaita v$adwVersion, but v1.5 or newer is required. " + - "The application might not work correctly." + "Detected libadwaita v$adwVersion, but v$MIN_ADW_MAJOR_VERSION.$MIN_ADW_MINOR_VERSION " + + "or newer is required. The application might not work correctly." ) } diff --git a/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppConstants.kt b/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppConstants.kt index ef1365e..7166cdb 100644 --- a/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppConstants.kt +++ b/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppConstants.kt @@ -12,6 +12,9 @@ const val ENV_COLOR_SCHEME = "SOS_COLOR_SCHEME" const val MIN_ADW_MAJOR_VERSION = 1 const val MIN_ADW_MINOR_VERSION = 5 +const val ADW_MAX_LENGTH_MIN_MAJOR_VERSION = 1 +const val ADW_MAX_LENGTH_MIN_MINOR_VERSION = 6 + const val DEFAULT_WINDOW_WIDTH = 400 const val DEFAULT_WINDOW_HEIGHT = 200 diff --git a/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppUtils.kt b/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppUtils.kt index 4e9aead..0965a96 100644 --- a/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppUtils.kt +++ b/app/src/main/kotlin/com/zugaldia/speedofsound/app/AppUtils.kt @@ -1,7 +1,22 @@ package com.zugaldia.speedofsound.app +import org.gnome.adw.Adw import org.gnome.adw.ColorScheme +/** + * Returns true if the runtime libadwaita version is at least [major].[minor].[micro]. + */ +fun isAdwVersionAtLeast(major: Int, minor: Int = 0, micro: Int = 0): Boolean { + val runtimeMajor = Adw.getMajorVersion() + val runtimeMinor = Adw.getMinorVersion() + val runtimeMicro = Adw.getMicroVersion() + return when { + runtimeMajor != major -> runtimeMajor > major + runtimeMinor != minor -> runtimeMinor > minor + else -> runtimeMicro >= micro + } +} + /** * Checks if the GIO store is disabled. */ diff --git a/app/src/main/kotlin/com/zugaldia/speedofsound/app/screens/preferences/credentials/AddCredentialDialog.kt b/app/src/main/kotlin/com/zugaldia/speedofsound/app/screens/preferences/credentials/AddCredentialDialog.kt index b189d82..c833071 100644 --- a/app/src/main/kotlin/com/zugaldia/speedofsound/app/screens/preferences/credentials/AddCredentialDialog.kt +++ b/app/src/main/kotlin/com/zugaldia/speedofsound/app/screens/preferences/credentials/AddCredentialDialog.kt @@ -7,6 +7,9 @@ import com.zugaldia.speedofsound.app.DEFAULT_MARGIN import com.zugaldia.speedofsound.app.MAX_CREDENTIAL_NAME_LENGTH import com.zugaldia.speedofsound.app.MAX_CREDENTIAL_VALUE_LENGTH import com.zugaldia.speedofsound.app.STYLE_CLASS_SUGGESTED_ACTION +import com.zugaldia.speedofsound.app.ADW_MAX_LENGTH_MIN_MAJOR_VERSION +import com.zugaldia.speedofsound.app.ADW_MAX_LENGTH_MIN_MINOR_VERSION +import com.zugaldia.speedofsound.app.isAdwVersionAtLeast import com.zugaldia.speedofsound.core.desktop.settings.CredentialSetting import com.zugaldia.speedofsound.core.desktop.settings.CredentialType import com.zugaldia.speedofsound.core.generateUniqueId @@ -35,19 +38,16 @@ class AddCredentialDialog( contentWidth = DEFAULT_ADD_CREDENTIAL_DIALOG_WIDTH contentHeight = DEFAULT_ADD_CREDENTIAL_DIALOG_HEIGHT + val supportsMaxLength = isAdwVersionAtLeast(ADW_MAX_LENGTH_MIN_MAJOR_VERSION, ADW_MAX_LENGTH_MIN_MINOR_VERSION) + nameEntry = EntryRow().apply { title = "Name" - // Cannot set (report upstream?), otherwise the app crashes with: - // (java:1284576): java-gi-WARNING **: 09:04:54.126: java.lang.AssertionError: - // java.lang.invoke.WrongMethodTypeException: handle's method type (Object[])Object - // but found (MemorySegment, int)void in ClickedCallback - //maxLength = MAX_CREDENTIAL_NAME_LENGTH + if (supportsMaxLength) maxLength = MAX_CREDENTIAL_NAME_LENGTH } apiKeyEntry = PasswordEntryRow().apply { title = "API Key" - // Do not set (see comment above) - //maxLength = MAX_CREDENTIAL_VALUE_LENGTH + if (supportsMaxLength) maxLength = MAX_CREDENTIAL_VALUE_LENGTH } val preferencesGroup = PreferencesGroup().apply { @@ -111,7 +111,9 @@ class AddCredentialDialog( @Suppress("ReturnCount") private fun validateInput(name: String, apiKey: String): Boolean { - if (name.isEmpty() || apiKey.isEmpty()) { return false } + if (name.isEmpty() || apiKey.isEmpty()) { + return false + } if (name.length > MAX_CREDENTIAL_NAME_LENGTH) { logger.warn("Credential name too long: ${name.length} > $MAX_CREDENTIAL_NAME_LENGTH") return false