Skip to content

Commit

Permalink
fix: launch crash on macOS versions < 10.15
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Jul 17, 2020
1 parent e25716b commit d817545
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/logic/SystemPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Cocoa
// macOS has some privacy restrictions. The user needs to grant certain permissions, app by app, in System Preferences > Security & Privacy
class SystemPermissions {
static var changeCallback: (() -> Void)!
static var screenRecordingObserver: Timer!
static var timer: Timer!
static var permissionsWindow: PermissionsWindow!

static func accessibilityIsGranted() -> Bool {
Expand Down Expand Up @@ -42,22 +42,24 @@ class SystemPermissions {
}

static func observePermissionsPostStartup() {
screenRecordingObserver = Timer.scheduledTimer(withTimeInterval: 5, repeats: true, block: { _ in
timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true, block: { _ in
if !(accessibilityIsGranted() && screenRecordingIsGranted()) {
App.app.restart()
}
})
}

static func observePermissionsPreStartup(_ startupBlock: @escaping () -> Void) {
// this call triggers the permission prompt, however it's the only way to force the app to be listed with a checkbox
SLSRequestScreenCaptureAccess()
screenRecordingObserver = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { _ in
if #available(OSX 10.15, *) {
// this call triggers the permission prompt, however it's the only way to force the app to be listed with a checkbox
SLSRequestScreenCaptureAccess()
}
timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { _ in
let accessibility = accessibilityIsGranted()
let screenRecording = screenRecordingIsGranted()
if accessibility && screenRecording {
permissionsWindow.close()
screenRecordingObserver.invalidate()
timer.invalidate()
startupBlock()
} else {
if accessibility != permissionsWindow.accessibilityView.isPermissionGranted {
Expand Down

0 comments on commit d817545

Please sign in to comment.