From 97fa86d8f0f73232119040dca264566f1dc22772 Mon Sep 17 00:00:00 2001 From: bbedward Date: Wed, 22 Apr 2026 10:32:05 -0400 Subject: [PATCH] loginctl: simplify event handling --- core/internal/server/loginctl/types.go | 7 +- core/internal/server/loginctl/types_test.go | 9 +-- core/internal/version/version_test.go | 72 --------------------- quickshell/Common/Theme.qml | 14 +--- quickshell/DMSShell.qml | 12 ++-- quickshell/Services/DMSService.qml | 7 +- quickshell/Services/DisplayService.qml | 9 ++- quickshell/Services/SessionService.qml | 17 ----- 8 files changed, 18 insertions(+), 129 deletions(-) diff --git a/core/internal/server/loginctl/types.go b/core/internal/server/loginctl/types.go index 76c74142..c3df1920 100644 --- a/core/internal/server/loginctl/types.go +++ b/core/internal/server/loginctl/types.go @@ -35,12 +35,7 @@ type SessionState struct { type EventType string const ( - EventStateChanged EventType = "state_changed" - EventLock EventType = "lock" - EventUnlock EventType = "unlock" - EventPrepareForSleep EventType = "prepare_for_sleep" - EventIdleHintChanged EventType = "idle_hint_changed" - EventLockedHintChanged EventType = "locked_hint_changed" + EventStateChanged EventType = "state_changed" ) type SessionEvent struct { diff --git a/core/internal/server/loginctl/types_test.go b/core/internal/server/loginctl/types_test.go index 383300fb..69e39917 100644 --- a/core/internal/server/loginctl/types_test.go +++ b/core/internal/server/loginctl/types_test.go @@ -8,11 +8,6 @@ import ( func TestEventType_Constants(t *testing.T) { assert.Equal(t, EventType("state_changed"), EventStateChanged) - assert.Equal(t, EventType("lock"), EventLock) - assert.Equal(t, EventType("unlock"), EventUnlock) - assert.Equal(t, EventType("prepare_for_sleep"), EventPrepareForSleep) - assert.Equal(t, EventType("idle_hint_changed"), EventIdleHintChanged) - assert.Equal(t, EventType("locked_hint_changed"), EventLockedHintChanged) } func TestSessionState_Struct(t *testing.T) { @@ -40,11 +35,11 @@ func TestSessionEvent_Struct(t *testing.T) { } event := SessionEvent{ - Type: EventLock, + Type: EventStateChanged, Data: state, } - assert.Equal(t, EventLock, event.Type) + assert.Equal(t, EventStateChanged, event.Type) assert.Equal(t, "1", event.Data.SessionID) assert.True(t, event.Data.Locked) } diff --git a/core/internal/version/version_test.go b/core/internal/version/version_test.go index 1e424c17..0fe12e95 100644 --- a/core/internal/version/version_test.go +++ b/core/internal/version/version_test.go @@ -2,12 +2,10 @@ package version import ( "os" - "os/exec" "path/filepath" "testing" mocks_version "github.com/AvengeMedia/DankMaterialShell/core/internal/mocks/version" - "github.com/AvengeMedia/DankMaterialShell/core/internal/utils" ) func TestCompareVersions(t *testing.T) { @@ -150,76 +148,6 @@ func TestGetCurrentDMSVersion_NotInstalled(t *testing.T) { } } -func TestGetCurrentDMSVersion_GitTag(t *testing.T) { - if !utils.CommandExists("git") { - t.Skip("git not available") - } - - tempDir := t.TempDir() - dmsPath := filepath.Join(tempDir, ".config", "quickshell", "dms") - os.MkdirAll(dmsPath, 0o755) - - originalHome := os.Getenv("HOME") - defer os.Setenv("HOME", originalHome) - os.Setenv("HOME", tempDir) - - exec.Command("git", "init", dmsPath).Run() - exec.Command("git", "-C", dmsPath, "config", "user.email", "test@test.com").Run() - exec.Command("git", "-C", dmsPath, "config", "user.name", "Test User").Run() - - testFile := filepath.Join(dmsPath, "test.txt") - os.WriteFile(testFile, []byte("test"), 0o644) - exec.Command("git", "-C", dmsPath, "add", ".").Run() - exec.Command("git", "-C", dmsPath, "commit", "-m", "initial").Run() - exec.Command("git", "-C", dmsPath, "tag", "v0.1.0").Run() - - version, err := GetCurrentDMSVersion() - if err != nil { - t.Fatalf("GetCurrentDMSVersion() failed: %v", err) - } - - if version != "v0.1.0" { - t.Errorf("Expected version v0.1.0, got %s", version) - } -} - -func TestGetCurrentDMSVersion_GitBranch(t *testing.T) { - if !utils.CommandExists("git") { - t.Skip("git not available") - } - - tempDir := t.TempDir() - dmsPath := filepath.Join(tempDir, ".config", "quickshell", "dms") - os.MkdirAll(dmsPath, 0o755) - - originalHome := os.Getenv("HOME") - defer os.Setenv("HOME", originalHome) - os.Setenv("HOME", tempDir) - - exec.Command("git", "init", dmsPath).Run() - exec.Command("git", "-C", dmsPath, "config", "user.email", "test@test.com").Run() - exec.Command("git", "-C", dmsPath, "config", "user.name", "Test User").Run() - exec.Command("git", "-C", dmsPath, "checkout", "-b", "master").Run() - - testFile := filepath.Join(dmsPath, "test.txt") - os.WriteFile(testFile, []byte("test"), 0o644) - exec.Command("git", "-C", dmsPath, "add", ".").Run() - exec.Command("git", "-C", dmsPath, "commit", "-m", "initial").Run() - - version, err := GetCurrentDMSVersion() - if err != nil { - t.Fatalf("GetCurrentDMSVersion() failed: %v", err) - } - - if version == "" { - t.Error("Expected non-empty version") - } - - if len(version) < 7 { - t.Errorf("Expected version with branch@commit format, got %s", version) - } -} - func TestVersionInfo_IsGit(t *testing.T) { tests := []struct { current string diff --git a/quickshell/Common/Theme.qml b/quickshell/Common/Theme.qml index 04df0b58..b04c854d 100644 --- a/quickshell/Common/Theme.qml +++ b/quickshell/Common/Theme.qml @@ -341,18 +341,6 @@ Singleton { Connections { target: DMSService - enabled: typeof DMSService !== "undefined" && typeof SessionData !== "undefined" - - function onLoginctlEvent(event) { - if (!SessionData.themeModeAutoEnabled) - return; - if (typeof SettingsData !== "undefined" && SettingsData.loginctlLockIntegration) - return; - const eventType = String(event?.type || event?.event || "").toLowerCase(); - if (eventType === "unlock") { - root.triggerThemeAutomationRefresh(); - } - } function onThemeAutoStateUpdate(data) { if (!SessionData.themeModeAutoEnabled) { @@ -415,7 +403,7 @@ Singleton { Connections { target: SessionService - enabled: typeof SessionService !== "undefined" && typeof SessionData !== "undefined" && SessionData.themeModeAutoEnabled + enabled: SessionData.themeModeAutoEnabled function onSessionUnlocked() { root.triggerThemeAutomationRefresh(); diff --git a/quickshell/DMSShell.qml b/quickshell/DMSShell.qml index 21f42775..dcca3c07 100644 --- a/quickshell/DMSShell.qml +++ b/quickshell/DMSShell.qml @@ -247,16 +247,16 @@ Item { repeat: false onTriggered: { root.recreateOsdSurfaces(); + root.pendingOsdResumeReloads--; - if (root.pendingOsdResumeReloads > 1) { - root.pendingOsdResumeReloads--; - interval = 1400; - restart(); + if (root.pendingOsdResumeReloads <= 0) { + root.pendingOsdResumeReloads = 0; + interval = 400; return; } - root.pendingOsdResumeReloads = 0; - interval = 400; + interval = 1400; + restart(); } } diff --git a/quickshell/Services/DMSService.qml b/quickshell/Services/DMSService.qml index 217b96a0..585e2622 100644 --- a/quickshell/Services/DMSService.qml +++ b/quickshell/Services/DMSService.qml @@ -45,7 +45,6 @@ Singleton { signal networkStateUpdate(var data) signal cupsStateUpdate(var data) signal loginctlStateUpdate(var data) - signal loginctlEvent(var event) signal capabilitiesReceived signal credentialsRequest(var data) signal bluetoothPairingRequest(var data) @@ -348,11 +347,7 @@ Singleton { } else if (service === "network.credentials") { credentialsRequest(data); } else if (service === "loginctl") { - if (data.event) { - loginctlEvent(data); - } else { - loginctlStateUpdate(data); - } + loginctlStateUpdate(data); } else if (service === "bluetooth.pairing") { bluetoothPairingRequest(data); } else if (service === "cups") { diff --git a/quickshell/Services/DisplayService.qml b/quickshell/Services/DisplayService.qml index 5fede6af..7666a586 100644 --- a/quickshell/Services/DisplayService.qml +++ b/quickshell/Services/DisplayService.qml @@ -749,8 +749,13 @@ Singleton { runResumeRecoveryPass(); resumeRecoveryAttempt++; - if (resumeRecoveryAttempt < 3) { - interval = resumeRecoveryAttempt === 1 ? 1400 : 2600; + switch (resumeRecoveryAttempt) { + case 1: + interval = 1400; + restart(); + return; + case 2: + interval = 2600; restart(); return; } diff --git a/quickshell/Services/SessionService.qml b/quickshell/Services/SessionService.qml index 90163f1d..c46cb7df 100644 --- a/quickshell/Services/SessionService.qml +++ b/quickshell/Services/SessionService.qml @@ -472,7 +472,6 @@ Singleton { } function onCapabilitiesReceived() { - checkDMSCapabilities(); syncSleepInhibitor(); } } @@ -526,10 +525,6 @@ Singleton { function onLoginctlStateUpdate(data) { updateLoginctlState(data); } - - function onLoginctlEvent(event) { - handleLoginctlEvent(event); - } } function checkDMSCapabilities() { @@ -677,16 +672,4 @@ Singleton { loginctlStateChanged(); } - - function handleLoginctlEvent(event) { - if (event.event === "Lock") { - locked = true; - lockedHint = true; - sessionLocked(); - } else if (event.event === "Unlock") { - locked = false; - lockedHint = false; - sessionUnlocked(); - } - } }