-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add workspace apps #136
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc83303
feat: add workspace apps
ethanndickson 56de38d
vscode desktop display name
ethanndickson b161b05
fixup
ethanndickson 0d54e6f
filter out web apps
ethanndickson 31f725e
filter more web apps
ethanndickson 7242106
swift 6.1 is out apparently and xcode just updates to it
ethanndickson 9eb598f
typo
ethanndickson 919160f
make icon size a fixed square
ethanndickson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import CoderSDK | ||
import os | ||
import SwiftUI | ||
|
||
// Each row in the workspaces list is an agent or an offline workspace | ||
|
@@ -26,6 +28,13 @@ enum VPNMenuItem: Equatable, Comparable, Identifiable { | |
} | ||
} | ||
|
||
var workspaceID: UUID { | ||
switch self { | ||
case let .agent(agent): agent.wsID | ||
case let .offlineWorkspace(workspace): workspace.id | ||
} | ||
} | ||
|
||
static func < (lhs: VPNMenuItem, rhs: VPNMenuItem) -> Bool { | ||
switch (lhs, rhs) { | ||
case let (.agent(lhsAgent), .agent(rhsAgent)): | ||
|
@@ -44,11 +53,17 @@ enum VPNMenuItem: Equatable, Comparable, Identifiable { | |
struct MenuItemView: View { | ||
@EnvironmentObject var state: AppState | ||
|
||
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "VPNMenu") | ||
|
||
let item: VPNMenuItem | ||
let baseAccessURL: URL | ||
|
||
@State private var nameIsSelected: Bool = false | ||
@State private var copyIsSelected: Bool = false | ||
|
||
private let defaultVisibleApps = 5 | ||
@State private var apps: [WorkspaceApp] = [] | ||
|
||
private var itemName: AttributedString { | ||
let name = switch item { | ||
case let .agent(agent): agent.primaryHost ?? "\(item.wsName).\(state.hostnameSuffix)" | ||
|
@@ -70,37 +85,90 @@ struct MenuItemView: View { | |
} | ||
|
||
var body: some View { | ||
HStack(spacing: 0) { | ||
Link(destination: wsURL) { | ||
HStack(spacing: Theme.Size.trayPadding) { | ||
StatusDot(color: item.status.color) | ||
Text(itemName).lineLimit(1).truncationMode(.tail) | ||
VStack(spacing: 0) { | ||
HStack(spacing: 0) { | ||
Link(destination: wsURL) { | ||
HStack(spacing: Theme.Size.trayPadding) { | ||
StatusDot(color: item.status.color) | ||
Text(itemName).lineLimit(1).truncationMode(.tail) | ||
Spacer() | ||
}.padding(.horizontal, Theme.Size.trayPadding) | ||
.frame(minHeight: 22) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.foregroundStyle(nameIsSelected ? .white : .primary) | ||
.background(nameIsSelected ? Color.accentColor.opacity(0.8) : .clear) | ||
.clipShape(.rect(cornerRadius: Theme.Size.rectCornerRadius)) | ||
.onHoverWithPointingHand { hovering in | ||
nameIsSelected = hovering | ||
} | ||
Spacer() | ||
}.padding(.horizontal, Theme.Size.trayPadding) | ||
.frame(minHeight: 22) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.foregroundStyle(nameIsSelected ? .white : .primary) | ||
.background(nameIsSelected ? Color.accentColor.opacity(0.8) : .clear) | ||
.clipShape(.rect(cornerRadius: Theme.Size.rectCornerRadius)) | ||
.onHover { hovering in nameIsSelected = hovering } | ||
Spacer() | ||
}.buttonStyle(.plain) | ||
if case let .agent(agent) = item, let copyableDNS = agent.primaryHost { | ||
Button { | ||
NSPasteboard.general.clearContents() | ||
NSPasteboard.general.setString(copyableDNS, forType: .string) | ||
} label: { | ||
Image(systemName: "doc.on.doc") | ||
.symbolVariant(.fill) | ||
.padding(3) | ||
.contentShape(Rectangle()) | ||
}.foregroundStyle(copyIsSelected ? .white : .primary) | ||
.imageScale(.small) | ||
.background(copyIsSelected ? Color.accentColor.opacity(0.8) : .clear) | ||
.clipShape(.rect(cornerRadius: Theme.Size.rectCornerRadius)) | ||
.onHover { hovering in copyIsSelected = hovering } | ||
.buttonStyle(.plain) | ||
.padding(.trailing, Theme.Size.trayMargin) | ||
}.buttonStyle(.plain) | ||
if case let .agent(agent) = item, let copyableDNS = agent.primaryHost { | ||
Button { | ||
NSPasteboard.general.clearContents() | ||
NSPasteboard.general.setString(copyableDNS, forType: .string) | ||
} label: { | ||
Image(systemName: "doc.on.doc") | ||
.symbolVariant(.fill) | ||
.padding(3) | ||
.contentShape(Rectangle()) | ||
}.foregroundStyle(copyIsSelected ? .white : .primary) | ||
.imageScale(.small) | ||
.background(copyIsSelected ? Color.accentColor.opacity(0.8) : .clear) | ||
.clipShape(.rect(cornerRadius: Theme.Size.rectCornerRadius)) | ||
.onHoverWithPointingHand { hovering in copyIsSelected = hovering } | ||
.buttonStyle(.plain) | ||
.padding(.trailing, Theme.Size.trayMargin) | ||
} | ||
} | ||
if !apps.isEmpty { | ||
HStack(spacing: 17) { | ||
ForEach(apps.prefix(defaultVisibleApps), id: \.id) { app in | ||
WorkspaceAppIcon(app: app) | ||
ethanndickson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.frame(width: Theme.Size.appIconWidth, height: Theme.Size.appIconHeight) | ||
} | ||
if apps.count < defaultVisibleApps { | ||
Spacer() | ||
} | ||
} | ||
.padding(.leading, apps.count < defaultVisibleApps ? 14 : 0) | ||
.padding(.bottom, 5) | ||
.padding(.top, 10) | ||
} | ||
} | ||
.task { await loadApps() } | ||
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.
|
||
} | ||
|
||
func loadApps() async { | ||
// If this menu item is an agent, and the user is logged in | ||
if case let .agent(agent) = item, | ||
let client = state.client, | ||
let host = agent.primaryHost, | ||
let baseAccessURL = state.baseAccessURL, | ||
// Like the CLI, we'll re-use the existing session token to populate the URL | ||
let sessionToken = state.sessionToken | ||
{ | ||
let workspace: CoderSDK.Workspace | ||
do { | ||
workspace = try await retry(floor: .milliseconds(100), ceil: .seconds(10)) { | ||
do { | ||
return try await client.workspace(item.workspaceID) | ||
} catch { | ||
logger.error("Failed to load apps for workspace \(item.wsName): \(error.localizedDescription)") | ||
throw error | ||
} | ||
} | ||
} catch { return } // Task cancelled | ||
|
||
if let wsAgent = workspace | ||
.latest_build.resources | ||
.compactMap(\.agents) | ||
.flatMap(\.self) | ||
.first(where: { $0.id == agent.id }) | ||
{ | ||
apps = agentToApps(logger, wsAgent, host, baseAccessURL, sessionToken) | ||
} else { | ||
logger.error("Could not find agent '\(agent.id)' in workspace '\(item.wsName)' resources") | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
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.
SwiftUI has a great
AsyncImage
View, but it doesn't support svgs. FWICT there's not even a public macOS API for rendering them.I also found this https://gist.github.com/erezhod/6e8e6af3c940d88a706a9d936c8838e6, but it doesn't have a license attached, and I didn't feel like reaching out to the two separate authors to ask.