Created
September 27, 2022 21:30
-
-
Save migueldeicaza/f1eaa27b166f5d7ba8cb28f7c020b15f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/SwiftTermApp/Connections.swift b/SwiftTermApp/Connections.swift | |
index 3d37b29..92e862e 100644 | |
--- a/SwiftTermApp/Connections.swift | |
+++ b/SwiftTermApp/Connections.swift | |
@@ -22,15 +22,7 @@ class Connections: ObservableObject { | |
@Published public var sessions: [Session] = [ | |
] | |
- public var terminalsCount: Int { | |
- dispatchPrecondition(condition: .onQueue(DispatchQueue.main)) | |
- | |
- var count = 0 | |
- for session in sessions { | |
- count += session.terminals.count | |
- } | |
- return count | |
- } | |
+ @Published public var terminalsCount: Int = 0 | |
public func active () -> Bool { | |
return sessions.count > 0 | |
@@ -51,6 +43,7 @@ class Connections: ObservableObject { | |
return | |
} | |
shared.sessions.append(session) | |
+ shared.terminalsCount += 1 | |
// This is used to track whether we should keep the display on, only when we have active sessions | |
settings.updateKeepOn() | |
@@ -70,6 +63,7 @@ class Connections: ObservableObject { | |
DispatchQueue.main.async { | |
if let idx = shared.sessions.firstIndex(of: session) { | |
shared.sessions.remove(at: idx) | |
+ shared.terminalsCount -= 1 | |
} | |
settings.updateKeepOn() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment