HASEL-UZH / PersonalAnalytics

Personal Analytics project to increase knowledge workers' awareness about work and productivity.
https://hasel.dev/project/individual-productivity/
Other
53 stars 15 forks source link

Window Name Tracking shows as not allowed sometimes, even when actually enabled. #263

Open csatterfield opened 3 years ago

csatterfield commented 3 years ago

It seems that the window list used in this function can sometimes contain a window with a nil name, meaning the tracking will show as disabled even if its actually enabled.

    func isWindowNameTrackingEnabled() -> Bool {
        // 22.4.2020 - the latest privacy measures in Catalina require screen capture permission in order to access the window name of an application. See: https://stackoverflow.com/questions/56597221/detecting-screen-recording-settings-on-macos-catalina
        guard let windows = CGWindowListCopyWindowInfo([.optionOnScreenOnly], kCGNullWindowID) as? [[String: AnyObject]] else { return false }
        return windows.allSatisfy({ window in
            let windowName = window[kCGWindowName as String] as? String
            return windowName != nil
        })
    }

A quick fix is to check for at least one non-nil window belonging to an application other than PersonalAnalytics, but this might still give an erroneous status. Is there a better way to do this check?