mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Applied latest changes from boring.notch
This commit is contained in:
parent
bad481588b
commit
628d76b41c
18 changed files with 940 additions and 339 deletions
125
DynamicIsland/components/Settings/SettingsWindowController.swift
Normal file
125
DynamicIsland/components/Settings/SettingsWindowController.swift
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
//
|
||||
// SettingsWindowController.swift
|
||||
// DynamicIsland
|
||||
//
|
||||
// Created by Alexander on 2025-06-14.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
import Defaults
|
||||
import Sparkle
|
||||
|
||||
class SettingsWindowController: NSWindowController {
|
||||
static let shared = SettingsWindowController()
|
||||
private var updaterController: SPUStandardUpdaterController?
|
||||
|
||||
private init() {
|
||||
let window = NSWindow(
|
||||
contentRect: NSRect(x: 0, y: 0, width: 700, height: 600),
|
||||
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
|
||||
backing: .buffered,
|
||||
defer: false
|
||||
)
|
||||
|
||||
super.init(window: window)
|
||||
|
||||
setupWindow()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func setUpdaterController(_ controller: SPUStandardUpdaterController) {
|
||||
self.updaterController = controller
|
||||
// Recreate the content view with the proper updater controller
|
||||
setupWindow()
|
||||
}
|
||||
|
||||
private func setupWindow() {
|
||||
guard let window = window else { return }
|
||||
|
||||
window.title = "Dynamic Island Settings"
|
||||
window.titlebarAppearsTransparent = false
|
||||
window.titleVisibility = .visible
|
||||
window.toolbarStyle = .unified
|
||||
window.isMovableByWindowBackground = true
|
||||
|
||||
// Make it behave like a regular app window with proper Spaces support
|
||||
window.collectionBehavior = [.managed, .participatesInCycle, .fullScreenAuxiliary]
|
||||
|
||||
// Ensure proper window behavior
|
||||
window.hidesOnDeactivate = false
|
||||
window.isExcludedFromWindowsMenu = false
|
||||
|
||||
// Configure window to be a standard document-style window
|
||||
window.isRestorable = true
|
||||
window.identifier = NSUserInterfaceItemIdentifier("DynamicIslandSettingsWindow")
|
||||
|
||||
// Create the SwiftUI content
|
||||
let settingsView = SettingsView(updaterController: updaterController)
|
||||
let hostingView = NSHostingView(rootView: settingsView)
|
||||
window.contentView = hostingView
|
||||
|
||||
// Handle window closing
|
||||
window.delegate = self
|
||||
}
|
||||
|
||||
func showWindow() {
|
||||
// Set app to regular mode first
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
|
||||
// If window is already visible, bring it to front properly
|
||||
if window?.isVisible == true {
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
window?.orderFrontRegardless()
|
||||
window?.makeKeyAndOrderFront(nil)
|
||||
return
|
||||
}
|
||||
|
||||
// Show the window with proper ordering
|
||||
window?.orderFrontRegardless()
|
||||
window?.makeKeyAndOrderFront(nil)
|
||||
window?.center()
|
||||
|
||||
// Activate the app and ensure window gets focus
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
|
||||
// Force window to front after activation
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.window?.makeKeyAndOrderFront(nil)
|
||||
}
|
||||
}
|
||||
|
||||
override func close() {
|
||||
super.close()
|
||||
relinquishFocus()
|
||||
}
|
||||
|
||||
private func relinquishFocus() {
|
||||
window?.orderOut(nil)
|
||||
|
||||
// Set app back to accessory mode immediately
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
}
|
||||
}
|
||||
|
||||
extension SettingsWindowController: NSWindowDelegate {
|
||||
func windowWillClose(_ notification: Notification) {
|
||||
relinquishFocus()
|
||||
}
|
||||
|
||||
func windowShouldClose(_ sender: NSWindow) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func windowDidBecomeKey(_ notification: Notification) {
|
||||
// Ensure app is in regular mode when window becomes key
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
}
|
||||
|
||||
func windowDidResignKey(_ notification: Notification) {
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue