Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Fader/FaderApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct FaderApp: App {
.environment(engine)
.environment(updater)
} label: {
Image(nsImage: Self.menuBarIcon)
MenuBarLabel(engine: engine, appIcon: Self.menuBarIcon)
}
.menuBarExtraStyle(.window)
}
Expand Down
29 changes: 29 additions & 0 deletions Fader/UI/MenuBarLabel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import SwiftUI

/// The menu bar icon: Fader's mark by default; with the opt-in from the
/// status item menu, the glyph of the device playing right now — the same
/// symbol its row shows in the popover.
struct MenuBarLabel: View {
static let showsOutputIconKey = "menuBarShowsOutputIcon"

let engine: MixerEngine
let appIcon: NSImage
@AppStorage(Self.showsOutputIconKey) private var showsOutputIcon = false

var body: some View {
if showsOutputIcon, let symbol = outputSymbol {
Image(systemName: symbol)
} else {
Image(nsImage: appIcon)
}
}

/// Nil until the engine has a default it can name (startup, a default the
/// list hides) — the app mark is the honest fallback there.
private var outputSymbol: String? {
if engine.multiOutput.isActive { return "hifispeaker.2" }
let monitor = engine.deviceMonitor
guard let device = monitor.devices.first(where: { $0.id == monitor.defaultDeviceID }) else { return nil }
return device.symbolName(direction: .output, bluetoothPeer: engine.bluetoothPeer(for: device))
}
}
14 changes: 14 additions & 0 deletions Fader/UI/StatusItemMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ final class StatusItemMenuController: NSObject {
login.state = SMAppService.mainApp.status == .enabled ? .on : .off
menu.addItem(login)

let outputIcon = NSMenuItem(
title: "Show Output Device in Menu Bar",
action: #selector(toggleOutputIcon),
keyEquivalent: ""
)
outputIcon.target = self
outputIcon.state = UserDefaults.standard.bool(forKey: MenuBarLabel.showsOutputIconKey) ? .on : .off
menu.addItem(outputIcon)

menu.addItem(.separator())

let checkTitle = updater.stagedVersion.map { "Restart to Update to \($0)" }
Expand Down Expand Up @@ -96,6 +105,11 @@ final class StatusItemMenuController: NSObject {
}
}

@objc private func toggleOutputIcon() {
let defaults = UserDefaults.standard
defaults.set(!defaults.bool(forKey: MenuBarLabel.showsOutputIconKey), forKey: MenuBarLabel.showsOutputIconKey)
}

@objc private func checkForUpdates() {
updater.checkForUpdates()
}
Expand Down
Loading