mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-28 23:54:32 +00:00
Restored files from old Mac, force pushing
This commit is contained in:
parent
5dd95228b8
commit
5040381840
126 changed files with 10431 additions and 67 deletions
147
DynamicIsland/models/BatteryStatusViewModel.swift
Normal file
147
DynamicIsland/models/BatteryStatusViewModel.swift
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
import Foundation
|
||||
import Cocoa
|
||||
import SwiftUI
|
||||
import IOKit.ps
|
||||
import Defaults
|
||||
|
||||
/// A view model that manages and monitors the battery status of the device
|
||||
class BatteryStatusViewModel: ObservableObject {
|
||||
|
||||
private var wasCharging: Bool = false
|
||||
private var powerSourceChangedCallback: IOPowerSourceCallbackType?
|
||||
private var runLoopSource: Unmanaged<CFRunLoopSource>?
|
||||
var animations: DynamicIslandAnimations = DynamicIslandAnimations()
|
||||
|
||||
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
|
||||
|
||||
@Published private(set) var levelBattery: Float = 0.0
|
||||
@Published private(set) var maxCapacity: Float = 0.0
|
||||
@Published private(set) var isPluggedIn: Bool = false
|
||||
@Published private(set) var isCharging: Bool = false
|
||||
@Published private(set) var isInLowPowerMode: Bool = false
|
||||
@Published private(set) var isInitial: Bool = false
|
||||
@Published private(set) var timeToFullCharge: Int = 0
|
||||
@Published private(set) var statusText: String = ""
|
||||
|
||||
private let managerBattery = BatteryActivityManager.shared
|
||||
private var managerBatteryId: Int?
|
||||
|
||||
static let shared = BatteryStatusViewModel()
|
||||
|
||||
/// Initializes the view model with a given DynamicIslandViewModel instance
|
||||
/// - Parameter vm: The DynamicIslandViewModel instance
|
||||
private init() {
|
||||
setupPowerStatus()
|
||||
setupMonitor()
|
||||
}
|
||||
|
||||
/// Sets up the initial power status by fetching battery information
|
||||
private func setupPowerStatus() {
|
||||
let batteryInfo = managerBattery.initializeBatteryInfo()
|
||||
updateBatteryInfo(batteryInfo)
|
||||
}
|
||||
|
||||
/// Sets up the monitor to observe battery events
|
||||
private func setupMonitor() {
|
||||
managerBatteryId = managerBattery.addObserver { [weak self] event in
|
||||
guard let self = self else { return }
|
||||
self.handleBatteryEvent(event)
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles battery events and updates the corresponding properties
|
||||
/// - Parameter event: The battery event to handle
|
||||
private func handleBatteryEvent(_ event: BatteryActivityManager.BatteryEvent) {
|
||||
switch event {
|
||||
case .powerSourceChanged(let isPluggedIn):
|
||||
print("🔌 Power source: \(isPluggedIn ? "Connected" : "Disconnected")")
|
||||
withAnimation {
|
||||
self.isPluggedIn = isPluggedIn
|
||||
self.statusText = isPluggedIn ? "Plugged In" : "Unplugged"
|
||||
self.notifyImportanChangeStatus()
|
||||
}
|
||||
|
||||
case .batteryLevelChanged(let level):
|
||||
print("🔋 Battery level: \(Int(level))%")
|
||||
withAnimation {
|
||||
self.levelBattery = level
|
||||
}
|
||||
|
||||
case .lowPowerModeChanged(let isEnabled):
|
||||
print("⚡ Low power mode: \(isEnabled ? "Enabled" : "Disabled")")
|
||||
self.notifyImportanChangeStatus()
|
||||
withAnimation {
|
||||
self.isInLowPowerMode = isEnabled
|
||||
self.statusText = "Low Power: \(self.isInLowPowerMode ? "On" : "Off")"
|
||||
}
|
||||
|
||||
case .isChargingChanged(let isCharging):
|
||||
print("🔌 Charging: \(isCharging ? "Yes" : "No")")
|
||||
print("maxCapacity: \(self.maxCapacity)")
|
||||
print("levelBattery: \(self.levelBattery)")
|
||||
self.notifyImportanChangeStatus()
|
||||
withAnimation {
|
||||
self.isCharging = isCharging
|
||||
self.statusText = isCharging ? "Charging battery" : (self.levelBattery < self.maxCapacity ? "Not charging" : "Full charge")
|
||||
}
|
||||
|
||||
case .timeToFullChargeChanged(let time):
|
||||
print("🕒 Time to full charge: \(time) minutes")
|
||||
withAnimation {
|
||||
self.timeToFullCharge = time
|
||||
}
|
||||
|
||||
case .maxCapacityChanged(let capacity):
|
||||
print("🔋 Max capacity: \(capacity)")
|
||||
withAnimation {
|
||||
self.maxCapacity = capacity
|
||||
}
|
||||
|
||||
case .error(let description):
|
||||
print("⚠️ Error: \(description)")
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the battery information with the given BatteryInfo instance
|
||||
/// - Parameter batteryInfo: The BatteryInfo instance containing the battery data
|
||||
private func updateBatteryInfo(_ batteryInfo: BatteryInfo) {
|
||||
withAnimation {
|
||||
self.levelBattery = batteryInfo.currentCapacity
|
||||
self.isPluggedIn = batteryInfo.isPluggedIn
|
||||
self.isCharging = batteryInfo.isCharging
|
||||
self.isInLowPowerMode = batteryInfo.isInLowPowerMode
|
||||
self.timeToFullCharge = batteryInfo.timeToFullCharge
|
||||
self.maxCapacity = batteryInfo.maxCapacity
|
||||
self.statusText = batteryInfo.isPluggedIn ? "Plugged In" : "Unplugged"
|
||||
}
|
||||
notifyImportanChangeStatus(delay: coordinator.firstLaunch ? 6 : 0.0)
|
||||
withAnimation {
|
||||
if self.isCharging {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
self.statusText = "Charging: Yes"
|
||||
}
|
||||
}
|
||||
if self.isInLowPowerMode {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
self.statusText = "Low Power: On"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Notifies important changes in the battery status with an optional delay
|
||||
/// - Parameter delay: The delay before notifying the change, default is 0.0
|
||||
private func notifyImportanChangeStatus(delay: Double = 0.0) {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
|
||||
self.coordinator.toggleExpandingView(status: true, type: .battery)
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
print("🔌 Cleaning up battery monitoring...")
|
||||
if let managerBatteryId: Int = managerBatteryId {
|
||||
managerBattery.removeObserver(byId: managerBatteryId)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
165
DynamicIsland/models/Constants.swift
Normal file
165
DynamicIsland/models/Constants.swift
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
//
|
||||
// Constants.swift
|
||||
// boringNotch
|
||||
//
|
||||
// Created by Richard Kunkli on 2024. 10. 17..
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Defaults
|
||||
|
||||
private let availableDirectories = FileManager
|
||||
.default
|
||||
.urls(for: .documentDirectory, in: .userDomainMask)
|
||||
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
let bundleIdentifier = Bundle.main.bundleIdentifier!
|
||||
let appVersion = "\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "") (\(Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""))"
|
||||
|
||||
let temporaryDirectory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
|
||||
let spacing: CGFloat = 16
|
||||
|
||||
struct CustomVisualizer: Codable, Hashable, Equatable, Defaults.Serializable {
|
||||
let UUID: UUID
|
||||
var name: String
|
||||
var url: URL
|
||||
var speed: CGFloat = 1.0
|
||||
}
|
||||
|
||||
enum CalendarSelectionState: Codable, Defaults.Serializable {
|
||||
case all
|
||||
case selected(Set<String>)
|
||||
}
|
||||
|
||||
enum HideNotchOption: String, Defaults.Serializable {
|
||||
case always
|
||||
case nowPlayingOnly
|
||||
case never
|
||||
}
|
||||
|
||||
// Define notification names at file scope
|
||||
extension Notification.Name {
|
||||
static let mediaControllerChanged = Notification.Name("mediaControllerChanged")
|
||||
}
|
||||
|
||||
// Media controller types for selection in settings
|
||||
enum MediaControllerType: String, CaseIterable, Identifiable, Defaults.Serializable {
|
||||
case nowPlaying = "Now Playing"
|
||||
case appleMusic = "Apple Music"
|
||||
case spotify = "Spotify"
|
||||
case youtubeMusic = "Youtube Music"
|
||||
|
||||
var id: String { self.rawValue }
|
||||
}
|
||||
|
||||
// Sneak peek styles for selection in settings
|
||||
enum SneakPeekStyle: String, CaseIterable, Identifiable, Defaults.Serializable {
|
||||
case standard = "Default"
|
||||
case inline = "Inline"
|
||||
|
||||
var id: String { self.rawValue }
|
||||
}
|
||||
|
||||
extension Defaults.Keys {
|
||||
// MARK: General
|
||||
static let menubarIcon = Key<Bool>("menubarIcon", default: true)
|
||||
static let showOnAllDisplays = Key<Bool>("showOnAllDisplays", default: false)
|
||||
static let automaticallySwitchDisplay = Key<Bool>("automaticallySwitchDisplay", default: true)
|
||||
static let releaseName = Key<String>("releaseName", default: "Wolf Painting 🐺🎨")
|
||||
|
||||
// MARK: Behavior
|
||||
static let minimumHoverDuration = Key<TimeInterval>("minimumHoverDuration", default: 0.3)
|
||||
static let enableHaptics = Key<Bool>("enableHaptics", default: true)
|
||||
static let openNotchOnHover = Key<Bool>("openNotchOnHover", default: true)
|
||||
static let extendHoverArea = Key<Bool>("extendHoverArea", default: false)
|
||||
static let notchHeightMode = Key<WindowHeightMode>(
|
||||
"notchHeightMode",
|
||||
default: WindowHeightMode.matchRealNotchSize
|
||||
)
|
||||
static let nonNotchHeightMode = Key<WindowHeightMode>(
|
||||
"nonNotchHeightMode",
|
||||
default: WindowHeightMode.matchMenuBar
|
||||
)
|
||||
static let nonNotchHeight = Key<CGFloat>("nonNotchHeight", default: 32)
|
||||
static let notchHeight = Key<CGFloat>("notchHeight", default: 32)
|
||||
//static let openLastTabByDefault = Key<Bool>("openLastTabByDefault", default: false)
|
||||
|
||||
// MARK: Appearance
|
||||
static let showEmojis = Key<Bool>("showEmojis", default: false)
|
||||
//static let alwaysShowTabs = Key<Bool>("alwaysShowTabs", default: true)
|
||||
static let showMirror = Key<Bool>("showMirror", default: false)
|
||||
static let mirrorShape = Key<MirrorShapeEnum>("mirrorShape", default: MirrorShapeEnum.rectangle)
|
||||
static let settingsIconInNotch = Key<Bool>("settingsIconInNotch", default: true)
|
||||
static let lightingEffect = Key<Bool>("lightingEffect", default: true)
|
||||
static let accentColor = Key<Color>("accentColor", default: Color.blue)
|
||||
static let enableShadow = Key<Bool>("enableShadow", default: true)
|
||||
static let cornerRadiusScaling = Key<Bool>("cornerRadiusScaling", default: true)
|
||||
static let useModernCloseAnimation = Key<Bool>("useModernCloseAnimation", default: true)
|
||||
static let showNotHumanFace = Key<Bool>("showNotHumanFace", default: false)
|
||||
static let tileShowLabels = Key<Bool>("tileShowLabels", default: false)
|
||||
static let showCalendar = Key<Bool>("showCalendar", default: false)
|
||||
static let sliderColor = Key<SliderColorEnum>(
|
||||
"sliderUseAlbumArtColor",
|
||||
default: SliderColorEnum.white
|
||||
)
|
||||
static let playerColorTinting = Key<Bool>("playerColorTinting", default: true)
|
||||
static let useMusicVisualizer = Key<Bool>("useMusicVisualizer", default: true)
|
||||
static let customVisualizers = Key<[CustomVisualizer]>("customVisualizers", default: [])
|
||||
static let selectedVisualizer = Key<CustomVisualizer?>("selectedVisualizer", default: nil)
|
||||
|
||||
// MARK: Gestures
|
||||
static let enableGestures = Key<Bool>("enableGestures", default: true)
|
||||
static let closeGestureEnabled = Key<Bool>("closeGestureEnabled", default: true)
|
||||
static let gestureSensitivity = Key<CGFloat>("gestureSensitivity", default: 200.0)
|
||||
|
||||
// MARK: Media playback
|
||||
static let coloredSpectrogram = Key<Bool>("coloredSpectrogram", default: true)
|
||||
static let enableSneakPeek = Key<Bool>("enableSneakPeek", default: false)
|
||||
static let sneakPeekStyles = Key<SneakPeekStyle>("sneakPeekStyles", default: .standard)
|
||||
static let enableFullscreenMediaDetection = Key<Bool>("enableFullscreenMediaDetection", default: true)
|
||||
static let waitInterval = Key<Double>("waitInterval", default: 3)
|
||||
|
||||
// MARK: Battery
|
||||
static let showPowerStatusNotifications = Key<Bool>("showPowerStatusNotifications", default: true)
|
||||
static let showBatteryIndicator = Key<Bool>("showBatteryIndicator", default: true)
|
||||
static let showBatteryPercentage = Key<Bool>("showBatteryPercentage", default: true)
|
||||
static let showPowerStatusIcons = Key<Bool>("showPowerStatusIcons", default: true)
|
||||
|
||||
// MARK: Downloads
|
||||
static let enableDownloadListener = Key<Bool>("enableDownloadListener", default: true)
|
||||
static let enableSafariDownloads = Key<Bool>("enableSafariDownloads", default: true)
|
||||
static let selectedDownloadIndicatorStyle = Key<DownloadIndicatorStyle>("selectedDownloadIndicatorStyle", default: DownloadIndicatorStyle.progress)
|
||||
static let selectedDownloadIconStyle = Key<DownloadIconStyle>("selectedDownloadIconStyle", default: DownloadIconStyle.onlyAppIcon)
|
||||
|
||||
// MARK: HUD
|
||||
static let inlineHUD = Key<Bool>("inlineHUD", default: false)
|
||||
static let enableGradient = Key<Bool>("enableGradient", default: false)
|
||||
static let systemEventIndicatorShadow = Key<Bool>("systemEventIndicatorShadow", default: false)
|
||||
static let systemEventIndicatorUseAccent = Key<Bool>("systemEventIndicatorUseAccent", default: false)
|
||||
|
||||
// MARK: Shelf
|
||||
static let dynamicShelf = Key<Bool>("dynamicShelf", default: true)
|
||||
static let openShelfByDefault = Key<Bool>("openShelfByDefault", default: true)
|
||||
|
||||
// MARK: Calendar
|
||||
static let calendarSelectionState = Key<CalendarSelectionState>("calendarSelectionState", default: .all)
|
||||
|
||||
// MARK: Fullscreen Media Detection
|
||||
static let alwaysHideInFullscreen = Key<Bool>("alwaysHideInFullscreen", default: false)
|
||||
|
||||
static let hideNotchOption = Key<HideNotchOption>("hideNotchOption", default: .nowPlayingOnly)
|
||||
|
||||
// MARK: Wobble Animation
|
||||
static let enableWobbleAnimation = Key<Bool>("enableWobbleAnimation", default: false)
|
||||
|
||||
// MARK: Media Controller
|
||||
static let mediaController = Key<MediaControllerType>("mediaController", default: defaultMediaController)
|
||||
|
||||
// Helper to determine the default media controller based on macOS version
|
||||
static var defaultMediaController: MediaControllerType {
|
||||
if #available(macOS 15.4, *) {
|
||||
return .appleMusic
|
||||
} else {
|
||||
return .nowPlaying
|
||||
}
|
||||
}
|
||||
}
|
||||
151
DynamicIsland/models/DynamicIslandViewModel.swift
Normal file
151
DynamicIsland/models/DynamicIslandViewModel.swift
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
//
|
||||
// DynamicIslandViewModel.swift
|
||||
// DynamicIsland
|
||||
//
|
||||
// Created by Harsh Vardhan Goswami on 04/08/24.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
import TheBoringWorkerNotifier
|
||||
|
||||
class DynamicIslandViewModel: NSObject, ObservableObject {
|
||||
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
|
||||
@ObservedObject var detector = FullscreenMediaDetector.shared
|
||||
|
||||
let animationLibrary: DynamicIslandAnimations = .init()
|
||||
let animation: Animation?
|
||||
|
||||
@Published var contentType: ContentType = .normal
|
||||
@Published private(set) var notchState: NotchState = .closed
|
||||
|
||||
@Published var dragDetectorTargeting: Bool = false
|
||||
@Published var dropZoneTargeting: Bool = false
|
||||
@Published var dropEvent: Bool = false
|
||||
@Published var anyDropZoneTargeting: Bool = false
|
||||
var cancellables: Set<AnyCancellable> = []
|
||||
|
||||
@Published var hideOnClosed: Bool = true
|
||||
@Published var isHoveringCalendar: Bool = false
|
||||
@Published var isBatteryPopoverActive: Bool = false
|
||||
|
||||
@Published var screen: String?
|
||||
|
||||
@Published var notchSize: CGSize = getClosedNotchSize()
|
||||
@Published var closedNotchSize: CGSize = getClosedNotchSize()
|
||||
|
||||
deinit {
|
||||
destroy()
|
||||
}
|
||||
|
||||
func destroy() {
|
||||
cancellables.forEach { $0.cancel() }
|
||||
cancellables.removeAll()
|
||||
}
|
||||
|
||||
init(screen: String? = nil) {
|
||||
animation = animationLibrary.animation
|
||||
|
||||
super.init()
|
||||
|
||||
self.screen = screen
|
||||
notchSize = getClosedNotchSize(screen: screen)
|
||||
closedNotchSize = notchSize
|
||||
|
||||
Publishers.CombineLatest($dropZoneTargeting, $dragDetectorTargeting)
|
||||
.map { value1, value2 in
|
||||
value1 || value2
|
||||
}
|
||||
.assign(to: \.anyDropZoneTargeting, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
setupDetectorObserver()
|
||||
}
|
||||
|
||||
private func setupDetectorObserver() {
|
||||
// 1) Publisher for the user’s fullscreen detection setting
|
||||
let enabledPublisher = Defaults
|
||||
.publisher(.enableFullscreenMediaDetection)
|
||||
.map(\.newValue)
|
||||
|
||||
// 2) For each non‑nil screen name, map to a Bool publisher for that screen's status
|
||||
let statusPublisher = $screen
|
||||
.compactMap { $0 }
|
||||
.removeDuplicates()
|
||||
.map { screenName in
|
||||
self.detector.$fullscreenStatus
|
||||
.map { $0[screenName] ?? false }
|
||||
.removeDuplicates()
|
||||
}
|
||||
.switchToLatest()
|
||||
|
||||
// 3) Combine enabled & status, animate only on changes
|
||||
Publishers.CombineLatest(statusPublisher, enabledPublisher)
|
||||
.map { status, enabled in enabled && status }
|
||||
.removeDuplicates()
|
||||
.receive(on: RunLoop.main)
|
||||
.sink { [weak self] shouldHide in
|
||||
withAnimation(.smooth) {
|
||||
self?.hideOnClosed = shouldHide
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// Computed property for effective notch height
|
||||
var effectiveClosedNotchHeight: CGFloat {
|
||||
let currentScreen = NSScreen.screens.first { $0.localizedName == screen }
|
||||
let noNotchAndFullscreen = hideOnClosed && (currentScreen?.safeAreaInsets.top ?? 0 <= 0 || currentScreen == nil)
|
||||
return noNotchAndFullscreen ? 0 : closedNotchSize.height
|
||||
}
|
||||
|
||||
func isMouseHovering(position: NSPoint = NSEvent.mouseLocation) -> Bool {
|
||||
let screenFrame = getScreenFrame(screen)
|
||||
if let frame = screenFrame {
|
||||
|
||||
let baseY = frame.maxY - notchSize.height
|
||||
let baseX = frame.midX - notchSize.width / 2
|
||||
|
||||
return position.y >= baseY && position.x >= baseX && position.x <= baseX + notchSize.width
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func open() {
|
||||
withAnimation(.bouncy) {
|
||||
self.notchSize = openNotchSize
|
||||
self.notchState = .open
|
||||
}
|
||||
|
||||
// Force music information update when notch is opened
|
||||
MusicManager.shared.forceUpdate()
|
||||
}
|
||||
|
||||
func close() {
|
||||
withAnimation(.smooth) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.notchSize = getClosedNotchSize(screen: self.screen)
|
||||
self.closedNotchSize = self.notchSize
|
||||
self.notchState = .closed
|
||||
}
|
||||
|
||||
// Set the current view to shelf if it contains files and the user enables openShelfByDefault
|
||||
// Otherwise, if the user has not enabled openLastShelfByDefault, set the view to home
|
||||
if !TrayDrop.shared.isEmpty && Defaults[.openShelfByDefault] {
|
||||
coordinator.currentView = .shelf
|
||||
} else if !coordinator.openLastTabByDefault {
|
||||
coordinator.currentView = .home
|
||||
}
|
||||
}
|
||||
|
||||
func closeHello() {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 3.5) { [weak self] in
|
||||
self?.coordinator.firstLaunch = false
|
||||
withAnimation(self?.animationLibrary.animation) {
|
||||
self?.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
DynamicIsland/models/PlaybackState.swift
Normal file
23
DynamicIsland/models/PlaybackState.swift
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// PlaybackState.swift
|
||||
// boringNotch
|
||||
//
|
||||
// Created by Alexander Greco on 2025-03-29.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct PlaybackState {
|
||||
var bundleIdentifier: String
|
||||
var isPlaying: Bool = false
|
||||
var title: String = "I'm Handsome"
|
||||
var artist: String = "Me"
|
||||
var album: String = "Self Love"
|
||||
var currentTime: Double = 0
|
||||
var duration: Double = 0
|
||||
var playbackRate: Double = 1
|
||||
var isShuffled: Bool? = nil
|
||||
var isRepeating: Bool? = nil
|
||||
var lastUpdated: Date = Date.distantPast
|
||||
var artwork: Data?
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue