From 6e258fdffa5c8b906b1cc171f753449a75854a8b Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Sun, 12 Jul 2026 11:39:58 +0200 Subject: [PATCH] cleanup code --- Sources/phbar/AppDelegate.swift | 17 ++++++++++++++--- Sources/phbar/Views/BarController.swift | 10 ++-------- Sources/phbar/Views/TextBlockView.swift | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Sources/phbar/AppDelegate.swift b/Sources/phbar/AppDelegate.swift index 5efd007..366d933 100644 --- a/Sources/phbar/AppDelegate.swift +++ b/Sources/phbar/AppDelegate.swift @@ -6,11 +6,22 @@ final class AppDelegate: NSObject, NSApplicationDelegate { var window: BarWindow! private var observers: [IPCObserver] = [] - init(config: PHConfig, screen: NSScreen, theme: PHTheme, blocks: [PHBlock], debug: Bool = false) { + init( + config: PHConfig, + screen: NSScreen, + theme: PHTheme, + blocks: [PHBlock], + debug: Bool + ) { super.init() - self.barController = BarController(config: config, screen: screen, theme: theme, blocks: blocks) - barController.debug = debug + self.barController = BarController( + config: config, + screen: screen, + theme: theme, + blocks: blocks, + debug: debug + ) } func applicationDidFinishLaunching(_ notification: Notification) { diff --git a/Sources/phbar/Views/BarController.swift b/Sources/phbar/Views/BarController.swift index 962db06..5e1acc7 100644 --- a/Sources/phbar/Views/BarController.swift +++ b/Sources/phbar/Views/BarController.swift @@ -5,13 +5,6 @@ final class BarController: ObservableObject { let config: PHConfig let screen: NSScreen let theme: PHTheme - var debug: Bool = false { - didSet { - for block in blocks { - block.debug = debug - } - } - } @Published var blocks: [PHBlock] var arrangedBlocks: [PHBlock] { @@ -22,7 +15,7 @@ final class BarController: ObservableObject { blocks.filter { $0.centered == true } } - init(config: PHConfig, screen: NSScreen, theme: PHTheme, blocks: [PHBlock]) { + init(config: PHConfig, screen: NSScreen, theme: PHTheme, blocks: [PHBlock], debug: Bool) { self.config = config self.screen = screen self.theme = theme @@ -31,6 +24,7 @@ final class BarController: ObservableObject { for block in blocks { block.text = text(for: block) block.style = style(for: block) + block.debug = debug } } } diff --git a/Sources/phbar/Views/TextBlockView.swift b/Sources/phbar/Views/TextBlockView.swift index 945695d..733388f 100644 --- a/Sources/phbar/Views/TextBlockView.swift +++ b/Sources/phbar/Views/TextBlockView.swift @@ -23,13 +23,13 @@ struct TextBlockView: View { .italic(block.text.italic) .foregroundStyle(block.style.foreground?.uiColor ?? .clear) .transformEffect(adjustOffset) - .border(bar.debug ? .blue : .clear) + .border(block.debug ? .blue : .clear) } .padding(.trailing, block.style.padding?.trailing ?? 0) .padding(.leading, block.style.padding?.leading ?? 0) } .fixedSize(horizontal: true, vertical: false) - .border(bar.debug ? .red : .clear) + .border(block.debug ? .red : .clear) .onHover { hovering = $0 } .onAppear { NSEvent.addLocalMonitorForEvents(matching: [