61 lines
2.1 KiB
Swift
61 lines
2.1 KiB
Swift
|
|
import AppKit
|
||
|
|
import NotifierCore
|
||
|
|
import SwiftUI
|
||
|
|
|
||
|
|
struct MenuContent: View {
|
||
|
|
@ObservedObject var state: AppState
|
||
|
|
|
||
|
|
var body: some View {
|
||
|
|
VStack(alignment: .leading, spacing: 8) {
|
||
|
|
if let warning = state.permission.warning {
|
||
|
|
Label(warning, systemImage: "exclamationmark.triangle.fill")
|
||
|
|
.font(.caption)
|
||
|
|
.foregroundStyle(.orange)
|
||
|
|
}
|
||
|
|
if state.history.isEmpty {
|
||
|
|
Text("Nothing waiting on you").foregroundStyle(.secondary)
|
||
|
|
} else {
|
||
|
|
ForEach(Array(state.history.prefix(10).enumerated()), id: \.offset) { _, event in
|
||
|
|
Button { TerminalFocuser.focus(bundleID: event.terminalBundleID) } label: {
|
||
|
|
EventRow(event: event).frame(maxWidth: .infinity, alignment: .leading)
|
||
|
|
}
|
||
|
|
.buttonStyle(.plain)
|
||
|
|
.help(event.terminalBundleID == nil ? "No terminal recorded for this event" : "Bring the terminal forward")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
Divider()
|
||
|
|
Toggle("Mute banners", isOn: $state.isMuted)
|
||
|
|
Toggle("Launch at login", isOn: $state.launchAtLogin)
|
||
|
|
.disabled(!LoginItem.isAvailable)
|
||
|
|
HStack {
|
||
|
|
Button("Clear") { state.clear() }.disabled(state.history.isEmpty)
|
||
|
|
Spacer()
|
||
|
|
Button("Quit") { NSApplication.shared.terminate(nil) }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
.padding(12)
|
||
|
|
.frame(width: 320)
|
||
|
|
.onAppear {
|
||
|
|
state.markSeen()
|
||
|
|
state.refreshPermission()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
struct EventRow: View {
|
||
|
|
let event: NotifyEvent
|
||
|
|
|
||
|
|
var body: some View {
|
||
|
|
VStack(alignment: .leading, spacing: 2) {
|
||
|
|
Text(event.title).font(.headline)
|
||
|
|
Text(event.message).font(.subheadline)
|
||
|
|
Text(detail).font(.caption).foregroundStyle(.secondary)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private var detail: String {
|
||
|
|
let folder = event.cwd.map { URL(fileURLWithPath: $0).lastPathComponent } ?? "unknown folder"
|
||
|
|
return "\(folder) · \(event.timestamp.formatted(date: .omitted, time: .shortened))"
|
||
|
|
}
|
||
|
|
}
|