Skip to content

Commit 62db7ee

Browse files
authored
Merge pull request #75 from zugaldia/az-maxlength
Enable maxLength on credential entry rows for Adw >= 1.6
2 parents 1301915 + 92188ab commit 62db7ee

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

app/src/main/kotlin/com/zugaldia/speedofsound/app/App.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ class SosApplication(applicationId: String, flags: Set<ApplicationFlags>) : Appl
3131

3232
init {
3333
onStartup {
34-
// We should update to a newer version of Adw once the new Ubuntu 26.04 LTS is out (and update
35-
// the Flatpak + Snap targets accordingly). There are some nice widgets we could use (e.g., WrapBox
36-
// in the preferences screen, ShortcutsDialog).
3734
val adwVersion = "${Adw.getMajorVersion()}.${Adw.getMinorVersion()}.${Adw.getMicroVersion()}"
3835
logger.info("Application started with Adw v$adwVersion.")
39-
if (Adw.getMajorVersion() < MIN_ADW_MAJOR_VERSION ||
40-
(Adw.getMajorVersion() == MIN_ADW_MAJOR_VERSION && Adw.getMinorVersion() < MIN_ADW_MINOR_VERSION)) {
36+
if (!isAdwVersionAtLeast(MIN_ADW_MAJOR_VERSION, MIN_ADW_MINOR_VERSION)) {
4137
logger.warn(
42-
"Detected libadwaita v$adwVersion, but v1.5 or newer is required. " +
43-
"The application might not work correctly."
38+
"Detected libadwaita v$adwVersion, but v$MIN_ADW_MAJOR_VERSION.$MIN_ADW_MINOR_VERSION " +
39+
"or newer is required. The application might not work correctly."
4440
)
4541
}
4642

app/src/main/kotlin/com/zugaldia/speedofsound/app/AppConstants.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const val ENV_COLOR_SCHEME = "SOS_COLOR_SCHEME"
1212
const val MIN_ADW_MAJOR_VERSION = 1
1313
const val MIN_ADW_MINOR_VERSION = 5
1414

15+
const val ADW_MAX_LENGTH_MIN_MAJOR_VERSION = 1
16+
const val ADW_MAX_LENGTH_MIN_MINOR_VERSION = 6
17+
1518
const val DEFAULT_WINDOW_WIDTH = 400
1619
const val DEFAULT_WINDOW_HEIGHT = 200
1720

app/src/main/kotlin/com/zugaldia/speedofsound/app/AppUtils.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
package com.zugaldia.speedofsound.app
22

3+
import org.gnome.adw.Adw
34
import org.gnome.adw.ColorScheme
45

6+
/**
7+
* Returns true if the runtime libadwaita version is at least [major].[minor].[micro].
8+
*/
9+
fun isAdwVersionAtLeast(major: Int, minor: Int = 0, micro: Int = 0): Boolean {
10+
val runtimeMajor = Adw.getMajorVersion()
11+
val runtimeMinor = Adw.getMinorVersion()
12+
val runtimeMicro = Adw.getMicroVersion()
13+
return when {
14+
runtimeMajor != major -> runtimeMajor > major
15+
runtimeMinor != minor -> runtimeMinor > minor
16+
else -> runtimeMicro >= micro
17+
}
18+
}
19+
520
/**
621
* Checks if the GIO store is disabled.
722
*/

app/src/main/kotlin/com/zugaldia/speedofsound/app/screens/preferences/credentials/AddCredentialDialog.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import com.zugaldia.speedofsound.app.DEFAULT_MARGIN
77
import com.zugaldia.speedofsound.app.MAX_CREDENTIAL_NAME_LENGTH
88
import com.zugaldia.speedofsound.app.MAX_CREDENTIAL_VALUE_LENGTH
99
import com.zugaldia.speedofsound.app.STYLE_CLASS_SUGGESTED_ACTION
10+
import com.zugaldia.speedofsound.app.ADW_MAX_LENGTH_MIN_MAJOR_VERSION
11+
import com.zugaldia.speedofsound.app.ADW_MAX_LENGTH_MIN_MINOR_VERSION
12+
import com.zugaldia.speedofsound.app.isAdwVersionAtLeast
1013
import com.zugaldia.speedofsound.core.desktop.settings.CredentialSetting
1114
import com.zugaldia.speedofsound.core.desktop.settings.CredentialType
1215
import com.zugaldia.speedofsound.core.generateUniqueId
@@ -35,19 +38,16 @@ class AddCredentialDialog(
3538
contentWidth = DEFAULT_ADD_CREDENTIAL_DIALOG_WIDTH
3639
contentHeight = DEFAULT_ADD_CREDENTIAL_DIALOG_HEIGHT
3740

41+
val supportsMaxLength = isAdwVersionAtLeast(ADW_MAX_LENGTH_MIN_MAJOR_VERSION, ADW_MAX_LENGTH_MIN_MINOR_VERSION)
42+
3843
nameEntry = EntryRow().apply {
3944
title = "Name"
40-
// Cannot set (report upstream?), otherwise the app crashes with:
41-
// (java:1284576): java-gi-WARNING **: 09:04:54.126: java.lang.AssertionError:
42-
// java.lang.invoke.WrongMethodTypeException: handle's method type (Object[])Object
43-
// but found (MemorySegment, int)void in ClickedCallback
44-
//maxLength = MAX_CREDENTIAL_NAME_LENGTH
45+
if (supportsMaxLength) maxLength = MAX_CREDENTIAL_NAME_LENGTH
4546
}
4647

4748
apiKeyEntry = PasswordEntryRow().apply {
4849
title = "API Key"
49-
// Do not set (see comment above)
50-
//maxLength = MAX_CREDENTIAL_VALUE_LENGTH
50+
if (supportsMaxLength) maxLength = MAX_CREDENTIAL_VALUE_LENGTH
5151
}
5252

5353
val preferencesGroup = PreferencesGroup().apply {
@@ -111,7 +111,9 @@ class AddCredentialDialog(
111111

112112
@Suppress("ReturnCount")
113113
private fun validateInput(name: String, apiKey: String): Boolean {
114-
if (name.isEmpty() || apiKey.isEmpty()) { return false }
114+
if (name.isEmpty() || apiKey.isEmpty()) {
115+
return false
116+
}
115117
if (name.length > MAX_CREDENTIAL_NAME_LENGTH) {
116118
logger.warn("Credential name too long: ${name.length} > $MAX_CREDENTIAL_NAME_LENGTH")
117119
return false

0 commit comments

Comments
 (0)