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:
67
Sources/Settings/Settings.swift
Normal file
67
Sources/Settings/Settings.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
// Settings holds the user settings. The settings use UserDefaults. The keys
|
||||
// have the prefix "ws." (spec section 7.13). The type is main-actor isolated
|
||||
// and publishes changes with the Observation framework.
|
||||
@MainActor
|
||||
@Observable
|
||||
final class Settings {
|
||||
|
||||
static let shared = Settings()
|
||||
|
||||
private enum Key {
|
||||
static let paused = "ws.paused"
|
||||
static let constrainWindows = "ws.constrainWindows"
|
||||
static let excludedBundleIDs = "ws.excludedBundleIDs"
|
||||
static let stripHeight = "ws.stripHeight"
|
||||
}
|
||||
|
||||
@ObservationIgnored
|
||||
private let defaults: UserDefaults
|
||||
|
||||
var paused: Bool {
|
||||
didSet { defaults.set(paused, forKey: Key.paused) }
|
||||
}
|
||||
|
||||
var constrainWindows: Bool {
|
||||
didSet { defaults.set(constrainWindows, forKey: Key.constrainWindows) }
|
||||
}
|
||||
|
||||
var excludedBundleIDs: [String] {
|
||||
didSet { defaults.set(excludedBundleIDs, forKey: Key.excludedBundleIDs) }
|
||||
}
|
||||
|
||||
var stripHeight: Double {
|
||||
didSet { defaults.set(stripHeight, forKey: Key.stripHeight) }
|
||||
}
|
||||
|
||||
init(defaults: UserDefaults = .standard) {
|
||||
self.defaults = defaults
|
||||
defaults.register(defaults: [
|
||||
Key.paused: false,
|
||||
Key.constrainWindows: true,
|
||||
Key.excludedBundleIDs: [String](),
|
||||
Key.stripHeight: 30.0
|
||||
])
|
||||
paused = defaults.bool(forKey: Key.paused)
|
||||
constrainWindows = defaults.bool(forKey: Key.constrainWindows)
|
||||
excludedBundleIDs = defaults.stringArray(forKey: Key.excludedBundleIDs) ?? []
|
||||
stripHeight = defaults.double(forKey: Key.stripHeight)
|
||||
}
|
||||
|
||||
// isExcluded returns true if the application is on the excluded list.
|
||||
func isExcluded(_ bundleID: String?) -> Bool {
|
||||
guard let bundleID = bundleID else { return false }
|
||||
return excludedBundleIDs.contains(bundleID)
|
||||
}
|
||||
|
||||
func addExcluded(_ bundleID: String) {
|
||||
guard excludedBundleIDs.contains(bundleID) == false else { return }
|
||||
excludedBundleIDs.append(bundleID)
|
||||
}
|
||||
|
||||
func removeExcluded(_ bundleID: String) {
|
||||
excludedBundleIDs.removeAll { $0 == bundleID }
|
||||
}
|
||||
}
|
||||
134
Sources/Settings/SettingsWindow.swift
Normal file
134
Sources/Settings/SettingsWindow.swift
Normal file
@@ -0,0 +1,134 @@
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
// SettingsWindow shows the settings of EPOD Window Bar. In v1 the window shows
|
||||
// the excluded applications list (spec section 7.13). The user adds an
|
||||
// application from the running applications. The user removes an application
|
||||
// from the list. EPOD Window Bar does not resize the windows of an excluded
|
||||
// application.
|
||||
@MainActor
|
||||
final class SettingsWindow: NSObject, NSWindowDelegate {
|
||||
|
||||
private let settings: Settings
|
||||
private var window: NSWindow?
|
||||
|
||||
init(settings: Settings) {
|
||||
self.settings = settings
|
||||
super.init()
|
||||
}
|
||||
|
||||
func show() {
|
||||
if window == nil {
|
||||
build()
|
||||
}
|
||||
window?.center()
|
||||
window?.makeKeyAndOrderFront(nil)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
|
||||
private func build() {
|
||||
let root = ExcludedAppsView(settings: settings)
|
||||
let hosting = NSHostingView(rootView: root)
|
||||
|
||||
let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 440, height: 380),
|
||||
styleMask: [.titled, .closable],
|
||||
backing: .buffered,
|
||||
defer: false)
|
||||
window.title = "EPOD Window Bar — Settings"
|
||||
window.isReleasedWhenClosed = false
|
||||
window.contentView = hosting
|
||||
window.delegate = self
|
||||
self.window = window
|
||||
}
|
||||
|
||||
// windowShouldClose hides the window. The window stays in memory.
|
||||
func windowShouldClose(_ sender: NSWindow) -> Bool {
|
||||
window?.orderOut(nil)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// AppEntry is one running application in the Add menu.
|
||||
private struct AppEntry: Identifiable {
|
||||
let name: String
|
||||
let bundleID: String
|
||||
var id: String { bundleID }
|
||||
}
|
||||
|
||||
// ExcludedAppsView is the SwiftUI content of the settings window.
|
||||
private struct ExcludedAppsView: View {
|
||||
|
||||
@Bindable var settings: Settings
|
||||
@State private var selection: String?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
Text("Excluded applications")
|
||||
.font(.headline)
|
||||
Text("EPOD Window Bar does not resize the windows of an excluded application.")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
List(selection: $selection) {
|
||||
ForEach(settings.excludedBundleIDs, id: \.self) { bundleID in
|
||||
Text(displayName(for: bundleID))
|
||||
.tag(bundleID)
|
||||
}
|
||||
}
|
||||
.frame(minHeight: 220)
|
||||
|
||||
HStack {
|
||||
Menu("Add") {
|
||||
let apps = runningApps()
|
||||
if apps.isEmpty {
|
||||
Text("No application is available.")
|
||||
} else {
|
||||
ForEach(apps) { app in
|
||||
Button(app.name) {
|
||||
settings.addExcluded(app.bundleID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: 90)
|
||||
|
||||
Button("Remove") {
|
||||
if let selection = selection {
|
||||
settings.removeExcluded(selection)
|
||||
self.selection = nil
|
||||
}
|
||||
}
|
||||
.disabled(selection == nil)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
// runningApps returns the regular running applications that are not on the
|
||||
// excluded list. The function sorts the applications by name.
|
||||
private func runningApps() -> [AppEntry] {
|
||||
var seen = Set<String>()
|
||||
var result: [AppEntry] = []
|
||||
for app in NSWorkspace.shared.runningApplications {
|
||||
guard app.activationPolicy == .regular else { continue }
|
||||
guard let bundleID = app.bundleIdentifier else { continue }
|
||||
guard settings.excludedBundleIDs.contains(bundleID) == false else { continue }
|
||||
guard seen.contains(bundleID) == false else { continue }
|
||||
seen.insert(bundleID)
|
||||
result.append(AppEntry(name: app.localizedName ?? bundleID, bundleID: bundleID))
|
||||
}
|
||||
return result.sorted { $0.name.lowercased() < $1.name.lowercased() }
|
||||
}
|
||||
|
||||
// displayName returns the application name for a bundle ID. The function
|
||||
// falls back to the bundle ID if no running application has this ID.
|
||||
private func displayName(for bundleID: String) -> String {
|
||||
for app in NSWorkspace.shared.runningApplications
|
||||
where app.bundleIdentifier == bundleID {
|
||||
return app.localizedName ?? bundleID
|
||||
}
|
||||
return bundleID
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user