Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

update branch with CapSoftware/cap main

PJa343b82ea02e
diff --cc .github/workflows/main.yml
index 2c6002e04,6659a1b14..74160d06b
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@@ -44,13 -44,15 +44,16 @@@ jobs
id: get_version
run: echo "appVersion=$(jq -r '.version' apps/desktop/package.json)" >> $GITHUB_OUTPUT
- - name: Create .env file
+ - name: Create .env file in root
run: |
- echo "NEXT_PUBLIC_URL=${{ secrets.NEXT_PUBLIC_URL }}" > apps/desktop/.env
- echo "appVersion=${{ steps.get_version.outputs.appVersion }}" >> apps/desktop/.env
- echo "NEXT_PUBLIC_ENVIRONMENT=production" >> apps/desktop/.env
- echo "NEXT_PUBLIC_LOCAL_MODE=false" >> apps/desktop/.env
- echo "CAP_DESKTOP_SENTRY_URL=https://efd3156d9c0a8a49bee3ee675bec80d8@o4506859771527168.ingest.us.sentry.io/4506859844403200" >> apps/desktop/.env
+ echo "NEXT_PUBLIC_URL=${{ secrets.NEXT_PUBLIC_URL }}" > .env
+ echo "appVersion=${{ steps.get_version.outputs.appVersion }}" >> .env
+ echo "NEXT_PUBLIC_ENVIRONMENT=production" >> .env
+ echo "NEXT_PUBLIC_LOCAL_MODE=false" >> .env
++ echo "CAP_DESKTOP_SENTRY_URL=https://efd3156d9c0a8a49bee3ee675bec80d8@o4506859771527168.ingest.us.sentry.io/4506859844403200" >> .env
+
+ - name: Copy .env to apps/desktop
+ run: cp .env apps/desktop/.env
- name: Output .env file
run: cat apps/desktop/.env
diff --cc apps/desktop/src-tauri/src/main.rs
index 47f2fe747,a53d06a07..5b8f710ed
--- a/apps/desktop/src-tauri/src/main.rs
+++ b/apps/desktop/src-tauri/src/main.rs
@@@ -31,16 -33,16 +31,16 @@@ use utils::has_screen_capture_access
use ffmpeg_sidecar::{
command::ffmpeg_is_installed,
- download::{ check_latest_version, download_ffmpeg_package, ffmpeg_download_url, unpack_ffmpeg },
+ download::{check_latest_version, download_ffmpeg_package, ffmpeg_download_url, unpack_ffmpeg},
- error::Result as FfmpegResult,
paths::sidecar_dir,
version::ffmpeg_version,
};
-use winit::monitor::{ MonitorHandle, VideoMode };
+use winit::monitor::{MonitorHandle, VideoMode};
macro_rules! generate_handler {
- ($($command:ident),*) => {{
+ ($($command:ident),*) => {
+ {
#[cfg(debug_assertions)]
tauri_specta::ts::export(
specta::collect_types![$($command),*],
@@@ -54,70 -57,43 +55,75 @@@
fn main() {
let _ = fix_path_env::fix();
- std::panic::set_hook(
- Box::new(|info| {
- eprintln!("Thread panicked: {:?}", info);
- })
- );
+ let context = tauri::generate_context!();
+ let rolling_log = app::get_log_file(&context);
+ let (log_writer, _log_guard) = tracing_appender::non_blocking(rolling_log);
+
+ let sentry_guard = sentry::init(sentry::ClientOptions {
+ dsn: app::config::sentry_dsn(),
+ release: sentry::release_name!(),
+ ..Default::default()
+ });
+ let maybe_sentry_subscriber =
+ sentry_guard
+ .is_enabled()
+ .then_some(
+ sentry_tracing::layer().event_filter(|metadata| match metadata.level() {
+ &Level::WARN => EventFilter::Event,
+ _ => EventFilter::Ignore,
+ }),
+ );
+
+ tracing_subscriber::registry()
+ .with(
+ tracing_subscriber::fmt::layer()
+ .with_writer(std::io::stdout.with_max_level(app::config::logging_level()))
+ .pretty(),
+ )
+ .with(
+ tracing_subscriber::fmt::layer()
+ .with_writer(log_writer.with_max_level(Level::DEBUG))
+ .with_ansi(false),
+ )
+ .with(maybe_sentry_subscriber)
+ .init();
+
+ std::panic::set_hook(Box::new(app::panic_hook));
- fn handle_ffmpeg_installation() -> FfmpegResult<()> {
+ fn handle_ffmpeg_installation() -> Result<(), String> {
if ffmpeg_is_installed() {
- println!("FFmpeg is already installed! πŸŽ‰");
+ tracing::info!("FFmpeg is already installed! πŸŽ‰");
return Ok(());
}
+ tracing::info!("FFmpeg not found. Attempting to install...");
match check_latest_version() {
- Ok(version) => println!("Latest available version: {}", version),
- Err(e) => println!("Skipping version check due to error: {}", e.to_string()),
+ Ok(version) => tracing::debug!("Latest available version: {}", version),
- Err(_) => tracing::debug!("Skipping version check on this platform."),
++ Err(e) => tracing::debug!("Skipping version check due to error: {e}"),
}
- let download_url = ffmpeg_download_url()?;
- let destination = sidecar_dir()?;
+ let download_url = ffmpeg_download_url().map_err(|e| e.to_string())?;
+ let destination = sidecar_dir().map_err(|e| e.to_string())?;
- println!("Downloading from: {:?}", download_url);
- let archive_path = download_ffmpeg_package(download_url, &destination).map_err(|e|
- e.to_string()
- )?;
- println!("Downloaded package: {:?}", archive_path);
+ tracing::debug!("Downloading from: {:?}", download_url);
- let archive_path = download_ffmpeg_package(download_url, &destination)?;
++ let archive_path =
++ download_ffmpeg_package(download_url, &destination).map_err(|e| e.to_string())?;
+ tracing::debug!("Downloaded package: {:?}", archive_path);
- println!("Extracting...");
+ tracing::debug!("Extracting...");
- unpack_ffmpeg(&archive_path, &destination)?;
+ unpack_ffmpeg(&archive_path, &destination).map_err(|e| e.to_string())?;
- let version = ffmpeg_version()?;
+ let version = ffmpeg_version().map_err(|e| e.to_string())?;
- println!("FFmpeg version: {}", version);
- println!("Done! 🏁");
+ tracing::info!("Done! Installed FFmpeg version {} 🏁", version);
Ok(())
}
-- handle_ffmpeg_installation().expect("Failed to install FFmpeg");
++ if let Err(error) = handle_ffmpeg_installation() {
++ tracing::error!(error);
++ // TODO: UI message instead
++ panic!("Failed to install FFmpeg, which is required for Cap to function. Shutting down now")
++ };
#[tauri::command]
#[specta::specta]
@@@ -360,65 -377,88 +401,88 @@@
Ok(())
})
- .invoke_handler(generate_handler![
- start_dual_recording,
- stop_all_recordings,
- enumerate_audio_devices,
- start_server,
- open_screen_capture_preferences,
- open_mic_preferences,
- open_camera_preferences,
- has_screen_capture_access,
- reset_screen_permissions,
- reset_microphone_permissions,
- reset_camera_permissions
- ])
+ .invoke_handler(
+ generate_handler![
+ start_dual_recording,
+ stop_all_recordings,
+ enumerate_audio_devices,
+ start_server,
+ open_screen_capture_preferences,
+ open_mic_preferences,
+ open_camera_preferences,
+ has_screen_capture_access,
+ reset_screen_permissions,
+ reset_microphone_permissions,
+ reset_camera_permissions
+ ]
+ )
.plugin(tauri_plugin_context_menu::init())
.system_tray(tray)
- .on_system_tray_event(move |app, event| match event {
- SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
- "show-window" => {
- let window = app.get_window("main").expect("Error while trying to get the main window.");
- window.show().expect("Error while trying to show main window");
- if !window.is_focused().unwrap_or(false) {
- window.set_focus().expect("Error while trying to set focus on main window");
- }
- if(window.is_minimized().unwrap_or(false)) {
- window.unminimize().expect("Error while trying to unminimize main window");
- }
- }
- "quit" => {
- app.exit(0);
- }
- item_id => {
- if !item_id.starts_with("in") {
- return;
- }
- let pattern = Regex::new(r"^in_(video|audio)_").expect("Failed to create regex for checking tray item events");
-
- if pattern.is_match(item_id) {
- #[derive(Clone, serde::Serialize)]
- struct SetDevicePayload {
- #[serde(rename(serialize="type"))]
- device_type: String,
- id: Option<String>
+ .on_system_tray_event(move |app, event| {
+ match event {
+ SystemTrayEvent::MenuItemClick { id, .. } =>
+ match id.as_str() {
+ "show-window" => {
+ let window = app
+ .get_window("main")
+ .expect("Error while trying to get the main window.");
+ window.show().expect("Error while trying to show main window");
+ if !window.is_focused().unwrap_or(false) {
+ window
+ .set_focus()
+ .expect("Error while trying to set focus on main window");
+ }
+ if window.is_minimized().unwrap_or(false) {
+ window
+ .unminimize()
+ .expect("Error while trying to unminimize main window");
+ }
+ }
+ "quit" => {
+ app.exit(0);
}
+ item_id => {
+ if !item_id.starts_with("in") {
+ return;
+ }
+ let pattern = Regex::new(r"^in_(video|audio)_").expect(
+ "Failed to create regex for checking tray item events"
+ );
+
+ if pattern.is_match(item_id) {
+ #[derive(Clone, serde::Serialize)]
+ struct SetDevicePayload {
+ #[serde(rename(serialize = "type"))]
+ device_type: String,
+ id: Option<String>,
+ }
- let device_id = pattern.replace_all(item_id, "").into_owned();
- let kind = if item_id.contains("video") { "videoinput" } else { "audioinput" };
+ let device_id = pattern.replace_all(item_id, "").into_owned();
+ let kind = if item_id.contains("video") {
+ "videoinput"
+ } else {
+ "audioinput"
+ };
- app.emit_all("tray-set-device-id", SetDevicePayload {
- device_type: kind.to_string(),
- id: if device_id == "none" { None } else { Some(device_id) }
- }).expect("Failed to emit tray set media device event to windows");
+ app.emit_all("tray-set-device-id", SetDevicePayload {
+ device_type: kind.to_string(),
+ id: if device_id == "none" {
+ None
+ } else {
+ Some(device_id)
+ },
+ }).expect("Failed to emit tray set media device event to windows");
+ }
+ }
}
+ SystemTrayEvent::LeftClick { position: _, size: _, .. } => {
+ app.emit_all("tray-on-left-click", Some(())).expect(
+ "Failed to emit tray left click event to windows"
+ );
}
- },
- SystemTrayEvent::LeftClick { position: _, size: _, .. } => {
- app.emit_all("tray-on-left-click", Some(())).expect("Failed to emit tray left click event to windows");
- },
- _ => {}
+ _ => {}
+ }
})
- .run(tauri::generate_context!())
+ .run(context)
.expect("Error while running tauri application");
}