-
-
Notifications
You must be signed in to change notification settings - Fork 473
Coalesce idempotent refreshSession calls triggered by event handlers #1249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,25 @@ func refreshAndLayout(_ event: RefreshSessionEvent, screenIsDefinitelyUnlocked: | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| refreshSession(event, screenIsDefinitelyUnlocked: screenIsDefinitelyUnlocked, startup: startup, body: {}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @MainActor private var havePendingRefresh = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @MainActor private var pendingRefreshScreenIsDefinitelyUnlocked = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @MainActor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func scheduleRefreshAndLayout(_ event: RefreshSessionEvent, screenIsDefinitelyUnlocked: Bool = false) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if havePendingRefresh { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if screenIsDefinitelyUnlocked { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pendingRefreshScreenIsDefinitelyUnlocked = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| havePendingRefresh = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pendingRefreshScreenIsDefinitelyUnlocked = screenIsDefinitelyUnlocked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+62
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels more natural to me to coalesce the latest
Suggested change
This way we will run the next refresh session with the latest known wdyt?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My logic for preferring true here was that the comments at AeroSpace/Sources/AppBundle/tree/frozen/closedWindowsCache.swift Lines 111 to 124 in ae0e577
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, makes sense. Merged with the following cleanup patch: diff --git a/Sources/AppBundle/initAppBundle.swift b/Sources/AppBundle/initAppBundle.swift
index 38751b79..c64d0fc8 100644
--- a/Sources/AppBundle/initAppBundle.swift
+++ b/Sources/AppBundle/initAppBundle.swift
@@ -23,7 +23,7 @@ import Foundation
AXUIElementSetMessagingTimeout(AXUIElementCreateSystemWide(), 1.0)
startUnixSocketServer()
GlobalObserver.initObserver()
- refreshAndLayout(.startup1, screenIsDefinitelyUnlocked: false, startup: true)
+ refreshSession(.startup1, screenIsDefinitelyUnlocked: false, startup: true, body: {})
refreshSession(.startup2, screenIsDefinitelyUnlocked: false) {
if serverArgs.startedAtLogin {
_ = config.afterLoginCommand.runCmdSeq(.defaultEnv, .emptyStdin)
diff --git a/Sources/AppBundle/layout/refresh.swift b/Sources/AppBundle/layout/refresh.swift
index 8ac24370..91cafb31 100644
--- a/Sources/AppBundle/layout/refresh.swift
+++ b/Sources/AppBundle/layout/refresh.swift
@@ -42,27 +42,16 @@ func refreshSession<T>(_ event: RefreshSessionEvent, screenIsDefinitelyUnlocked:
return result
}
-@MainActor
-func refreshAndLayout(_ event: RefreshSessionEvent, screenIsDefinitelyUnlocked: Bool, startup: Bool = false) {
- refreshSession(event, screenIsDefinitelyUnlocked: screenIsDefinitelyUnlocked, startup: startup, body: {})
-}
-
@MainActor private var havePendingRefresh = false
-@MainActor private var pendingRefreshScreenIsDefinitelyUnlocked = false
@MainActor
func scheduleRefreshAndLayout(_ event: RefreshSessionEvent, screenIsDefinitelyUnlocked: Bool = false) {
- if havePendingRefresh {
- if screenIsDefinitelyUnlocked {
- pendingRefreshScreenIsDefinitelyUnlocked = true
- }
- return
- }
+ if screenIsDefinitelyUnlocked { resetClosedWindowsCache() }
+ if havePendingRefresh { return }
havePendingRefresh = true
- pendingRefreshScreenIsDefinitelyUnlocked = screenIsDefinitelyUnlocked
DispatchQueue.main.async { @MainActor in
havePendingRefresh = false
- refreshSession(event, screenIsDefinitelyUnlocked: pendingRefreshScreenIsDefinitelyUnlocked, startup: false, body: {})
+ refreshSession(event, screenIsDefinitelyUnlocked: false, startup: false, body: {})
}
}
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DispatchQueue.main.async { @MainActor in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| havePendingRefresh = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| refreshSession(event, screenIsDefinitelyUnlocked: pendingRefreshScreenIsDefinitelyUnlocked, startup: false, body: {}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @MainActor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func refreshModel() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gc() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -81,7 +100,7 @@ func refreshObs(_ obs: AXObserver, ax: AXUIElement, notif: CFString, data: Unsaf | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| check(Thread.isMainThread) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let notif = notif as String | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MainActor.assumeIsolated { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| refreshAndLayout(.ax(notif), screenIsDefinitelyUnlocked: false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scheduleRefreshAndLayout(.ax(notif), screenIsDefinitelyUnlocked: false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
ifproves that it's not 100% idempotent :/screenIsDefinitelyUnlockedis definitely a hack anyway that I hope to get rid of in scope #1215 + #1216