-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed import in main, moved macos permission prompt into seperat…
…e file
- Loading branch information
Showing
3 changed files
with
68 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def background_ensure_permissions() -> None: | ||
from multiprocessing import Process | ||
|
||
permission_process = Process(target=ensure_permissions, args=(())) | ||
permission_process.start() | ||
return | ||
|
||
|
||
def ensure_permissions() -> None: | ||
from ApplicationServices import AXIsProcessTrusted | ||
from AppKit import NSAlert, NSAlertFirstButtonReturn, NSWorkspace, NSURL | ||
|
||
accessibility_permissions = AXIsProcessTrusted() | ||
if not accessibility_permissions: | ||
logger.info("No accessibility permissions, prompting user") | ||
title = "Missing accessibility permissions" | ||
info = "To let ActivityWatch capture window titles grant it accessibility permissions. \n If you've already given ActivityWatch accessibility permissions and are still seeing this dialog, try removing and re-adding them." | ||
|
||
alert = NSAlert.new() | ||
alert.setMessageText_(title) | ||
alert.setInformativeText_(info) | ||
|
||
ok_button = alert.addButtonWithTitle_("Open accessibility settings") | ||
|
||
alert.addButtonWithTitle_("Close") | ||
choice = alert.runModal() | ||
if choice == NSAlertFirstButtonReturn: | ||
NSWorkspace.sharedWorkspace().openURL_( | ||
NSURL.URLWithString_( | ||
"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility" | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters