From 4003df41e114b319399b84eb19f19d0dd1424315 Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Mon, 22 Feb 2021 23:35:00 +0900 Subject: [PATCH] fix: avoid restarting alt-tab in some rare scenarios (#825) --- src/logic/SystemPermissions.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/logic/SystemPermissions.swift b/src/logic/SystemPermissions.swift index d0041ccc..791703c6 100644 --- a/src/logic/SystemPermissions.swift +++ b/src/logic/SystemPermissions.swift @@ -36,10 +36,20 @@ class SystemPermissions { } static func observePermissionsPostStartup() { + var counter = 0 timer = Timer(timeInterval: 5, repeats: true, block: { _ in - if !(accessibilityIsGranted() && screenRecordingIsGranted()) { + if !accessibilityIsGranted() { App.app.restart() } + if !screenRecordingIsGranted() { + // permission check may yield a false negative during wake-up + // we restart after 2 negative checks + if counter >= 2 { + App.app.restart() + } else { + counter += 1 + } + } }) timer.tolerance = 4.9 CFRunLoopAddTimer(BackgroundWork.systemPermissionsThread.runLoop, timer, .defaultMode)