mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Changes applied: Still fucked but working
This commit is contained in:
parent
4136f6d9b9
commit
310dde6573
8 changed files with 18739 additions and 1538 deletions
|
|
@ -355,7 +355,7 @@
|
|||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = DynamicIsland/DynamicIsland.entitlements;
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
|
|
@ -397,7 +397,7 @@
|
|||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = DynamicIsland/DynamicIsland.entitlements;
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
1615
DynamicIsland/Localizable.xcstrings.backup
Normal file
1615
DynamicIsland/Localizable.xcstrings.backup
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -71,35 +71,28 @@ class SettingsWindowController: NSWindowController {
|
|||
}
|
||||
|
||||
func showWindow() {
|
||||
// Set app to regular mode first
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
// Ensure window exists
|
||||
_ = window
|
||||
|
||||
// If window is already visible, bring it to front properly
|
||||
if window?.isVisible == true {
|
||||
forceWindowToFront()
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
window?.orderFrontRegardless()
|
||||
window?.makeKeyAndOrderFront(nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Show the window with proper ordering
|
||||
window?.center()
|
||||
forceWindowToFront()
|
||||
}
|
||||
|
||||
private func forceWindowToFront() {
|
||||
// Multi-step approach to ensure window gets focus
|
||||
window?.orderFrontRegardless()
|
||||
window?.makeKeyAndOrderFront(nil)
|
||||
window?.center()
|
||||
|
||||
// Activate the app with maximum priority
|
||||
// Activate the app and ensure window gets focus
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
|
||||
// Double-check after a brief delay
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
|
||||
guard let window = self?.window else { return }
|
||||
if !window.isKeyWindow {
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
// Force window to front after activation
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.window?.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,97 +5,107 @@
|
|||
// Created by Richard Kunkli on 21/08/2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
|
||||
enum PanDirection {
|
||||
case left, right, up, down
|
||||
|
||||
var isHorizontal: Bool { self == .left || self == .right }
|
||||
var sign: CGFloat { (self == .right || self == .down) ? 1 : -1 }
|
||||
|
||||
func signed(from translation: CGSize) -> CGFloat { (isHorizontal ? translation.width : translation.height) * sign }
|
||||
func signed(deltaX: CGFloat, deltaY: CGFloat) -> CGFloat { (isHorizontal ? deltaX : deltaY) * sign }
|
||||
}
|
||||
|
||||
extension View {
|
||||
func panGesture(direction: PanDirection, action: @escaping (CGFloat, NSEvent.Phase) -> Void) -> some View {
|
||||
background(
|
||||
PanGestureView(direction: direction, action: action)
|
||||
.frame(maxWidth: 0, maxHeight: 0)
|
||||
func panGesture(direction: PanDirection, threshold: CGFloat = 4, action: @escaping (CGFloat, NSEvent.Phase) -> Void) -> some View {
|
||||
self
|
||||
.gesture(
|
||||
DragGesture(minimumDistance: 0)
|
||||
.onChanged { value in
|
||||
let s = direction.signed(from: value.translation)
|
||||
guard s > 0, s.magnitude >= threshold else { return }
|
||||
action(s.magnitude, .changed)
|
||||
}
|
||||
.onEnded { _ in action(0, .ended) }
|
||||
)
|
||||
.background(ScrollMonitor(direction: direction, threshold: threshold, action: action))
|
||||
}
|
||||
}
|
||||
|
||||
struct PanGestureView: NSViewRepresentable {
|
||||
private struct ScrollMonitor: NSViewRepresentable {
|
||||
let direction: PanDirection
|
||||
let threshold: CGFloat
|
||||
let action: (CGFloat, NSEvent.Phase) -> Void
|
||||
|
||||
func makeNSView(context: Context) -> NSView {
|
||||
let view = NSView()
|
||||
NSEvent.addLocalMonitorForEvents(matching: [.scrollWheel]) { event in
|
||||
if event.window == view.window {
|
||||
context.coordinator.handleEvent(event)
|
||||
}
|
||||
return event
|
||||
}
|
||||
context.coordinator.installMonitor(on: view)
|
||||
return view
|
||||
}
|
||||
|
||||
func updateNSView(_ nsView: NSView, context: Context) {
|
||||
|
||||
}
|
||||
func updateNSView(_ nsView: NSView, context: Context) {}
|
||||
static func dismantleNSView(_ nsView: NSView, coordinator: Coordinator) { coordinator.removeMonitor() }
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(direction: direction, action: action)
|
||||
Coordinator(direction: direction, threshold: threshold, action: action)
|
||||
}
|
||||
|
||||
class Coordinator: NSObject {
|
||||
let direction: PanDirection
|
||||
let action: (CGFloat, NSEvent.Phase) -> Void
|
||||
@MainActor final class Coordinator: NSObject {
|
||||
private let direction: PanDirection
|
||||
private let threshold: CGFloat
|
||||
private let action: (CGFloat, NSEvent.Phase) -> Void
|
||||
private var monitor: Any?
|
||||
private var accumulated: CGFloat = 0
|
||||
private var active = false
|
||||
private let noiseThreshold: CGFloat = 0.2
|
||||
|
||||
var accumulatedScrollDeltaX: CGFloat = 0
|
||||
var accumulatedScrollDeltaY: CGFloat = 0
|
||||
|
||||
init(direction: PanDirection, action: @escaping (CGFloat, NSEvent.Phase) -> Void) {
|
||||
init(direction: PanDirection, threshold: CGFloat, action: @escaping (CGFloat, NSEvent.Phase) -> Void) {
|
||||
self.direction = direction
|
||||
self.threshold = threshold
|
||||
self.action = action
|
||||
}
|
||||
|
||||
@objc func handleEvent(_ event: NSEvent) {
|
||||
if event.type == .scrollWheel {
|
||||
accumulatedScrollDeltaX += event.scrollingDeltaX
|
||||
accumulatedScrollDeltaY += event.scrollingDeltaY
|
||||
|
||||
switch direction {
|
||||
case .down:
|
||||
if accumulatedScrollDeltaY > 0 {
|
||||
handle()
|
||||
}
|
||||
case .up:
|
||||
if accumulatedScrollDeltaY < 0 {
|
||||
handle()
|
||||
}
|
||||
case .left:
|
||||
if accumulatedScrollDeltaX < 0 {
|
||||
handle()
|
||||
}
|
||||
case .right:
|
||||
if accumulatedScrollDeltaX > 0 {
|
||||
handle()
|
||||
func installMonitor(on view: NSView) {
|
||||
removeMonitor()
|
||||
monitor = NSEvent.addLocalMonitorForEvents(matching: [.scrollWheel]) { [weak self, weak view] event in
|
||||
guard let self = self, event.window === view?.window else { return event }
|
||||
self.handleScroll(event)
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
func handle() {
|
||||
if (direction == .left || direction == .right) {
|
||||
action(abs(accumulatedScrollDeltaX), event.phase)
|
||||
func removeMonitor() {
|
||||
if let monitor = monitor {
|
||||
NSEvent.removeMonitor(monitor)
|
||||
self.monitor = nil
|
||||
}
|
||||
accumulated = 0
|
||||
active = false
|
||||
}
|
||||
|
||||
private func handleScroll(_ event: NSEvent) {
|
||||
if event.phase == .ended || event.momentumPhase == .ended {
|
||||
if active {
|
||||
action(accumulated.magnitude, .ended)
|
||||
} else {
|
||||
action(abs(accumulatedScrollDeltaY), event.phase)
|
||||
action(0, .ended)
|
||||
}
|
||||
active = false
|
||||
accumulated = 0
|
||||
return
|
||||
}
|
||||
|
||||
if event.phase == .ended {
|
||||
accumulatedScrollDeltaY = 0
|
||||
accumulatedScrollDeltaX = 0
|
||||
}
|
||||
let s = direction.signed(deltaX: event.scrollingDeltaX, deltaY: event.scrollingDeltaY)
|
||||
guard s.magnitude > noiseThreshold else { return }
|
||||
accumulated = s > 0 ? accumulated + s : 0
|
||||
|
||||
if !active && accumulated >= threshold {
|
||||
active = true
|
||||
action(accumulated.magnitude, .began)
|
||||
} else if active {
|
||||
action(accumulated.magnitude, .changed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum PanDirection {
|
||||
case left
|
||||
case right
|
||||
case up
|
||||
case down
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import Cocoa
|
||||
|
||||
class DynamicIslandStatusMenu: NSMenu {
|
||||
class StatusBarMenu: NSMenu {
|
||||
|
||||
var statusItem: NSStatusItem!
|
||||
|
||||
|
|
@ -11,7 +11,6 @@ class DynamicIslandStatusMenu: NSMenu {
|
|||
|
||||
convenience init() {
|
||||
self.init(title: "DynamicIsland")
|
||||
setupStatusItem()
|
||||
}
|
||||
|
||||
required init(coder: NSCoder) {
|
||||
|
|
@ -23,22 +22,14 @@ class DynamicIslandStatusMenu: NSMenu {
|
|||
// Initialize the status item
|
||||
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
||||
|
||||
// Set the menu bar icon
|
||||
if let button = statusItem.button {
|
||||
button.image = NSImage(systemSymbolName: "music.note", accessibilityDescription: "DynamicIsland")
|
||||
button.action = #selector(showMenu)
|
||||
button.image = NSImage(named: "logo")
|
||||
}
|
||||
|
||||
// Set up the menu
|
||||
self.addItem(NSMenuItem(title: "Quit", action: #selector(quitAction), keyEquivalent: "q"))
|
||||
self.addItem(NSMenuItem(title: "Quit", action: #selector(NSApp.terminate(_:)), keyEquivalent: "q"))
|
||||
statusItem.menu = self
|
||||
}
|
||||
|
||||
@objc func showMenu() {
|
||||
// Handle menu show action
|
||||
}
|
||||
|
||||
@objc func quitAction() {
|
||||
NSApp.terminate(nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,3 +27,18 @@ struct PlaybackState {
|
|||
var lastUpdated: Date = Date.distantPast
|
||||
var artwork: Data?
|
||||
}
|
||||
|
||||
extension PlaybackState: Equatable {
|
||||
static func == (lhs: PlaybackState, rhs: PlaybackState) -> Bool {
|
||||
return lhs.bundleIdentifier == rhs.bundleIdentifier
|
||||
&& lhs.isPlaying == rhs.isPlaying
|
||||
&& lhs.title == rhs.title
|
||||
&& lhs.artist == rhs.artist
|
||||
&& lhs.album == rhs.album
|
||||
&& lhs.currentTime == rhs.currentTime
|
||||
&& lhs.duration == rhs.duration
|
||||
&& lhs.isShuffled == rhs.isShuffled
|
||||
&& lhs.repeatMode == rhs.repeatMode
|
||||
&& lhs.artwork == rhs.artwork
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,12 @@ import Defaults
|
|||
import MacroVisionKit
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
class FullscreenMediaDetector: ObservableObject {
|
||||
static let shared = FullscreenMediaDetector()
|
||||
private let detector: MacroVisionKit
|
||||
@ObservedObject private var musicManager = MusicManager.shared
|
||||
|
||||
@Published private(set) var fullscreenStatus: [String: Bool] = [:]
|
||||
@MainActor @Published private(set) var fullscreenStatus: [String: Bool] = [:]
|
||||
private var notificationTask: Task<Void, Never>?
|
||||
|
||||
private init() {
|
||||
self.detector = MacroVisionKit.shared
|
||||
|
|
@ -25,18 +24,35 @@ class FullscreenMediaDetector: ObservableObject {
|
|||
}
|
||||
|
||||
private func setupNotificationObservers() {
|
||||
let nc = NSWorkspace.shared.notificationCenter
|
||||
nc.addObserver(self, selector: #selector(handleChange),
|
||||
name: NSWorkspace.activeSpaceDidChangeNotification, object: nil)
|
||||
nc.addObserver(self, selector: #selector(handleChange),
|
||||
name: NSApplication.didChangeScreenParametersNotification, object: nil)
|
||||
notificationTask = Task { @Sendable [weak self] in
|
||||
await withTaskGroup(of: Void.self) { group in
|
||||
group.addTask {
|
||||
let activeSpaceNotifications = NSWorkspace.shared.notificationCenter.notifications(
|
||||
named: NSWorkspace.activeSpaceDidChangeNotification
|
||||
)
|
||||
|
||||
for await _ in activeSpaceNotifications {
|
||||
await self?.handleChange()
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func handleChange() {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
self.updateFullScreenStatus()
|
||||
group.addTask {
|
||||
let screenParameterNotifications = NSWorkspace.shared.notificationCenter.notifications(
|
||||
named: NSApplication.didChangeScreenParametersNotification
|
||||
)
|
||||
|
||||
for await _ in screenParameterNotifications {
|
||||
await self?.handleChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleChange() async {
|
||||
try? await Task.sleep(for: .milliseconds(500))
|
||||
self.updateFullScreenStatus()
|
||||
}
|
||||
|
||||
private func updateFullScreenStatus() {
|
||||
guard Defaults[.enableFullscreenMediaDetection] else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue