
    Ojk                        d Z ddlmZ ddlZddlZej
                  dk(  ZddZddZdddZ	dddZ
dd	Zdd
ZdddZy)u  Screen capture — works under macOS TCC and on Windows.

macOS: Jarvis used to shell out `screencapture` via the Bash tool, but that
runs deep inside the bundled `claude` CLI process tree, which macOS holds
responsible for the TCC check — NOT Jarvis.app — so capture was denied no
matter how many times Ahmed toggled the app on. The engine process (this
Python) is a direct child of Jarvis.app (the app that holds the grant), so we
capture HERE and the `screencapture` we spawn inherits the engine's
responsible process. CoreGraphics' CGDisplayCreateImage is deprecated on
macOS 26 (Tahoe) and returns a BLANK image — `screencapture` still works.

Windows: no screen-recording permission wall (no TCC), so `mss` (fast
multi-monitor grabber) writes the PNG directly; nothing to preflight.

Public interface is identical on both so main.py / control.py call it
unchanged: has_access(), request_access(), capture(path, display).
    )annotationsNdarwinc                 <    dd l } t        | j                               S Nr   )QuartzboolCGPreflightScreenCaptureAccessr   s    :/Users/ahmed/devFolder/Ultron/claude-voice/voice/screen.py_mac_has_accessr      s    55788    c                 <    dd l } t        | j                               S r   )r   r   CGRequestScreenCaptureAccessr
   s    r   _mac_request_accessr   #   s    33566r   c                   t               st                t               syt        j                  j	                  |       }|rt        j
                  |d       ddg}|	 |dt        t        |            gz  }|j                  |        dd l}	 |j                  |ddd	      }|j                  dk7  r#d
|j                  j!                         xs dd d fS y# t        t        f$ r Y ow xY w# t        $ r}d
d| d d fcY d }~S d }~ww xY w)N)Fno_screen_recording_permissionTexist_okscreencapturez-xz-Dr      )capture_outputtexttimeoutFcapture_error:x   screencapture_failedTN)r   r   ospathdirnamemakedirsstrint	TypeError
ValueErrorappend
subprocessrun	Exception
returncodestderrstrip)r   displayparentargsr'   res          r   _mac_capturer2   (   s
    :WW__T"F
FT*T"D	T3s7|,--D 	KK1NN44NL 	||qqxx~~'A+A4CHHH :& 		  1qc*4C0001s0   C C+ C('C(+	D4	D=DDc                b   	 dd l }dd l}t        j                  j	                  |       }|rt        j
                  |d       |j                         5 }|j                  }|st        |      dkD  r|d   n|d   }n?t        |      }d|cxk  rt        |      k  rn n||   nt        |      dkD  r|d   n|d   }|j                  |      }|j                  j                  |j                  |j                  |        d d d        y# 1 sw Y   yxY w# t        $ r}	dd|	 d d	 fcY d }	~	S d }	~	ww xY w)
Nr   Tr      )outputr   Fr   r   )mss	mss.toolsr   r   r    r!   monitorslenr#   grabtoolsto_pngrgbsizer)   )
r   r-   r6   r.   sctr8   monnimgr1   s
             r   _mss_capturerC   D   s	   1&KK.WWY#||H%(]Q%6hqkHQKL%&!%;c(m%;hqk#&x=1#4HQK(1+ ((3-CIISWWchht<     1qc*4C0001s=   AD B*D<D D
D D 	D.	D)#D.)D.c                 D    t         r	 t               S y# t        $ r Y yw xY w)z<True if this process may record the screen. Windows: always.FT)_DARWINr   r)    r   r   
has_accessrG   ^   s,    	"$$   		   	 	c                 D    t         r	 t               S y# t        $ r Y yw xY w)u   Prompt for Screen Recording (macOS) / no-op (Windows). Returns whether
    access is granted right now — a fresh macOS grant may only apply after the
    app is relaunched.FT)rE   r   r)   rF   r   r   request_accessrJ   h   s.     	&((   		rH   c                >    t         rt        | |      S t        | |      S )zeCapture a display to `path` as PNG. `display` is 1-based (None = main).
    Returns (ok, error_slug).)rE   r2   rC   )r   r-   s     r   capturerL   t   s     +2<g&R|D'7RRr   )returnr   )N)r   r"   rM   ztuple[bool, str | None])__doc__
__future__r   r   sysplatformrE   r   r   r2   rC   rG   rJ   rL   rF   r   r   <module>rR      sG   $ # 	 

,,(
"9
7
814	Sr   