Skip to content

Commit

Permalink
Revert "release: 0.2.0"
Browse files Browse the repository at this point in the history
This reverts commit 711849d, reversing
changes made to 80dd343.
  • Loading branch information
richiemcilroy committed Apr 16, 2024
1 parent 711849d commit d576147
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 353 deletions.
4 changes: 0 additions & 4 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"name": "desktop",
"private": true,
<<<<<<< HEAD
"version": "0.1.9",
=======
"version": "0.2.0",
>>>>>>> main
"scripts": {
"dev": "tauri dev",
"build": "tsc && next build",
Expand Down
13 changes: 1 addition & 12 deletions apps/desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tauri-build = { version = "1.5.1", features = [] }
ffmpeg-sidecar = "0.5.1"

[dependencies]
tauri = { version = "1.6.1", features = [ "system-tray", "updater", "macos-private-api", "window-set-position", "fs-write-file", "fs-remove-file", "fs-read-file", "fs-rename-file", "fs-exists", "fs-remove-dir", "fs-read-dir", "fs-copy-file", "fs-create-dir", "window-set-ignore-cursor-events", "window-unminimize", "window-minimize", "window-close", "window-show", "window-start-dragging", "window-hide", "window-unmaximize", "window-maximize", "window-set-always-on-top", "shell-open", "devtools", "os-all", "http-all", "icon-png"] }
tauri = { version = "1.6.1", features = [ "updater", "macos-private-api", "window-set-position", "fs-write-file", "fs-remove-file", "fs-read-file", "fs-rename-file", "fs-exists", "fs-remove-dir", "fs-read-dir", "fs-copy-file", "fs-create-dir", "window-set-ignore-cursor-events", "window-unminimize", "window-minimize", "window-close", "window-show", "window-start-dragging", "window-hide", "window-unmaximize", "window-maximize", "window-set-always-on-top", "shell-open", "devtools", "os-all", "http-all"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-plugin-context-menu = "0.7.0"
Expand Down
Binary file removed apps/desktop/src-tauri/icons/tray-default-icon.png
Binary file not shown.
Binary file removed apps/desktop/src-tauri/icons/tray-stop-icon.png
Binary file not shown.
143 changes: 3 additions & 140 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::collections::LinkedList;
use std::sync::{Arc};
use std::path::PathBuf;
use cpal::Devices;
use regex::Regex;
use tokio::sync::Mutex;
use std::sync::atomic::{AtomicBool};
use std::{vec};
use tauri::{command, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTraySubmenu, Window};
use std::env;
use tauri::{command, Manager, Window};
use window_vibrancy::{apply_blur, apply_vibrancy, NSVisualEffectMaterial};
use window_shadows::set_shadow;
use tauri_plugin_positioner::{WindowExt, Position};
Expand Down Expand Up @@ -159,39 +156,6 @@ fn main() {
(0, 0)
};

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

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

fn create_tray_menu(submenus: Option<Vec<SystemTraySubmenu>>) -> SystemTrayMenu {
let mut tray_menu = SystemTrayMenu::new();

if let Some(items) = submenus {
for submenu in items {
tray_menu = tray_menu.add_submenu(submenu);
}
tray_menu = tray_menu.add_native_item(tauri::SystemTrayMenuItem::Separator);
}

tray_menu
.add_item(CustomMenuItem::new("show-window".to_string(), "Show Cap"))
.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");

tauri::Builder::default()
.plugin(tauri_plugin_oauth::init())
.plugin(tauri_plugin_positioner::init())
Expand Down Expand Up @@ -224,67 +188,6 @@ fn main() {

app.manage(Arc::new(Mutex::new(recording_state)));

let tray_handle = app.tray_handle();
app.listen_global("toggle-recording", move|event| {
let is_recording: bool = serde_json::from_str(event.payload().expect("Error while openning event payload")).expect("Error while deserializing recording state from event payload");

let icon_bytes = if is_recording {
include_bytes!("../icons/tray-stop-icon.png").to_vec()
} else {
include_bytes!("../icons/tray-default-icon.png").to_vec()
};

tray_handle.set_icon(tauri::Icon::Raw(icon_bytes)).expect("Error while setting tray icon");
});

let tray_handle = app.tray_handle();
app.listen_global("media-devices-set", move|event| {
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct Payload {
media_devices: Vec<MediaDevice>,
selected_video: Option<MediaDevice>,
selected_audio: Option<MediaDevice>
}
let payload: Payload = serde_json::from_str(event.payload().expect("Error wile openning event payload")).expect("Error while deserializing media devices from event payload");

fn create_submenu_items(devices: &Vec<MediaDevice>, selected_device: &Option<MediaDevice>, kind: DeviceKind) -> SystemTrayMenu {
let id_prefix = if kind == DeviceKind::Video {
"video"
} else {
"audio"
};
let mut none_item = CustomMenuItem::new(format!("in_{}_none", id_prefix), "None");
if selected_device.is_none() {
none_item = none_item.selected();
}
let initial = SystemTrayMenu::new().add_item(none_item);
devices
.iter()
.filter(|device| device.kind == kind)
.fold(initial, |tray_items, device| {
let mut menu_item = CustomMenuItem::new(format!("in_{}_{}", id_prefix, device.id), &device.label);

if let Some(selected) = selected_device {
if selected.label == device.label {
menu_item = menu_item.selected();
}
}

tray_items.add_item(menu_item)
})
}

let new_menu = create_tray_menu(Some(
vec![
SystemTraySubmenu::new("Camera", create_submenu_items(&payload.media_devices, &payload.selected_video, DeviceKind::Video)),
SystemTraySubmenu::new("Microphone", create_submenu_items(&payload.media_devices, &payload.selected_audio, DeviceKind::Audio))
]
));

tray_handle.set_menu(new_menu).expect("Error while updating the tray menu items");
});

Ok(())
})
.invoke_handler(tauri::generate_handler![
Expand All @@ -302,46 +205,6 @@ fn main() {
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");
window.set_focus().expect("Error while trying to set focus on 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" };

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");
},
_ => {}
})
.run(tauri::generate_context!())
.expect("Error while running tauri application");
}
}
10 changes: 1 addition & 9 deletions apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
},
"package": {
"productName": "Cap",
<<<<<<< HEAD
"version": "0.1.9"
=======
"version": "0.2.0"
>>>>>>> main
},
"tauri": {
"allowlist": {
Expand Down Expand Up @@ -103,10 +99,6 @@
"alwaysOnTop": false,
"center": true
}
],
"systemTray": {
"iconPath": "icons/tray-default-icon.png",
"iconAsTemplate": true
}
]
}
}
2 changes: 1 addition & 1 deletion apps/desktop/src/components/windows/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Camera = () => {
const video = videoRef.current;
const constraints = {
video: {
deviceId: selectedVideoDevice.id,
deviceId: selectedVideoDevice.deviceId,
},
};

Expand Down

0 comments on commit d576147

Please sign in to comment.