mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-28 15:44:32 +00:00
Somewhat working file tray
This commit is contained in:
parent
4c7e79b954
commit
30422c3d95
29 changed files with 4032 additions and 65 deletions
|
|
@ -501,6 +501,9 @@ extension Defaults.Keys {
|
|||
// MARK: Shelf
|
||||
static let dynamicShelf = Key<Bool>("dynamicShelf", default: true)
|
||||
static let openShelfByDefault = Key<Bool>("openShelfByDefault", default: true)
|
||||
static let quickShareProvider = Key<String>("quickShareProvider", default: "AirDrop")
|
||||
static let copyOnDrag = Key<Bool>("copyOnDrag", default: false)
|
||||
static let autoRemoveShelfItems = Key<Bool>("autoRemoveShelfItems", default: false)
|
||||
|
||||
// MARK: Calendar
|
||||
static let calendarSelectionState = Key<CalendarSelectionState>("calendarSelectionState", default: .all)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import Combine
|
|||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
class DynamicIslandViewModel: NSObject, ObservableObject {
|
||||
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
|
||||
@ObservedObject var detector = FullscreenMediaDetector.shared
|
||||
|
|
@ -45,6 +46,7 @@ class DynamicIslandViewModel: NSObject, ObservableObject {
|
|||
@Published var notchSize: CGSize = getClosedNotchSize()
|
||||
@Published var closedNotchSize: CGSize = getClosedNotchSize()
|
||||
|
||||
@MainActor
|
||||
deinit {
|
||||
destroy()
|
||||
}
|
||||
|
|
@ -282,7 +284,7 @@ class DynamicIslandViewModel: NSObject, ObservableObject {
|
|||
|
||||
// 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] {
|
||||
if !ShelfStateViewModel.shared.isEmpty && Defaults[.openShelfByDefault] {
|
||||
coordinator.currentView = .shelf
|
||||
} else if !coordinator.openLastTabByDefault {
|
||||
coordinator.currentView = .home
|
||||
|
|
|
|||
157
DynamicIsland/models/SharingStateManager.swift
Normal file
157
DynamicIsland/models/SharingStateManager.swift
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
//
|
||||
// SharingStateManager.swift
|
||||
// boringNotch
|
||||
//
|
||||
// Created by Alexander on 2025-10-10.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
extension Notification.Name {
|
||||
static let sharingDidFinish = Notification.Name("com.ebullioscopic.sharingDidFinish")
|
||||
}
|
||||
|
||||
@MainActor
|
||||
final class SharingStateManager: ObservableObject {
|
||||
static let shared = SharingStateManager()
|
||||
|
||||
private var activeSessions: Int = 0 {
|
||||
didSet {
|
||||
let newValue = activeSessions > 0
|
||||
if newValue != preventNotchClose {
|
||||
preventNotchClose = newValue
|
||||
if !newValue {
|
||||
NotificationCenter.default.post(name: .sharingDidFinish, object: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Published var preventNotchClose: Bool = false
|
||||
|
||||
private var activeDelegates: [UUID: SharingLifecycleDelegate] = [:]
|
||||
|
||||
private init() {}
|
||||
|
||||
func requestCloseIfReady() {
|
||||
if !preventNotchClose {
|
||||
NotificationCenter.default.post(name: .sharingDidFinish, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
func beginInteraction() {
|
||||
activeSessions += 1
|
||||
}
|
||||
|
||||
func endInteraction() {
|
||||
if activeSessions > 0 { activeSessions -= 1 }
|
||||
}
|
||||
|
||||
func makeDelegate(onEnd: (() -> Void)? = nil) -> SharingLifecycleDelegate {
|
||||
let id = UUID()
|
||||
let delegate = SharingLifecycleDelegate(id: id, onEnd: { [weak self] in
|
||||
onEnd?()
|
||||
self?.unregisterDelegate(id: id)
|
||||
}, onBegin: { [weak self] in
|
||||
self?.beginInteraction()
|
||||
}, onFinish: { [weak self] in
|
||||
self?.endInteraction()
|
||||
})
|
||||
activeDelegates[id] = delegate
|
||||
return delegate
|
||||
}
|
||||
|
||||
private func unregisterDelegate(id: UUID) {
|
||||
activeDelegates.removeValue(forKey: id)
|
||||
}
|
||||
}
|
||||
|
||||
final class SharingLifecycleDelegate: NSObject, NSSharingServiceDelegate, NSSharingServicePickerDelegate {
|
||||
let id: UUID
|
||||
private let onEnd: () -> Void
|
||||
private let onBegin: () -> Void
|
||||
private let onFinish: () -> Void
|
||||
|
||||
private var pickerActive = false
|
||||
private var serviceInProgress = false
|
||||
private var finished = false
|
||||
private var timeoutTask: Task<Void, Never>?
|
||||
|
||||
init(id: UUID, onEnd: @escaping () -> Void, onBegin: @escaping () -> Void, onFinish: @escaping () -> Void) {
|
||||
self.id = id
|
||||
self.onEnd = onEnd
|
||||
self.onBegin = onBegin
|
||||
self.onFinish = onFinish
|
||||
}
|
||||
|
||||
deinit {
|
||||
timeoutTask?.cancel()
|
||||
}
|
||||
|
||||
func markPickerBegan() {
|
||||
guard !pickerActive else { return }
|
||||
pickerActive = true
|
||||
onBegin()
|
||||
}
|
||||
|
||||
func markServiceBegan() {
|
||||
guard !serviceInProgress else { return }
|
||||
serviceInProgress = true
|
||||
onBegin()
|
||||
startTimeoutFallback()
|
||||
}
|
||||
|
||||
private func startTimeoutFallback() {
|
||||
timeoutTask?.cancel()
|
||||
timeoutTask = Task { @MainActor [weak self] in
|
||||
try? await Task.sleep(for: .seconds(2))
|
||||
guard let self = self, !Task.isCancelled else { return }
|
||||
if !self.finished {
|
||||
self.finishIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func finishIfNeeded() {
|
||||
guard !finished else { return }
|
||||
finished = true
|
||||
timeoutTask?.cancel()
|
||||
onFinish()
|
||||
onEnd()
|
||||
}
|
||||
|
||||
// MARK: - NSSharingServicePickerDelegate
|
||||
|
||||
func sharingServicePicker(_ sharingServicePicker: NSSharingServicePicker, didChoose service: NSSharingService?) {
|
||||
if service == nil {
|
||||
if pickerActive && !serviceInProgress {
|
||||
finishIfNeeded()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
service?.delegate = self
|
||||
serviceInProgress = true
|
||||
startTimeoutFallback()
|
||||
}
|
||||
|
||||
// MARK: - NSSharingServiceDelegate
|
||||
|
||||
func sharingService(_ sharingService: NSSharingService, willShareItems items: [Any]) {
|
||||
if !pickerActive && !serviceInProgress {
|
||||
onBegin()
|
||||
}
|
||||
serviceInProgress = true
|
||||
}
|
||||
|
||||
func sharingService(_ sharingService: NSSharingService, didShareItems items: [Any]) {
|
||||
finishIfNeeded()
|
||||
}
|
||||
|
||||
func sharingService(_ sharingService: NSSharingService, didFailToShareItems items: [Any], error: Error) {
|
||||
finishIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue