cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

ci/pipeline-ergonomics
goq / src-tauri / src / main.rs
main.rs 5.7K
1// Prevents additional console window on Windows in release, DO NOT REMOVE!!2#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]34mod commands;5mod media;6mod platform_capabilities;78use commands::AppState;910fn main() {11 let state = match AppState::from_args(std::env::args_os()) {12 Ok(state) => state,13 Err(error) => {14 eprintln!("portal: {error}");15 std::process::exit(2);16 }17 };1819 let app = tauri::Builder::default()20 // Must be registered first so secondary deep-link launches are routed21 // into the already-running Portal process.22 .plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| {23 for argument in argv.into_iter().skip(1) {24 let path = std::path::PathBuf::from(&argument);25 if path.extension().and_then(|value| value.to_str()) != Some("goq-invite") {26 continue;27 }28 if let Ok(url) = url::Url::from_file_path(path)29 && let Err(error) = commands::enrollment::stage_opened_url(app, &url)30 {31 log::warn!("could not import invitation from secondary launch: {error}");32 }33 }34 }))35 .plugin(tauri_plugin_deep_link::init())36 .plugin(tauri_plugin_dialog::init())37 // The native window belongs to the user, not the current stream.38 // Persist its last size/position across relaunches; incoming video is39 // letterboxed inside those bounds by the frontend.40 .plugin(tauri_plugin_window_state::Builder::default().build())41 // Packet-level transport logs are catastrophically expensive in an42 // interactive media client. Keep actionable warnings and errors43 // without formatting every QUIC packet on the UI-critical machine.44 .plugin(45 tauri_plugin_log::Builder::default()46 .level(log::LevelFilter::Warn)47 .build(),48 )49 .manage(state)50 .setup(|app| {51 use tauri::Manager;52 use tauri_plugin_deep_link::DeepLinkExt;5354 if let Ok(Some(urls)) = app.deep_link().get_current() {55 for url in urls {56 if let Err(error) = commands::enrollment::stage_opened_url(app.handle(), &url) {57 log::warn!("could not import startup invitation: {error}");58 }59 }60 }61 let app_handle = app.handle().clone();62 app.deep_link().on_open_url(move |event| {63 for url in event.urls() {64 if let Err(error) = commands::enrollment::stage_opened_url(&app_handle, &url) {65 log::warn!("could not import opened invitation: {error}");66 }67 }68 });6970 // The Tauri application is the installed client. Hosting is owned71 // exclusively by the separate, headless `sigil` daemon.72 if let Some(window) = app.get_webview_window("main") {73 let focus_window = window.clone();74 window.on_window_event(move |event| {75 if matches!(event, tauri::WindowEvent::Focused(true))76 && let Err(error) =77 commands::state::reassert_client_cursor_grab(&focus_window)78 {79 log::warn!("could not restore cursor grab after focus changed: {error}");80 }81 });82 let _ = window.show();83 }8485 Ok(())86 })87 .invoke_handler(tauri::generate_handler![88 commands::auth::fido_device_info,89 commands::auth::fido_pin_retries,90 commands::auth::key_derive_identity,91 commands::enrollment::portal_enrollment_status,92 commands::enrollment::portal_import_invitation_file,93 commands::enrollment::portal_confirm_invitation,94 commands::enrollment::portal_cancel_invitation,95 commands::enrollment::portal_reset_enrollment,96 commands::state::development_connection_mode,97 commands::state::set_client_cursor_grab,98 commands::state::set_webcodecs_available,99 commands::state::is_webcodecs_available,100 commands::network::iroh_client_connect,101 commands::network::iroh_client_disconnect,102 commands::network::iroh_client_ack_frame,103 commands::network::iroh_client_request_keyframe,104 commands::network::iroh_client_send_media_feedback,105 commands::network::iroh_client_ack_audio,106 commands::network::iroh_client_stop_audio,107 commands::network::iroh_client_send_input,108 commands::network::iroh_client_request_focus,109 commands::network::iroh_client_release_focus,110 commands::network::iroh_client_approve_focus,111 commands::network::iroh_client_deny_focus,112 commands::network::iroh_client_preempt_focus,113 commands::network::iroh_client_start_focused_input,114 ])115 .build(tauri::generate_context!())116 .expect("error while building Portal application");117 app.run(|app, event| {118 #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]119 if let tauri::RunEvent::Opened { urls } = event {120 for url in urls {121 if let Err(error) = commands::enrollment::stage_opened_url(app, &url) {122 log::warn!("could not import opened invitation file: {error}");123 }124 }125 }126 #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]127 let _ = (app, event);128 });129 commands::state::restore_client_cursor();130}