general: cleanup
This commit is contained in:
@@ -16,6 +16,7 @@ final class MenuBarGuideOverlayPresenter {
|
||||
private var window: NSWindow?
|
||||
private var displayLink: CVDisplayLink?
|
||||
private var lastWindowFrame: CGRect = .zero
|
||||
private var onboardingWindowObserver: NSObjectProtocol?
|
||||
|
||||
func updateVisibility(isVisible: Bool) {
|
||||
if isVisible {
|
||||
@@ -117,6 +118,28 @@ final class MenuBarGuideOverlayPresenter {
|
||||
let overlayView = MenuBarGuideOverlayView()
|
||||
window.contentView = NSHostingView(rootView: overlayView)
|
||||
}
|
||||
|
||||
func setupOnboardingWindowObserver() {
|
||||
// Remove any existing observer to prevent duplicates
|
||||
if let observer = onboardingWindowObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
}
|
||||
|
||||
// Add observer for when the onboarding window is closed
|
||||
onboardingWindowObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSWindow.willCloseNotification,
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { [weak self] notification in
|
||||
guard let window = notification.object as? NSWindow,
|
||||
window.identifier == WindowIdentifiers.onboarding else {
|
||||
return
|
||||
}
|
||||
|
||||
// Hide the overlay when onboarding window closes
|
||||
self?.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MenuBarGuideOverlayView: View {
|
||||
|
||||
@@ -31,20 +31,11 @@ final class OnboardingWindowPresenter {
|
||||
|
||||
private var windowController: NSWindowController?
|
||||
private var closeObserver: NSObjectProtocol?
|
||||
private var isShowingWindow = false
|
||||
|
||||
func show(settingsManager: SettingsManager) {
|
||||
print("DEBUG: OnboardingWindowPresenter.show called")
|
||||
if activateIfPresent() {
|
||||
print("DEBUG: Onboarding already present, activated")
|
||||
return
|
||||
if activateIfPresent() {
|
||||
return
|
||||
}
|
||||
guard !isShowingWindow else {
|
||||
print("DEBUG: Onboarding already showing")
|
||||
return
|
||||
}
|
||||
isShowingWindow = true
|
||||
print("DEBUG: Creating new onboarding window")
|
||||
createWindow(settingsManager: settingsManager)
|
||||
}
|
||||
|
||||
@@ -56,7 +47,7 @@ final class OnboardingWindowPresenter {
|
||||
|
||||
// Even if not visible, we may still need to activate it if it exists
|
||||
let needsActivation = !window.isVisible || window.isMiniaturized
|
||||
|
||||
|
||||
if needsActivation {
|
||||
NSApp.unhide(nil)
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
@@ -68,21 +59,22 @@ final class OnboardingWindowPresenter {
|
||||
// Ensure the window is properly ordered front
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
window.orderFrontRegardless()
|
||||
|
||||
|
||||
// Make sure it's in the main space
|
||||
window.makeMain()
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func close() {
|
||||
removeCloseObserver()
|
||||
// Notify overlay presenter to hide the guide overlay
|
||||
MenuBarGuideOverlayPresenter.shared.hide()
|
||||
|
||||
windowController?.window?.close()
|
||||
windowController = nil
|
||||
isShowingWindow = false
|
||||
}
|
||||
|
||||
private func createWindow(settingsManager: SettingsManager) {
|
||||
@@ -122,29 +114,11 @@ final class OnboardingWindowPresenter {
|
||||
window.orderFrontRegardless()
|
||||
|
||||
windowController = controller
|
||||
|
||||
removeCloseObserver()
|
||||
closeObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSWindow.willCloseNotification,
|
||||
object: window,
|
||||
queue: .main
|
||||
) { [weak self] _ in
|
||||
Task { @MainActor in
|
||||
self?.windowController = nil
|
||||
self?.isShowingWindow = false
|
||||
self?.removeCloseObserver()
|
||||
}
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name("OnboardingWindowDidClose"), object: nil)
|
||||
}
|
||||
|
||||
// Setup observer for when the onboarding window closes
|
||||
MenuBarGuideOverlayPresenter.shared.setupOnboardingWindowObserver()
|
||||
}
|
||||
|
||||
private func removeCloseObserver() {
|
||||
if let observer = closeObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
closeObserver = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct OnboardingContainerView: View {
|
||||
|
||||
@@ -13,24 +13,16 @@ final class SettingsWindowPresenter {
|
||||
|
||||
private var windowController: NSWindowController?
|
||||
private var closeObserver: NSObjectProtocol?
|
||||
private var isShowingWindow = false
|
||||
|
||||
func show(settingsManager: SettingsManager, initialTab: Int = 0) {
|
||||
if focusExistingWindow(tab: initialTab) { return }
|
||||
guard !isShowingWindow else { return }
|
||||
isShowingWindow = true
|
||||
createWindow(settingsManager: settingsManager, initialTab: initialTab)
|
||||
}
|
||||
|
||||
func focus(tab: Int) {
|
||||
_ = focusExistingWindow(tab: tab)
|
||||
createWindow(settingsManager: settingsManager, initialTab: initialTab)
|
||||
}
|
||||
|
||||
func close() {
|
||||
windowController?.close()
|
||||
windowController = nil
|
||||
isShowingWindow = false
|
||||
removeCloseObserver()
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
@@ -95,28 +87,6 @@ final class SettingsWindowPresenter {
|
||||
|
||||
windowController = controller
|
||||
|
||||
removeCloseObserver()
|
||||
closeObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSWindow.willCloseNotification,
|
||||
object: window,
|
||||
queue: .main
|
||||
) { [weak self] _ in
|
||||
Task { @MainActor [weak self] in
|
||||
self?.windowController = nil
|
||||
self?.isShowingWindow = false
|
||||
self?.removeCloseObserver()
|
||||
NotificationCenter.default.post(
|
||||
name: Notification.Name("SettingsWindowDidClose"), object: nil)
|
||||
}
|
||||
self?.isShowingWindow = false
|
||||
}
|
||||
}
|
||||
|
||||
private func removeCloseObserver() {
|
||||
if let observer = closeObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
closeObserver = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user