- Notifications
You must be signed in to change notification settings - Fork5
fix: display offline workspaces#41
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
87ec698
fix: unquarantine dylib after download
ethanndickson024d7e3
capitalization
ethanndicksone64ea22
review
ethanndicksonce1883e
fix: display offline workspaces
ethanndickson972f269
review
ethanndickson63442fe
undo dumb idea
ethanndicksonce56128
Merge branch 'main' into ethan/offline-workspaces
ethanndicksonFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 2 additions & 1 deletionCoder Desktop/Coder Desktop/About.swift
This file contains hidden or 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
26 changes: 13 additions & 13 deletionsCoder Desktop/Coder Desktop/Preview Content/PreviewVPN.swift
This file contains hidden or 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
140 changes: 140 additions & 0 deletionsCoder Desktop/Coder Desktop/VPNMenuState.swift
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import Foundation | ||
import SwiftUI | ||
import VPNLib | ||
structAgent:Identifiable,Equatable,Comparable{ | ||
letid:UUID | ||
letname:String | ||
letstatus:AgentStatus | ||
lethosts:[String] | ||
letwsName:String | ||
letwsID:UUID | ||
// Agents are sorted by status, and then by name | ||
staticfunc<(lhs:Agent, rhs:Agent)->Bool{ | ||
if lhs.status!= rhs.status{ | ||
return lhs.status< rhs.status | ||
} | ||
return lhs.wsName.localizedCompare(rhs.wsName)==.orderedAscending | ||
} | ||
// Hosts arrive sorted by length, the shortest looks best in the UI. | ||
varprimaryHost:String?{ hosts.first} | ||
} | ||
enumAgentStatus:Int,Equatable,Comparable{ | ||
case okay=0 | ||
case warn=1 | ||
case error=2 | ||
case off=3 | ||
publicvarcolor:Color{ | ||
switchself{ | ||
case.okay:.green | ||
case.warn:.yellow | ||
case.error:.red | ||
case.off:.gray | ||
} | ||
} | ||
staticfunc<(lhs:AgentStatus, rhs:AgentStatus)->Bool{ | ||
lhs.rawValue< rhs.rawValue | ||
} | ||
} | ||
structWorkspace:Identifiable,Equatable,Comparable{ | ||
letid:UUID | ||
letname:String | ||
varagents:Set<UUID> | ||
staticfunc<(lhs:Workspace, rhs:Workspace)->Bool{ | ||
lhs.name.localizedCompare(rhs.name)==.orderedAscending | ||
} | ||
} | ||
structVPNMenuState{ | ||
varagents:[UUID:Agent]=[:] | ||
varworkspaces:[UUID:Workspace]=[:] | ||
// Upserted agents that don't belong to any known workspace, have no FQDNs, | ||
// or have any invalid UUIDs. | ||
varinvalidAgents:[Vpn_Agent]=[] | ||
mutatingfunc upsertAgent(_ agent:Vpn_Agent){ | ||
guard | ||
let id=UUID(uuidData: agent.id), | ||
let wsID=UUID(uuidData: agent.workspaceID), | ||
var workspace=workspaces[wsID], | ||
!agent.fqdn.isEmpty | ||
else{ | ||
invalidAgents.append(agent) | ||
return | ||
} | ||
// An existing agent with the same name, belonging to the same workspace | ||
// is from a previous workspace build, and should be removed. | ||
agents.filter{ $0.value.name== agent.name && $0.value.wsID== wsID} | ||
.forEach{agents[$0.key]=nil} | ||
workspace.agents.insert(id) | ||
workspaces[wsID]= workspace | ||
agents[id]=Agent( | ||
id: id, | ||
name: agent.name, | ||
// If last handshake was not within last five minutes, the agent is unhealthy | ||
status: agent.lastHandshake.date>Date.now.addingTimeInterval(-300)?.okay:.warn, | ||
// Remove trailing dot if present | ||
hosts: agent.fqdn.map{ $0.hasSuffix(".")?String($0.dropLast()): $0}, | ||
wsName: workspace.name, | ||
wsID: wsID | ||
) | ||
} | ||
mutatingfunc deleteAgent(withId id:Data){ | ||
guardlet agentUUID=UUID(uuidData: id)else{return} | ||
// Update Workspaces | ||
iflet agent=agents[agentUUID],var ws=workspaces[agent.wsID]{ | ||
ws.agents.remove(agentUUID) | ||
workspaces[agent.wsID]= ws | ||
} | ||
agents[agentUUID]=nil | ||
// Remove from invalid agents if present | ||
invalidAgents.removeAll{ invalidAgentin | ||
invalidAgent.id== id | ||
} | ||
} | ||
mutatingfunc upsertWorkspace(_ workspace:Vpn_Workspace){ | ||
guardlet wsID=UUID(uuidData: workspace.id)else{return} | ||
workspaces[wsID]=Workspace(id: wsID, name: workspace.name, agents:[]) | ||
// Check if we can associate any invalid agents with this workspace | ||
invalidAgents.filter{ agentin | ||
agent.workspaceID== workspace.id | ||
}.forEach{ agentin | ||
invalidAgents.removeAll{ $0== agent} | ||
upsertAgent(agent) | ||
} | ||
} | ||
mutatingfunc deleteWorkspace(withId id:Data){ | ||
guardlet wsID=UUID(uuidData: id)else{return} | ||
agents.filter{ _, valuein | ||
value.wsID== wsID | ||
}.forEach{ key, _in | ||
agents[key]=nil | ||
} | ||
workspaces[wsID]=nil | ||
} | ||
varsorted:[VPNMenuItem]{ | ||
varitems= agents.values.map{VPNMenuItem.agent($0)} | ||
// Workspaces with no agents are shown as offline | ||
items+= workspaces.filter{ _, valuein | ||
value.agents.isEmpty | ||
}.map{VPNMenuItem.offlineWorkspace(Workspace(id: $0.key, name: $0.value.name, agents: $0.value.agents))} | ||
return items.sorted() | ||
} | ||
mutatingfunc clear(){ | ||
agents.removeAll() | ||
workspaces.removeAll() | ||
} | ||
} |
64 changes: 8 additions & 56 deletionsCoder Desktop/Coder Desktop/VPNService.swift
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.