Skip to content

Commit

Permalink
generate_handler macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Jun 12, 2024
1 parent ebe1383 commit d51d01d
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ use ffmpeg_sidecar::{

use winit::monitor::{MonitorHandle, VideoMode};

macro_rules! generate_handler {
($($command:ident),*) => {{
#[cfg(debug_assertions)]
tauri_specta::ts::export(
specta::collect_types![$($command),*],
"../src/utils/commands.ts"
).unwrap();

tauri::generate_handler![$($command),*]
}}
}

fn main() {
let _ = fix_path_env::fix();
Expand Down Expand Up @@ -152,10 +163,14 @@ fn main() {
}));

let event_loop = winit::event_loop::EventLoop::new().expect("Failed to create event loop");
let monitor: MonitorHandle = event_loop.primary_monitor().expect("No primary monitor found");
let monitor: MonitorHandle = event_loop
.primary_monitor()
.expect("No primary monitor found");
let video_modes: Vec<VideoMode> = monitor.video_modes().collect();

let max_mode = video_modes.iter().max_by_key(|mode| mode.size().width * mode.size().height);
let max_mode = video_modes
.iter()
.max_by_key(|mode| mode.size().width * mode.size().height);

let (max_width, max_height) = if let Some(max_mode) = max_mode {
println!("Maximum resolution: {:?}", max_mode.size());
Expand All @@ -167,18 +182,18 @@ fn main() {

#[derive(serde::Deserialize, PartialEq)]
enum DeviceKind {
#[serde(alias="videoinput")]
#[serde(alias = "videoinput")]
Video,
#[serde(alias="audioinput")]
Audio
#[serde(alias = "audioinput")]
Audio,
}

#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct MediaDevice {
id: String,
kind: DeviceKind,
label: String
label: String,
}

fn create_tray_menu(submenus: Option<Vec<SystemTraySubmenu>>) -> SystemTrayMenu {
Expand All @@ -196,22 +211,10 @@ fn main() {
.add_item(CustomMenuItem::new("quit".to_string(), "Quit").accelerator("CmdOrControl+Q"))
}

let tray = SystemTray::new().with_menu(create_tray_menu(None)).with_menu_on_left_click(false).with_title("Cap");

#[cfg(debug_assertions)]
tauri_specta::ts::export(specta::collect_types![
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,
], "../src/utils/commands.ts").unwrap();
let tray = SystemTray::new()
.with_menu(create_tray_menu(None))
.with_menu_on_left_click(false)
.with_title("Cap");

tauri::Builder::default()
.plugin(tauri_plugin_oauth::init())
Expand Down Expand Up @@ -322,7 +325,7 @@ fn main() {

Ok(())
})
.invoke_handler(tauri::generate_handler![
.invoke_handler(generate_handler![
start_dual_recording,
stop_all_recordings,
enumerate_audio_devices,
Expand All @@ -333,7 +336,7 @@ fn main() {
has_screen_capture_access,
reset_screen_permissions,
reset_microphone_permissions,
reset_camera_permissions,
reset_camera_permissions
])
.plugin(tauri_plugin_context_menu::init())
.system_tray(tray)
Expand Down

0 comments on commit d51d01d

Please sign in to comment.