Some checks failed
Build / test on ubuntu-latest (py-3.9) (push) Failing after 2m36s
Build / typecheck (push) Successful in 1m38s
Build / test on macos-latest (py-3.9) (push) Has been cancelled
Build / test on windows-latest (py-3.9) (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1s
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import logging
|
|
from multiprocessing import Process
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def background_ensure_permissions() -> None:
|
|
permission_process = Process(target=ensure_permissions, args=(()))
|
|
permission_process.start()
|
|
return
|
|
|
|
|
|
def ensure_permissions() -> None:
|
|
# noreorder
|
|
from AppKit import ( # fmt: skip
|
|
NSURL,
|
|
NSAlert,
|
|
NSAlertFirstButtonReturn,
|
|
NSWorkspace,
|
|
)
|
|
from ApplicationServices import AXIsProcessTrusted # fmt: skip
|
|
|
|
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)
|
|
|
|
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"
|
|
)
|
|
)
|