@@ -16,10 +16,10 @@ use std::{
1616 time:: { Duration , Instant } ,
1717} ;
1818use tauri:: { AppHandle , LogicalSize , Manager , RunEvent , State , WebviewWindowBuilder } ;
19- #[ cfg( any( target_os = "linux" , all( debug_assertions, windows) ) ) ]
20- use tauri_plugin_deep_link:: DeepLinkExt ;
2119#[ cfg( windows) ]
2220use tauri_plugin_decorum:: WebviewWindowExt ;
21+ #[ cfg( any( target_os = "linux" , all( debug_assertions, windows) ) ) ]
22+ use tauri_plugin_deep_link:: DeepLinkExt ;
2323use tauri_plugin_dialog:: { DialogExt , MessageDialogButtons , MessageDialogResult } ;
2424use tauri_plugin_shell:: process:: { CommandChild , CommandEvent } ;
2525use tauri_plugin_store:: StoreExt ;
@@ -30,7 +30,7 @@ use crate::window_customizer::PinchZoomDisablePlugin;
3030const SETTINGS_STORE : & str = "opencode.settings.dat" ;
3131const DEFAULT_SERVER_URL_KEY : & str = "defaultServerUrl" ;
3232
33- #[ derive( Clone , serde:: Serialize ) ]
33+ #[ derive( Clone , serde:: Serialize , specta :: Type ) ]
3434struct ServerReadyData {
3535 url : String ,
3636 password : Option < String > ,
@@ -64,6 +64,7 @@ struct LogState(Arc<Mutex<VecDeque<String>>>);
6464const MAX_LOG_ENTRIES : usize = 200 ;
6565
6666#[ tauri:: command]
67+ #[ specta:: specta]
6768fn kill_sidecar ( app : AppHandle ) {
6869 let Some ( server_state) = app. try_state :: < ServerState > ( ) else {
6970 println ! ( "Server not running" ) ;
@@ -97,6 +98,7 @@ async fn get_logs(app: AppHandle) -> Result<String, String> {
9798}
9899
99100#[ tauri:: command]
101+ #[ specta:: specta]
100102async fn ensure_server_ready ( state : State < ' _ , ServerState > ) -> Result < ServerReadyData , String > {
101103 state
102104 . status
@@ -106,6 +108,7 @@ async fn ensure_server_ready(state: State<'_, ServerState>) -> Result<ServerRead
106108}
107109
108110#[ tauri:: command]
111+ #[ specta:: specta]
109112fn get_default_server_url ( app : AppHandle ) -> Result < Option < String > , String > {
110113 let store = app
111114 . store ( SETTINGS_STORE )
@@ -119,6 +122,7 @@ fn get_default_server_url(app: AppHandle) -> Result<Option<String>, String> {
119122}
120123
121124#[ tauri:: command]
125+ #[ specta:: specta]
122126async fn set_default_server_url ( app : AppHandle , url : Option < String > ) -> Result < ( ) , String > {
123127 let store = app
124128 . store ( SETTINGS_STORE )
@@ -252,6 +256,26 @@ async fn check_server_health(url: &str, password: Option<&str>) -> bool {
252256pub fn run ( ) {
253257 let updater_enabled = option_env ! ( "TAURI_SIGNING_PRIVATE_KEY" ) . is_some ( ) ;
254258
259+ let builder = tauri_specta:: Builder :: < tauri:: Wry > :: new ( )
260+ // Then register them (separated by a comma)
261+ . commands ( tauri_specta:: collect_commands![
262+ kill_sidecar,
263+ install_cli,
264+ ensure_server_ready,
265+ get_default_server_url,
266+ set_default_server_url,
267+ markdown:: parse_markdown_command
268+ ] )
269+ . error_handling ( tauri_specta:: ErrorHandlingMode :: Throw ) ;
270+
271+ #[ cfg( debug_assertions) ] // <- Only export on non-release builds
272+ builder
273+ . export (
274+ specta_typescript:: Typescript :: default ( ) ,
275+ "../src/bindings.ts" ,
276+ )
277+ . expect ( "Failed to export typescript bindings" ) ;
278+
255279 #[ cfg( all( target_os = "macos" , not( debug_assertions) ) ) ]
256280 let _ = std:: process:: Command :: new ( "killall" )
257281 . arg ( "opencode-cli" )
@@ -285,15 +309,10 @@ pub fn run() {
285309 . plugin ( tauri_plugin_notification:: init ( ) )
286310 . plugin ( PinchZoomDisablePlugin )
287311 . plugin ( tauri_plugin_decorum:: init ( ) )
288- . invoke_handler ( tauri:: generate_handler![
289- kill_sidecar,
290- install_cli,
291- ensure_server_ready,
292- get_default_server_url,
293- set_default_server_url,
294- markdown:: parse_markdown_command
295- ] )
312+ . invoke_handler ( builder. invoke_handler ( ) )
296313 . setup ( move |app| {
314+ builder. mount_events ( app) ;
315+
297316 #[ cfg( any( target_os = "linux" , all( debug_assertions, windows) ) ) ]
298317 app. deep_link ( ) . register_all ( ) . ok ( ) ;
299318
0 commit comments