fix(mac): restore session usage bar

This commit is contained in:
Peter Steinberger
2025-12-22 20:14:54 +01:00
parent 3412ff7003
commit f24d8473b1
3 changed files with 6 additions and 43 deletions

View File

@@ -210,24 +210,10 @@ struct MenuContent: View {
} label: {
MenuHostedItem(
width: self.sessionMenuItemWidth,
rootView: AnyView(SessionMenuLabelView(row: row)))
rootView: AnyView(SessionMenuLabelView(row: row, width: self.sessionMenuItemWidth)))
}
}
}
Button {
Task { @MainActor in
guard let key = SessionActions.promptForSessionKey() else { return }
do {
try await SessionActions.createSession(key: key)
await self.reloadSessionMenu()
} catch {
SessionActions.presentError(title: "Create session failed", error: error)
}
}
} label: {
Label("New Session…", systemImage: "plus.circle")
}
}
}

View File

@@ -34,12 +34,6 @@ enum SessionActions {
_ = try await ControlChannel.shared.request(method: "sessions.patch", params: params)
}
static func createSession(key: String) async throws {
_ = try await ControlChannel.shared.request(
method: "sessions.patch",
params: ["key": AnyHashable(key)])
}
static func resetSession(key: String) async throws {
_ = try await ControlChannel.shared.request(
method: "sessions.reset",
@@ -69,23 +63,6 @@ enum SessionActions {
return alert.runModal() == .alertFirstButtonReturn
}
@MainActor
static func promptForSessionKey() -> String? {
let alert = NSAlert()
alert.messageText = "New Session"
alert.informativeText = "Create a new session key (e.g. \"main\", \"group:dev\", \"scratch\")."
let field = NSTextField(frame: NSRect(x: 0, y: 0, width: 280, height: 24))
field.placeholderString = "session key"
alert.accessoryView = field
alert.addButton(withTitle: "Create")
alert.addButton(withTitle: "Cancel")
alert.alertStyle = .informational
let result = alert.runModal()
guard result == .alertFirstButtonReturn else { return nil }
let trimmed = field.stringValue.trimmingCharacters(in: .whitespacesAndNewlines)
return trimmed.isEmpty ? nil : trimmed
}
@MainActor
static func presentError(title: String, error: Error) {
let alert = NSAlert()
@@ -130,4 +107,3 @@ enum SessionActions {
NSWorkspace.shared.activateFileViewerSelecting([url])
}
}

View File

@@ -2,14 +2,16 @@ import SwiftUI
struct SessionMenuLabelView: View {
let row: SessionRow
let width: CGFloat
private let horizontalPadding: CGFloat = 8
var body: some View {
VStack(alignment: .leading, spacing: 5) {
ContextUsageBar(
usedTokens: row.tokens.total,
contextTokens: row.tokens.contextTokens,
width: nil,
height: 3)
width: max(1, self.width - (self.horizontalPadding * 2)),
height: 4)
HStack(alignment: .firstTextBaseline, spacing: 8) {
Text(row.key)
@@ -29,7 +31,6 @@ struct SessionMenuLabelView: View {
}
}
.padding(.vertical, 4)
.padding(.horizontal, 6)
.padding(.horizontal, self.horizontalPadding)
}
}