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
10 changes: 3 additions & 7 deletions app/src/main/kotlin/com/zugaldia/speedofsound/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ class SosApplication(applicationId: String, flags: Set<ApplicationFlags>) : 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."
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/kotlin/com/zugaldia/speedofsound/app/AppUtils.kt
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading