ActivityWatch / aw-watcher-window

Cross-platform window watcher (for use with ActivityWatch)
Mozilla Public License 2.0
91 stars 53 forks source link

WIP: Ensure Accessibility permissions on macOS #41

Closed xylix closed 4 years ago

xylix commented 4 years ago
Screenshot 2020-03-28 at 17 43 21

Use AppKit to figure if we have accessibility perms and pyobjc to ask for them.

Still needs to:

xylix commented 4 years ago

Is it possible to add a button on the alert that opens the accessibility settings? I think I've seen that somewhere.

I found these https://macosxautomation.com/system-prefs-links.html which work as links, but I'm still looking for a way to make the button press "open" the link to the accessibility settings. A standard <a href> link didn't work, but there should be a sane way to link in NSAlert buttons.

Found it. Need to call NSWorkspace.sharedWorkspace().openURL_(NSURL.URLWithString_("x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")) on button press.

lgtm-com[bot] commented 4 years ago

This pull request introduces 4 alerts when merging 890b6d65af84c96c9d62e641c0d6c1bb86edb302 into 25ae6997d4c848c96970c573b4fec14236009a9a - view on LGTM.com

new alerts:

lgtm-com[bot] commented 4 years ago

This pull request introduces 1 alert when merging f032ed1ad2a7903f42f3077d74a6d2c4f9b440f4 into 25ae6997d4c848c96970c573b4fec14236009a9a - view on LGTM.com

new alerts:

xylix commented 4 years ago

Using a native python thread causes a

objc.error: NSInternalInconsistencyException - NSWindow drag regions should only be invalidated on the Main Thread!

Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.30.142/AppKit.subproj/NSView.m, line 13568.
fish: 'python aw_watcher_window/__main…' terminated by signal SIGILL (Illegal instruction)

Error. Will need to look into using macOS's own work queue (https://developer.apple.com/documentation/dispatch/1452927-dispatch_get_global_queue?language=objc )

ErikBjare commented 4 years ago

If the issue is that the stuff needs to happen on the main thread, try using the Python multiprocessing module? A bit hacky but will probably work.

On Sun, 29 Mar 2020, 17:49 Kerkko Pelttari, notifications@github.com wrote:

Using a native python thread causes a ```objc.error: NSInternalInconsistencyException - NSWindow drag regions should only be invalidated on the Main Thread!

Assertion failed: (NSViewIsCurrentlyBuildingLayerTreeForDisplay() != currentlyBuildingLayerTree), function NSViewSetCurrentlyBuildingLayerTreeForDisplay, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.30.142/AppKit.subproj/NSView.m, line 13568. fish: 'python aw_watcher_window/__main…' terminated by signal SIGILL (Illegal instruction)```Error. Will need to look into using macOS's own work queue ( https://developer.apple.com/documentation/dispatch/1452927-dispatch_get_global_queue?language=objc )

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ActivityWatch/aw-watcher-window/pull/41#issuecomment-605657325, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKXDOW67AZCNZR2TDZXBA3RJ5UZ7ANCNFSM4LVTVLEA .

xylix commented 4 years ago

Seems like it should work. I'll look into it later this week.

xylix commented 4 years ago

Multiprocessing got rid of the objc.error: NSInternalInconsistencyException - NSWindow drag regions should only be invalidated on the Main Thread! problem. The alert is still a bit wonky (it doesn't "pop up" in the desktop like an alert should, instead it stays in the background and shakes in the macOS dock.

It does now block execution though... which is weird. The window watcher continues execution after I close the modal.

I think I resolved the conflict correctly, will need to see what CI says.

lgtm-com[bot] commented 4 years ago

This pull request introduces 1 alert when merging 3ad2af62e130706c061bf7fc45de66b4f2e608bd into 620b52cb169b2c6e25aad6ea16799324ee6f7318 - view on LGTM.com

new alerts:

lgtm-com[bot] commented 4 years ago

This pull request introduces 1 alert when merging b829e0421d56cd4d1bdc0fb0d8ef71652638db72 into 620b52cb169b2c6e25aad6ea16799324ee6f7318 - view on LGTM.com

new alerts:

xylix commented 4 years ago

There might have still been some problem, I'll need to manually test on macOS before I can be sure. I'll get that done tomorrow, bit busy today.

xylix commented 4 years ago

@ErikBjare Looks fine to merge, I tested it locally and solved the conflict of the lock file.

lgtm-com[bot] commented 4 years ago

This pull request introduces 1 alert when merging 724a3e2b5775ad1d327adcbe506df19c735fd83d into 8075f16de6512767491712946ed5741d2ed9eb9c - view on LGTM.com

new alerts:

ErikBjare commented 4 years ago

@xylix Are the two things in the top comment resolved?

xylix commented 4 years ago

@ErikBjare Oh right. I guess the other one is not, because it is actually pretty hard in recent macOS to set a setting from dialog. Instead the dialog just gives a message and Open Accessibility Options button.

ErikBjare commented 4 years ago

@xylix Should we just leave it as is then and merge?

xylix commented 4 years ago

Yeah I think we should. The other open PR requires more work before it is ready but this one will be an improvement even in it's current form.

ErikBjare commented 4 years ago

Nice! Merging.