Skip to content

Commit

Permalink
Remove AlertWindowsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Sep 18, 2023
1 parent 7a43b17 commit fece577
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 495 deletions.
142 changes: 0 additions & 142 deletions src/apps/SettingsWindow/src/AlertWindowsManager.swift

This file was deleted.

1 change: 0 additions & 1 deletion src/apps/SettingsWindow/src/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public class AppDelegate: NSObject, NSApplicationDelegate {
// Start StateJsonMonitor
//

AlertWindowsManager.shared.parentWindow = window
StateJsonMonitor.shared.start()

//
Expand Down
12 changes: 12 additions & 0 deletions src/apps/SettingsWindow/src/ContentViewStates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import SwiftUI
final class ContentViewStates: ObservableObject {
static let shared = ContentViewStates()

//
// Alerts
//

@Published public var showDriverNotActivatedAlert = false
@Published public var showDriverVersionMismatchedAlert = false
@Published public var showInputMonitoringPermissionsAlert = false

//
// ContentMainView
//

@Published var navigationSelection = NavigationTag.simpleModifications

//
Expand Down
71 changes: 16 additions & 55 deletions src/apps/SettingsWindow/src/StateJsonMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public class StateJsonMonitor {

private var states: [String: State] = [:]

public var needsDriverNotActivatedAlert = false
public var needsDriverVersionMismatchedAlert = false
public var needsInputMonitoringPermissionsAlert = false

public func start() {
let obj = unsafeBitCast(self, to: UnsafeMutableRawPointer.self)
libkrbn_enable_observer_state_json_file_monitor(callback, obj)
Expand Down Expand Up @@ -72,79 +68,44 @@ public class StateJsonMonitor {
// print("driverVersionMismatched \(driverVersionMismatched)")
// print("inputMonitoringNotPermitted \(inputMonitoringNotPermitted)")

let contentViewStates = ContentViewStates.shared

//
// - DriverNotActivatedAlertWindow
// - DriverVersionMismatchedAlertWindow
// - DriverNotActivatedAlert
// - DriverVersionMismatchedAlert
//

if needsDriverVersionMismatchedAlert {
// If DriverVersionMismatchedAlertWindow is shown,
// keep needsDriverNotActivatedAlert to prevent showing DriverNotActivatedAlertWindow after the driver is deactivated.
if contentViewStates.showDriverVersionMismatchedAlert {
// If diverVersionMismatchedAlert is shown,
// keep needsDriverNotActivatedAlert to prevent showing DriverNotActivatedAlert after the driver is deactivated.

if !driverVersionMismatched {
needsDriverVersionMismatchedAlert = false
contentViewStates.showDriverVersionMismatchedAlert = false
}

} else {
if driverNotActivated {
needsDriverNotActivatedAlert = true
needsDriverVersionMismatchedAlert = false
contentViewStates.showDriverNotActivatedAlert = true
contentViewStates.showDriverVersionMismatchedAlert = false
} else {
needsDriverNotActivatedAlert = false
contentViewStates.showDriverNotActivatedAlert = false

if driverVersionMismatched {
needsDriverVersionMismatchedAlert = true
contentViewStates.showDriverVersionMismatchedAlert = true
} else {
needsDriverVersionMismatchedAlert = false
contentViewStates.showDriverVersionMismatchedAlert = false
}
}
}

//
// - InputMonitoringPermissionsAlertWindow
// - InputMonitoringPermissionsAlert
//

if inputMonitoringNotPermitted {
needsInputMonitoringPermissionsAlert = true
contentViewStates.showInputMonitoringPermissionsAlert = true
} else {
needsInputMonitoringPermissionsAlert = false
}

print("needsDriverNotActivatedAlert \(needsDriverNotActivatedAlert)")
print("needsDriverVersionMismatchedAlert \(needsDriverVersionMismatchedAlert)")
print("needsInputMonitoringPermissionsAlert \(needsInputMonitoringPermissionsAlert)")

//
// Update alert window
//

updateAlertWindow(
needsAlert: { return StateJsonMonitor.shared.needsDriverNotActivatedAlert },
show: { AlertWindowsManager.shared.showDriverNotActivatedAlertWindow() },
hide: { AlertWindowsManager.shared.hideDriverNotActivatedAlertWindow() })

updateAlertWindow(
needsAlert: { return StateJsonMonitor.shared.needsDriverVersionMismatchedAlert },
show: { AlertWindowsManager.shared.showDriverVersionMismatchedAlertWindow() },
hide: { AlertWindowsManager.shared.hideDriverVersionMismatchedAlertWindow() })

updateAlertWindow(
needsAlert: { return StateJsonMonitor.shared.needsInputMonitoringPermissionsAlert },
show: { AlertWindowsManager.shared.showInputMonitoringPermissionsAlertWindow() },
hide: { AlertWindowsManager.shared.hideInputMonitoringPermissionsAlertWindow() })
}

private func updateAlertWindow(
needsAlert: @escaping () -> Bool,
show: @escaping () -> Void,
hide: @escaping () -> Void
) {
Task { @MainActor in
if needsAlert() {
show()
} else {
hide()
}
contentViewStates.showInputMonitoringPermissionsAlert = false
}
}
}
Loading

0 comments on commit fece577

Please sign in to comment.