@@ -27,8 +27,8 @@ use std::{
2727 time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ,
2828} ;
2929use taskers_control:: {
30- BrowserControlCommand , ControlCommand , ControlError , ControlResponse , TerminalDebugCommand ,
31- bind_socket, default_socket_path, serve_with_handler,
30+ BrowserControlCommand , ControlCommand , ControlError , ControlResponse , ScreenshotCommand ,
31+ TerminalDebugCommand , bind_socket, default_socket_path, serve_with_handler,
3232} ;
3333use taskers_core:: { AppState , default_session_path, load_or_bootstrap} ;
3434use taskers_domain:: { AppModel , NotificationDeliveryState , NotificationId , SignalKind } ;
@@ -118,6 +118,7 @@ struct RuntimePathOverrides {
118118
119119enum HostAutomationCommand {
120120 Browser ( BrowserControlCommand ) ,
121+ Screenshot ( ScreenshotCommand ) ,
121122 TerminalDebug ( TerminalDebugCommand ) ,
122123}
123124
@@ -1443,14 +1444,14 @@ fn run_internal_surface_probe(
14431444 mode : GhosttyProbeMode ,
14441445 config : TaskersConfig ,
14451446) -> glib:: ExitCode {
1446- if !gtk:: is_initialized_main_thread ( ) {
1447- if let Err ( error) = gtk:: init ( ) {
1448- safe_eprintln ( format ! (
1449- "ghostty {} self-probe failed during gtk init: {error}" ,
1450- mode . as_arg ( )
1451- ) ) ;
1452- return glib :: ExitCode :: FAILURE ;
1453- }
1447+ if !gtk:: is_initialized_main_thread ( )
1448+ && let Err ( error) = gtk:: init ( )
1449+ {
1450+ safe_eprintln ( format ! (
1451+ "ghostty {} self-probe failed during gtk init: {error}" ,
1452+ mode . as_arg ( )
1453+ ) ) ;
1454+ return glib :: ExitCode :: FAILURE ;
14541455 }
14551456
14561457 let settings = WebKitSettings :: builder ( )
@@ -1801,6 +1802,15 @@ async fn handle_host_request(
18011802 )
18021803 . await
18031804 }
1805+ HostAutomationCommand :: Screenshot ( command) => handle_screenshot_request (
1806+ window,
1807+ core,
1808+ host,
1809+ last_revision,
1810+ last_size,
1811+ diagnostics,
1812+ command,
1813+ ) ,
18041814 HostAutomationCommand :: TerminalDebug ( command) => handle_terminal_debug_request (
18051815 window,
18061816 core,
@@ -1866,6 +1876,21 @@ fn handle_terminal_debug_request(
18661876 Ok ( ControlResponse :: TerminalDebug { result } )
18671877}
18681878
1879+ fn handle_screenshot_request (
1880+ window : & adw:: ApplicationWindow ,
1881+ core : & SharedCore ,
1882+ host : & Rc < RefCell < TaskersHost > > ,
1883+ last_revision : & Rc < Cell < u64 > > ,
1884+ last_size : & Rc < Cell < ( i32 , i32 ) > > ,
1885+ diagnostics : Option < & DiagnosticsWriter > ,
1886+ command : ScreenshotCommand ,
1887+ ) -> Result < ControlResponse , ControlError > {
1888+ sync_window ( window, core, host, last_revision, last_size, diagnostics) ;
1889+ let result = host. borrow_mut ( ) . execute_screenshot ( command) ?;
1890+ sync_window ( window, core, host, last_revision, last_size, diagnostics) ;
1891+ Ok ( ControlResponse :: Screenshot { result } )
1892+ }
1893+
18691894fn browser_surface_id ( command : & BrowserControlCommand ) -> taskers_shell_core:: SurfaceId {
18701895 match command {
18711896 BrowserControlCommand :: Navigate { surface_id, .. }
@@ -1947,6 +1972,27 @@ fn spawn_control_server(
19471972 )
19481973 } ) ?
19491974 }
1975+ ControlCommand :: Screenshot { screenshot_command } => {
1976+ let ( response_tx, response_rx) =
1977+ tokio:: sync:: oneshot:: channel ( ) ;
1978+ host_tx
1979+ . send ( HostAutomationRequest {
1980+ command : HostAutomationCommand :: Screenshot (
1981+ screenshot_command,
1982+ ) ,
1983+ response_tx,
1984+ } )
1985+ . map_err ( |_| {
1986+ ControlError :: internal (
1987+ "host automation bridge is unavailable" ,
1988+ )
1989+ } ) ?;
1990+ response_rx. await . map_err ( |_| {
1991+ ControlError :: internal (
1992+ "host automation bridge dropped the response" ,
1993+ )
1994+ } ) ?
1995+ }
19501996 ControlCommand :: TerminalDebug { debug_command } => {
19511997 let ( response_tx, response_rx) =
19521998 tokio:: sync:: oneshot:: channel ( ) ;
@@ -2434,7 +2480,7 @@ mod startup_tests {
24342480 #[ test]
24352481 fn launcher_bundle_binary_does_not_use_dev_diagnostics ( ) {
24362482 assert ! ( !looks_like_dev_install( Path :: new(
2437- "/home/notes/.local/share/taskers/releases/0.4 .0/x86_64-unknown-linux-gnu/taskers-gtk"
2483+ "/home/notes/.local/share/taskers/releases/0.5 .0/x86_64-unknown-linux-gnu/taskers-gtk"
24382484 ) ) ) ;
24392485 }
24402486
0 commit comments