EPOD Window Bar: a window strip above the macOS Dock
EPOD Window Bar is a macOS agent app. It shows a thin strip above the Dock with one tab per window of the frontmost application. One click raises the window. Build from source with XcodeGen and Xcode. Signing uses Config.xcconfig (ad-hoc by default; a local Local.xcconfig can set a team ID). The app needs Accessibility and Screen Recording permissions, and runs in a reduced mode without Screen Recording. See README.md and docs/ for details.
This commit is contained in:
152
Sources/Permissions/OnboardingWindow.swift
Normal file
152
Sources/Permissions/OnboardingWindow.swift
Normal file
@@ -0,0 +1,152 @@
|
||||
import AppKit
|
||||
|
||||
// OnboardingWindow explains the two permissions. Each row has a button that
|
||||
// opens the correct System Settings pane. The window updates the status of
|
||||
// each permission when the state changes. The Continue button is active only
|
||||
// when Accessibility is granted. Screen Recording is optional (reduced mode).
|
||||
@MainActor
|
||||
final class OnboardingWindow: NSObject, NSWindowDelegate {
|
||||
|
||||
private let permissions: PermissionManager
|
||||
var onContinue: (() -> Void)?
|
||||
|
||||
private var window: NSWindow?
|
||||
private var accessibilityStatus: NSTextField?
|
||||
private var screenStatus: NSTextField?
|
||||
private var continueButton: NSButton?
|
||||
|
||||
init(permissions: PermissionManager) {
|
||||
self.permissions = permissions
|
||||
super.init()
|
||||
}
|
||||
|
||||
func show() {
|
||||
if window == nil {
|
||||
build()
|
||||
}
|
||||
window?.center()
|
||||
window?.makeKeyAndOrderFront(nil)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
|
||||
func close() {
|
||||
window?.orderOut(nil)
|
||||
}
|
||||
|
||||
// update sets the status text of each permission.
|
||||
// The function enables the Continue button if Accessibility is granted.
|
||||
func update(state: PermissionState) {
|
||||
accessibilityStatus?.stringValue = state.accessibility ? "Granted" : "Not granted"
|
||||
accessibilityStatus?.textColor = state.accessibility ? .systemGreen : .systemRed
|
||||
|
||||
screenStatus?.stringValue = state.screenRecording ? "Granted" : "Not granted — reduced mode"
|
||||
screenStatus?.textColor = state.screenRecording ? .systemGreen : .systemOrange
|
||||
|
||||
continueButton?.isEnabled = state.accessibility
|
||||
}
|
||||
|
||||
private func build() {
|
||||
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 480, height: 320),
|
||||
styleMask: [.titled, .closable],
|
||||
backing: .buffered,
|
||||
defer: false)
|
||||
window.title = "EPOD Window Bar — Permissions"
|
||||
window.isReleasedWhenClosed = false
|
||||
window.delegate = self
|
||||
|
||||
let title = label(text: "EPOD Window Bar needs two permissions.",
|
||||
font: .boldSystemFont(ofSize: 15))
|
||||
|
||||
let accessibilityRow = permissionRow(
|
||||
name: "Accessibility",
|
||||
detail: "EPOD Window Bar reads, raises, and resizes windows.",
|
||||
buttonTitle: "Open Accessibility Settings",
|
||||
action: #selector(openAccessibility),
|
||||
statusOut: &accessibilityStatus)
|
||||
|
||||
let screenRow = permissionRow(
|
||||
name: "Screen Recording",
|
||||
detail: "EPOD Window Bar reads window titles on other desktops.",
|
||||
buttonTitle: "Open Screen Recording Settings",
|
||||
action: #selector(openScreen),
|
||||
statusOut: &screenStatus)
|
||||
|
||||
let continueButton = NSButton(title: "Continue",
|
||||
target: self,
|
||||
action: #selector(continueTapped))
|
||||
continueButton.bezelStyle = .rounded
|
||||
continueButton.keyEquivalent = "\r"
|
||||
continueButton.isEnabled = false
|
||||
self.continueButton = continueButton
|
||||
|
||||
let stack = NSStackView(views: [title, accessibilityRow, screenRow, continueButton])
|
||||
stack.orientation = .vertical
|
||||
stack.alignment = .leading
|
||||
stack.spacing = 18
|
||||
stack.edgeInsets = NSEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
let content = NSView()
|
||||
content.addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
stack.topAnchor.constraint(equalTo: content.topAnchor),
|
||||
stack.leadingAnchor.constraint(equalTo: content.leadingAnchor),
|
||||
stack.trailingAnchor.constraint(equalTo: content.trailingAnchor),
|
||||
stack.bottomAnchor.constraint(equalTo: content.bottomAnchor)
|
||||
])
|
||||
window.contentView = content
|
||||
|
||||
self.window = window
|
||||
update(state: permissions.current)
|
||||
}
|
||||
|
||||
// permissionRow builds one row: a name, a detail line, a status line, and
|
||||
// a button that opens the correct settings pane.
|
||||
private func permissionRow(name: String,
|
||||
detail: String,
|
||||
buttonTitle: String,
|
||||
action: Selector,
|
||||
statusOut: inout NSTextField?) -> NSView {
|
||||
let nameLabel = label(text: name, font: .boldSystemFont(ofSize: 13))
|
||||
let detailLabel = label(text: detail, font: .systemFont(ofSize: 12))
|
||||
detailLabel.textColor = .secondaryLabelColor
|
||||
|
||||
let status = label(text: "—", font: .systemFont(ofSize: 12))
|
||||
statusOut = status
|
||||
|
||||
let button = NSButton(title: buttonTitle, target: self, action: action)
|
||||
button.bezelStyle = .rounded
|
||||
|
||||
let stack = NSStackView(views: [nameLabel, detailLabel, status, button])
|
||||
stack.orientation = .vertical
|
||||
stack.alignment = .leading
|
||||
stack.spacing = 4
|
||||
return stack
|
||||
}
|
||||
|
||||
private func label(text: String, font: NSFont) -> NSTextField {
|
||||
let field = NSTextField(labelWithString: text)
|
||||
field.font = font
|
||||
return field
|
||||
}
|
||||
|
||||
@objc private func openAccessibility() {
|
||||
permissions.openAccessibilitySettings()
|
||||
}
|
||||
|
||||
@objc private func openScreen() {
|
||||
permissions.requestScreenRecording()
|
||||
permissions.openScreenRecordingSettings()
|
||||
}
|
||||
|
||||
@objc private func continueTapped() {
|
||||
onContinue?()
|
||||
}
|
||||
|
||||
// windowShouldClose hides the window. The window stays in memory.
|
||||
// The app opens the window again if a permission is revoked.
|
||||
func windowShouldClose(_ sender: NSWindow) -> Bool {
|
||||
window?.orderOut(nil)
|
||||
return false
|
||||
}
|
||||
}
|
||||
81
Sources/Permissions/PermissionManager.swift
Normal file
81
Sources/Permissions/PermissionManager.swift
Normal file
@@ -0,0 +1,81 @@
|
||||
import AppKit
|
||||
import ApplicationServices
|
||||
import CoreGraphics
|
||||
|
||||
// PermissionState holds the two permissions that EPOD Window Bar needs.
|
||||
struct PermissionState: Equatable {
|
||||
var accessibility: Bool
|
||||
var screenRecording: Bool
|
||||
|
||||
// allGranted is true if both permissions are present.
|
||||
var allGranted: Bool { accessibility && screenRecording }
|
||||
|
||||
// reducedMode is true if Accessibility is present but Screen Recording
|
||||
// is not. In reduced mode the app shows only windows on the current Space.
|
||||
var reducedMode: Bool { accessibility && !screenRecording }
|
||||
}
|
||||
|
||||
// PermissionManager reads the permission state and polls for changes.
|
||||
// The manager polls every 2 s. The poll catches a grant while the onboarding
|
||||
// window is open. The poll also catches a revoke at runtime.
|
||||
@MainActor
|
||||
final class PermissionManager {
|
||||
|
||||
private(set) var current: PermissionState
|
||||
var onChange: ((PermissionState) -> Void)?
|
||||
|
||||
private var timer: Timer?
|
||||
|
||||
init() {
|
||||
current = PermissionManager.read(prompt: false)
|
||||
}
|
||||
|
||||
func start() {
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { [weak self] _ in
|
||||
MainActor.assumeIsolated {
|
||||
self?.refresh()
|
||||
}
|
||||
}
|
||||
refresh()
|
||||
}
|
||||
|
||||
// refresh reads the state again. The manager calls onChange only if the
|
||||
// state changed.
|
||||
func refresh() {
|
||||
let new = PermissionManager.read(prompt: false)
|
||||
if new != current {
|
||||
current = new
|
||||
Log.app.info("Permission state changed. ax=\(new.accessibility) sr=\(new.screenRecording)")
|
||||
onChange?(new)
|
||||
}
|
||||
}
|
||||
|
||||
// requestScreenRecording asks macOS for Screen Recording.
|
||||
// macOS shows the system prompt one time.
|
||||
func requestScreenRecording() {
|
||||
CGRequestScreenCaptureAccess()
|
||||
}
|
||||
|
||||
func openAccessibilitySettings() {
|
||||
open("x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")
|
||||
}
|
||||
|
||||
func openScreenRecordingSettings() {
|
||||
open("x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture")
|
||||
}
|
||||
|
||||
// read returns the current permission state.
|
||||
// prompt shows the system Accessibility prompt if the value is true.
|
||||
static func read(prompt: Bool) -> PermissionState {
|
||||
let key = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String
|
||||
let options = [key: prompt] as CFDictionary
|
||||
let ax = AXIsProcessTrustedWithOptions(options)
|
||||
let sr = CGPreflightScreenCaptureAccess()
|
||||
return PermissionState(accessibility: ax, screenRecording: sr)
|
||||
}
|
||||
|
||||
private func open(_ value: String) {
|
||||
guard let url = URL(string: value) else { return }
|
||||
NSWorkspace.shared.open(url)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user