Skip to content
Open
2 changes: 2 additions & 0 deletions Barik/Barik.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<true/>
<key>com.apple.security.personal-information.location</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
69 changes: 69 additions & 0 deletions Barik/Helpers/SystemUIHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import AppKit
import Foundation

/// Helper for triggering macOS system UI elements
final class SystemUIHelper {

/// Opens the macOS Notification Center
static func openNotificationCenter() {
// Check for Accessibility permission first
let trusted = AXIsProcessTrustedWithOptions(
[kAXTrustedCheckOptionPrompt.takeUnretainedValue(): true] as CFDictionary
)

guard trusted else {
// System will show the prompt automatically
return
}

let script = """
tell application "System Events"
tell process "ControlCenter"
click menu bar item "Clock" of menu bar 1
end tell
end tell
"""
runAppleScript(script)
}

/// Opens the macOS Weather menu bar dropdown
static func openWeatherDropdown() {
let script = """
tell application "System Events"
tell process "ControlCenter"
try
click menu bar item "Weather" of menu bar 1
on error
-- Weather might not be in menu bar, try to open Weather app instead
tell application "Weather" to activate
end try
end tell
end tell
"""
runAppleScript(script)
}

/// Opens the Weather app
static func openWeatherApp() {
NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.Weather")!)
// Fallback to opening Weather app directly
if let weatherURL = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.apple.weather") {
NSWorkspace.shared.open(weatherURL)
}
}

/// Runs an AppleScript
@discardableResult
private static func runAppleScript(_ script: String) -> String? {
guard let appleScript = NSAppleScript(source: script) else {
return nil
}
var error: NSDictionary?
let result = appleScript.executeAndReturnError(&error)
if let error = error {
print("AppleScript Error: \(error)")
return nil
}
return result.stringValue
}
}
7 changes: 6 additions & 1 deletion Barik/Info.plist
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>NSLocationUsageDescription</key>
<string>Barik needs your location to show local weather conditions.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Barik needs your location to show local weather conditions.</string>
</dict>
</plist>
4 changes: 4 additions & 0 deletions Barik/Views/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ struct MenuBarView: View {
NowPlayingWidget()
.environmentObject(config)

case "default.weather":
WeatherWidget()
.environmentObject(config)

case "spacer":
Spacer().frame(minWidth: 50, maxWidth: .infinity)

Expand Down
Loading