Capture is now a decision, not a hidden setting. The popover shows a four-way scope control with the target named under it (800 x 600 on Display 1, the frontmost window, the front browser window, the whole display), and the window header carries the same choice beside the verbs. Picking Window or Browser hides Redline, dims the screen, names the app under the pointer and highlights its window; a click captures exactly that window, Escape cancels, and the desktop highlights the whole screen. New Session is one click: the current captures stay in their own folder, a fresh session opens, and the area picker comes straight up with the saved area pre-selected — Return keeps it, a drag replaces it. Settings is consolidated into one door (the popover gear, plus Cmd-,): what to capture, saved area, shortcut, ask-on-new-session, sending, session age limit, and a new Updates group with automatic install (on by default; installs only when nothing is unsent). The footer filler and the extra-actions menu are gone.
279 lines
9.5 KiB
Swift
279 lines
9.5 KiB
Swift
import AppKit
|
|
import SwiftUI
|
|
import ShotdeckCore
|
|
|
|
/// The menu-bar popover: decide what to capture, see the pages, then capture or send.
|
|
/// History, editable details and file facts live in the Redline window; Settings has
|
|
/// exactly one door — the gear here (⌘, works anywhere).
|
|
struct MenuBarView: View {
|
|
@Environment(AppModel.self) private var model
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
if model.screenRecordingGranted {
|
|
header
|
|
scopeControl
|
|
pageStrip
|
|
newsRow
|
|
verbs
|
|
} else {
|
|
permissionBlock
|
|
}
|
|
}
|
|
.padding(10)
|
|
.frame(width: 340, alignment: .leading)
|
|
.controlSize(.small)
|
|
}
|
|
|
|
// MARK: - Header
|
|
|
|
private var header: some View {
|
|
HStack(alignment: .top, spacing: 8) {
|
|
VStack(alignment: .leading, spacing: 1) {
|
|
HStack(spacing: 5) {
|
|
Text(laneTitle)
|
|
.font(.system(size: 13, weight: .semibold))
|
|
.lineLimit(1)
|
|
if let version = versionTitle {
|
|
Text(version)
|
|
.font(.system(size: 13))
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(1)
|
|
}
|
|
}
|
|
Text(detailLine)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
}
|
|
Spacer(minLength: 4)
|
|
Button {
|
|
presentWindow(focusLane: true)
|
|
} label: {
|
|
Image(systemName: "square.and.pencil")
|
|
.font(.system(size: 12, weight: .semibold))
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.help("Edit review details")
|
|
.accessibilityLabel("Edit review details")
|
|
|
|
Button {
|
|
(model as? SettingsWindowPresenting)?.presentSettingsWindow()
|
|
} label: {
|
|
Image(systemName: "gearshape")
|
|
.font(.system(size: 12, weight: .semibold))
|
|
}
|
|
.buttonStyle(.borderless)
|
|
.keyboardShortcut(",", modifiers: .command)
|
|
.help("Settings (⌘,)")
|
|
.accessibilityLabel("Settings")
|
|
}
|
|
}
|
|
|
|
private var laneTitle: String {
|
|
let lane = model.session.context.lane
|
|
return lane.isEmpty ? "No lane" : lane
|
|
}
|
|
|
|
private var versionTitle: String? {
|
|
let version = model.session.context.deployedVersion
|
|
return version.isEmpty ? nil : version
|
|
}
|
|
|
|
private var detailLine: String {
|
|
let context = model.session.context
|
|
var parts: [String] = []
|
|
if !context.commit.isEmpty { parts.append(context.commit) }
|
|
if !context.reviewer.isEmpty { parts.append(context.reviewer) }
|
|
let pages = model.session.captures.count
|
|
parts.append(pages == 0 ? "no pages" : "\(pages) page\(pages == 1 ? "" : "s")")
|
|
return parts.joined(separator: " · ")
|
|
}
|
|
|
|
// MARK: - What to capture
|
|
|
|
private var scopeControl: some View {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Picker("Capture", selection: scopeBinding) {
|
|
ForEach(CaptureScope.allCases, id: \.self) { scope in
|
|
Text(scope.displayName).tag(scope)
|
|
}
|
|
}
|
|
.pickerStyle(.segmented)
|
|
.labelsHidden()
|
|
.accessibilityLabel("Capture")
|
|
|
|
HStack(spacing: 6) {
|
|
Text(model.captureTargetDescription)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
Spacer(minLength: 4)
|
|
if model.captureScope == .area {
|
|
Button("Choose Area…") {
|
|
Task { await model.rePickRegion() }
|
|
}
|
|
.buttonStyle(.link)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private var scopeBinding: Binding<CaptureScope> {
|
|
Binding(
|
|
get: { model.captureScope },
|
|
set: { scope in Task { await model.chooseCaptureScope(scope) } }
|
|
)
|
|
}
|
|
|
|
// MARK: - Pages
|
|
|
|
@ViewBuilder
|
|
private var pageStrip: some View {
|
|
if model.session.isEmpty {
|
|
VStack(spacing: 2) {
|
|
Text("No pages yet")
|
|
.font(.callout)
|
|
.foregroundStyle(.secondary)
|
|
Text(emptyHint)
|
|
.font(.caption)
|
|
.foregroundStyle(.tertiary)
|
|
}
|
|
.frame(maxWidth: .infinity, minHeight: 62)
|
|
.background(.quaternary.opacity(0.4), in: RoundedRectangle(cornerRadius: 6, style: .continuous))
|
|
} else {
|
|
SessionStrip(limit: 3)
|
|
}
|
|
}
|
|
|
|
private var emptyHint: String {
|
|
"\(model.hotkeyDisplayString) captures the \(model.captureScope.displayName.lowercased())"
|
|
}
|
|
|
|
// MARK: - News
|
|
|
|
@ViewBuilder
|
|
private var newsRow: some View {
|
|
if let update = model.updateAvailable {
|
|
HStack(spacing: 6) {
|
|
Circle().fill(.green).frame(width: 6, height: 6)
|
|
Text(model.autoInstallUpdates
|
|
? "Redline \(update.version) is ready — restarts when nothing is unsent"
|
|
: "Redline \(update.version) is ready")
|
|
.font(.caption)
|
|
.lineLimit(2)
|
|
Spacer(minLength: 4)
|
|
Button("Restart Now") { model.installUpdate() }
|
|
.buttonStyle(.link)
|
|
}
|
|
} else if let status = model.statusLine, !status.isEmpty {
|
|
Text(status)
|
|
.font(.caption)
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(2)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
}
|
|
|
|
// MARK: - Verbs
|
|
|
|
private var verbs: some View {
|
|
VStack(spacing: 6) {
|
|
HStack(spacing: 6) {
|
|
Button {
|
|
Task { await model.captureNow() }
|
|
} label: {
|
|
HStack(spacing: 4) {
|
|
Image(systemName: "viewfinder")
|
|
Text(model.isCapturing ? "Capturing…" : "Capture")
|
|
Text(model.hotkeyDisplayString)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.controlSize(.regular)
|
|
.disabled(model.isCapturing)
|
|
|
|
Button {
|
|
guard let sender = model as? SendCapable else { return }
|
|
let anchor = NSApp.keyWindow?.contentView
|
|
Task { await sender.send(anchor: anchor) }
|
|
} label: {
|
|
HStack(spacing: 4) {
|
|
Image(systemName: "paperplane.fill")
|
|
Text(sendTitle)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.controlSize(.regular)
|
|
.disabled(model.session.isEmpty || model.isSending)
|
|
}
|
|
|
|
HStack(spacing: 6) {
|
|
Button {
|
|
Task { await model.newSession() }
|
|
} label: {
|
|
HStack(spacing: 4) {
|
|
Image(systemName: "plus.square.on.square")
|
|
Text("New Session")
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.controlSize(.regular)
|
|
.disabled(model.isSending)
|
|
.help("Keeps this session and starts a fresh one, then asks where to capture.")
|
|
|
|
Button {
|
|
presentWindow(focusLane: false)
|
|
} label: {
|
|
HStack(spacing: 4) {
|
|
Image(systemName: "macwindow")
|
|
Text("Open Redline")
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.bordered)
|
|
.controlSize(.regular)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var sendTitle: String {
|
|
let count = model.session.captures.count
|
|
guard count > 0 else { return "Send…" }
|
|
let pages = "\(count) page\(count == 1 ? "" : "s")"
|
|
return model.transport == .oneDrive ? "Save \(pages)…" : "Send \(pages)…"
|
|
}
|
|
|
|
// MARK: - Permission
|
|
|
|
private var permissionBlock: some View {
|
|
HStack(alignment: .top, spacing: 6) {
|
|
Image(systemName: "exclamationmark.triangle")
|
|
.foregroundStyle(.yellow)
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
Text(
|
|
ShotdeckError.screenRecordingNotGranted.errorDescription
|
|
?? "Screen Recording is turned off."
|
|
)
|
|
.font(.caption)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
Button("Open Screen Recording settings") {
|
|
model.openScreenRecordingSettings()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func presentWindow(focusLane: Bool) {
|
|
guard let presenter = model as? SessionsWindowPresenting else {
|
|
model.setStatus("The Redline window is not available in this build.")
|
|
return
|
|
}
|
|
presenter.presentSessionsWindow(focusLane: focusLane)
|
|
}
|
|
}
|