refactor: permissions window is lazily initialized
This commit is contained in:
1 parent
da21cb8e21
commit
93e2b35dc7
2 files changed
+25
-14
No files matched your search
@@ -16,7 +16,8 @@ class SystemPermissions {
|
||||
|
||||
private static func checkPermissionsOnTimer() {
|
||||
AccessibilityPermission.update()
|
||||
if !preStartupPermissionsPassed || App.app.permissionsWindow.isVisible {
|
||||
let isPermissionsWindowVisible = App.app.permissionsWindow?.isVisible ?? false
|
||||
if !preStartupPermissionsPassed || isPermissionsWindowVisible {
|
||||
ScreenRecordingPermission.update()
|
||||
}
|
||||
Logger.debug { "accessibility:\(AccessibilityPermission.status) screenRecording:\(ScreenRecordingPermission.status)" }
|
||||
@@ -24,15 +25,15 @@ class SystemPermissions {
|
||||
checkPermissionsPreStartup()
|
||||
} else {
|
||||
checkPermissionsPostStartup()
|
||||
if App.app.permissionsWindow.isVisible && !timerIsFrequent {
|
||||
if isPermissionsWindowVisible && !timerIsFrequent {
|
||||
setFrequentTimer()
|
||||
} else if !App.app.permissionsWindow.isVisible && timerIsFrequent {
|
||||
} else if !isPermissionsWindowVisible && timerIsFrequent {
|
||||
setInfrequentTimer()
|
||||
}
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
Menubar.togglePermissionCallout(ScreenRecordingPermission.status != .granted)
|
||||
App.app.permissionsWindow.updatePermissionViews()
|
||||
App.app.permissionsWindow?.updatePermissionViews()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ class SystemPermissions {
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
App.app.permissionsWindow.show()
|
||||
App.app.showPermissionsWindow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-9
@@ -21,7 +21,7 @@ class App: AppCenterApplication {
|
||||
var thumbnailsPanel: TilesPanel!
|
||||
var previewPanel: PreviewPanel!
|
||||
var preferencesWindow: PreferencesWindow!
|
||||
var permissionsWindow: PermissionsWindow!
|
||||
var permissionsWindow: PermissionsWindow?
|
||||
var appIsBeingUsed = false
|
||||
var shortcutIndex = 0
|
||||
var forceDoNothingOnRelease = false
|
||||
@@ -93,7 +93,7 @@ class App: AppCenterApplication {
|
||||
private func allSecondaryWindowsCanBecomeKey(_ canBecomeKey_: Bool) {
|
||||
preferencesWindow?.canBecomeKey_ = canBecomeKey_
|
||||
feedbackWindow?.canBecomeKey_ = canBecomeKey_
|
||||
permissionsWindow.canBecomeKey_ = canBecomeKey_
|
||||
permissionsWindow?.canBecomeKey_ = canBecomeKey_
|
||||
}
|
||||
|
||||
func closeSelectedWindow() {
|
||||
@@ -147,7 +147,7 @@ class App: AppCenterApplication {
|
||||
}
|
||||
|
||||
@objc func checkPermissions(_ sender: NSMenuItem) {
|
||||
permissionsWindow.show()
|
||||
showPermissionsWindow()
|
||||
}
|
||||
|
||||
@objc func supportProject() {
|
||||
@@ -155,11 +155,11 @@ class App: AppCenterApplication {
|
||||
}
|
||||
|
||||
@objc func showFeedbackPanel() {
|
||||
showSecondaryWindow(ensureFeedbackWindow())
|
||||
showSecondaryWindow(getOrCreateFeedbackWindow())
|
||||
}
|
||||
|
||||
@objc func showPreferencesWindow() {
|
||||
showSecondaryWindow(ensurePreferencesWindow())
|
||||
showSecondaryWindow(getOrCreatePreferencesWindow())
|
||||
}
|
||||
|
||||
func showSecondaryWindow(_ window: NSWindow?) {
|
||||
@@ -173,20 +173,31 @@ class App: AppCenterApplication {
|
||||
}
|
||||
}
|
||||
|
||||
private func ensurePreferencesWindow() -> PreferencesWindow {
|
||||
private func getOrCreatePreferencesWindow() -> PreferencesWindow {
|
||||
if preferencesWindow == nil {
|
||||
preferencesWindow = PreferencesWindow()
|
||||
}
|
||||
return preferencesWindow
|
||||
}
|
||||
|
||||
private func ensureFeedbackWindow() -> FeedbackWindow {
|
||||
private func getOrCreateFeedbackWindow() -> FeedbackWindow {
|
||||
if feedbackWindow == nil {
|
||||
feedbackWindow = FeedbackWindow()
|
||||
}
|
||||
return feedbackWindow
|
||||
}
|
||||
|
||||
private func getOrCreatePermissionsWindow() -> PermissionsWindow {
|
||||
if permissionsWindow == nil {
|
||||
permissionsWindow = PermissionsWindow()
|
||||
}
|
||||
return permissionsWindow!
|
||||
}
|
||||
|
||||
func showPermissionsWindow() {
|
||||
getOrCreatePermissionsWindow().show()
|
||||
}
|
||||
|
||||
func showUi(_ shortcutIndex: Int) {
|
||||
showUiOrCycleSelection(shortcutIndex, true)
|
||||
}
|
||||
@@ -196,7 +207,7 @@ class App: AppCenterApplication {
|
||||
}
|
||||
|
||||
@objc func showAboutTab() {
|
||||
ensurePreferencesWindow().selectTab("about")
|
||||
getOrCreatePreferencesWindow().selectTab("about")
|
||||
showPreferencesWindow()
|
||||
}
|
||||
|
||||
@@ -353,7 +364,6 @@ extension App: NSApplicationDelegate {
|
||||
#endif
|
||||
AXUIElement.setGlobalTimeout()
|
||||
Preferences.initialize()
|
||||
permissionsWindow = PermissionsWindow()
|
||||
BackgroundWork.preStart()
|
||||
SystemPermissions.ensurePermissionsAreGranted()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user