From d576147444a1032d7b8990fd07e128f4cae502c0 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:49:02 +0100 Subject: [PATCH] Revert "release: 0.2.0" This reverts commit 711849d03294e1a064c6054cd06ba35357fdd69e, reversing changes made to 80dd34392276f6a9824a75543e85090516ecd2b8. --- apps/desktop/package.json | 4 - apps/desktop/src-tauri/Cargo.lock | 13 +- apps/desktop/src-tauri/Cargo.toml | 2 +- .../src-tauri/icons/tray-default-icon.png | Bin 1843 -> 0 bytes .../src-tauri/icons/tray-stop-icon.png | Bin 555 -> 0 bytes apps/desktop/src-tauri/src/main.rs | 143 +----------------- apps/desktop/src-tauri/tauri.conf.json | 10 +- .../desktop/src/components/windows/Camera.tsx | 2 +- .../src/components/windows/inner/Recorder.tsx | 125 ++++++--------- .../utils/recording/MediaDeviceContext.tsx | 133 +++++++--------- apps/desktop/src/utils/recording/utils.ts | 6 +- apps/web/app/api/playlist/route.ts | 2 - apps/web/app/api/status/route.ts | 7 - apps/web/next.config.mjs | 12 -- apps/web/package.json | 4 - 15 files changed, 110 insertions(+), 353 deletions(-) delete mode 100644 apps/desktop/src-tauri/icons/tray-default-icon.png delete mode 100644 apps/desktop/src-tauri/icons/tray-stop-icon.png delete mode 100644 apps/web/app/api/status/route.ts diff --git a/apps/desktop/package.json b/apps/desktop/package.json index 91ab2b0..f91f5f8 100644 --- a/apps/desktop/package.json +++ b/apps/desktop/package.json @@ -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", diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock index 759d8f0..cfef6e0 100644 --- a/apps/desktop/src-tauri/Cargo.lock +++ b/apps/desktop/src-tauri/Cargo.lock @@ -2320,15 +2320,6 @@ dependencies = [ "serde", ] -[[package]] -name = "infer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f178e61cdbfe084aa75a2f4f7a25a5bb09701a47ae1753608f194b15783c937a" -dependencies = [ - "cfb", -] - [[package]] name = "infer" version = "0.13.0" @@ -4747,7 +4738,6 @@ dependencies = [ "http", "ignore", "indexmap 1.9.3", - "infer 0.9.0", "minisign-verify", "nix 0.26.4", "notify-rust", @@ -4757,7 +4747,6 @@ dependencies = [ "os_info", "os_pipe", "percent-encoding", - "png", "rand 0.8.5", "raw-window-handle 0.5.2", "regex", @@ -4961,7 +4950,7 @@ dependencies = [ "glob", "heck 0.4.1", "html5ever", - "infer 0.13.0", + "infer", "json-patch", "kuchikiki", "log", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index a495a64..523243a 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -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" diff --git a/apps/desktop/src-tauri/icons/tray-default-icon.png b/apps/desktop/src-tauri/icons/tray-default-icon.png deleted file mode 100644 index 4823afb235fed4cf825c3a0f076313b04c649717..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1843 zcmV-32h8}1P)L9xl9ncF5bH01d8HCG_TlVEzviamS0!5PmB}*iR+G-PhYYsv#oklYqU0ChH#k&ei3vObA z2D}Xr7ZN}{BGlSe|MX;I+5y1y#fZja7+gX4?pMgXMNGp{f^Osh?cJrZ47*!2m!Q(@73y|1N z(zy{`39a=K*0v)oYX(S4_*Ai;I4}sX=L|t+R0Ammj;5DW+P~+-4`=jE31H67?7WEN zt8BPUxDKppcVKM?fKxSF&I9@HS%BwGE6||=*XSPhTGyd_8wNiSz_MM3Qy-K&4j9K- zD%tq=7Q1}vODy{w|7V$S`;C;Rk(43AdIDU-Wc((N&I=bG9wzvEPXszrfRR2>kLIiI zZEDF~0wA3x@#i_ik85=9x5n3f)`jIW#d)NJ=Nt(?3vy!Trkf^@XE%{7_QGA7%p(NU zR+&FCWZ>!J3?hsmVdzi&KWg5534pne4t%9(oIRLu#T^|9xU>Cyum$4&q$hvy{rPwb zs*oK=Xf6ujB9=^$YKTvvGMcgtZTmGS_`=57h`2Ag3AAKnx(25M$)C?nit9u99et2P$Mt zxlBZ|9x%;E&h@1nWlSR%P>+}-mJrtcR+7TJ4_8UJOq^8XdbySXvMmPTh6BoV5Xsnb z#)x8~2sO58s+>O^36ypD*fVo0wqaFe71##qo zrYukNTA10s?@$pFV5K4H{0g`Y&8FsoJ*mv5vy1`6oAiU$7SutVsaY zGYBsUQzK!&2O&@{4`lyy(vg6B7tQqUIrQ*?+{agcqP7)}9dvtpz28JeJwPZOdksQv zRw0=L?Xoj@P+VE~$0r1>Kw5)AFqZgDd`0vPx$8A9#qt!~mLsEnqG-QDA%zSOh*p{yX*oEut1CT7PmEj>UlM>Zq za{x@M{|DVlxB#-|_p0ohz;d0zt=k5$WPZqU^lDAG0J}q>|)%ho^x$X1i= z<&!n>W;Ahv2mM>)zR6n-p2n8K=vibF2d~F zPy`ZdL`C{QNXWrPBmgO`SnTR;$I(`t{V;N?@aM;|0A#VmCUxwtd~*?k@Z?` tA+kP9^iiDcY393uWqF(?UImMr{QwuPp&=J=7ZLyf002ovPDHLkV1k|r^}hfB diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 91bb5c6..cd45597 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -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}; @@ -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>) -> 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()) @@ -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, - selected_video: Option, - selected_audio: Option - } - 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, selected_device: &Option, 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![ @@ -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 - } - - 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"); -} +} \ No newline at end of file diff --git a/apps/desktop/src-tauri/tauri.conf.json b/apps/desktop/src-tauri/tauri.conf.json index f286655..d6a5970 100644 --- a/apps/desktop/src-tauri/tauri.conf.json +++ b/apps/desktop/src-tauri/tauri.conf.json @@ -8,11 +8,7 @@ }, "package": { "productName": "Cap", -<<<<<<< HEAD "version": "0.1.9" -======= - "version": "0.2.0" ->>>>>>> main }, "tauri": { "allowlist": { @@ -103,10 +99,6 @@ "alwaysOnTop": false, "center": true } - ], - "systemTray": { - "iconPath": "icons/tray-default-icon.png", - "iconAsTemplate": true - } + ] } } diff --git a/apps/desktop/src/components/windows/Camera.tsx b/apps/desktop/src/components/windows/Camera.tsx index a0de0e2..833d1d2 100644 --- a/apps/desktop/src/components/windows/Camera.tsx +++ b/apps/desktop/src/components/windows/Camera.tsx @@ -15,7 +15,7 @@ export const Camera = () => { const video = videoRef.current; const constraints = { video: { - deviceId: selectedVideoDevice.id, + deviceId: selectedVideoDevice.deviceId, }, }; diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsx index cb34f1c..bf0c494 100644 --- a/apps/desktop/src/components/windows/inner/Recorder.tsx +++ b/apps/desktop/src/components/windows/inner/Recorder.tsx @@ -1,7 +1,7 @@ "use client"; import { useState, useEffect } from "react"; -import { Device, useMediaDevices } from "@/utils/recording/MediaDeviceContext"; +import { useMediaDevices } from "@/utils/recording/MediaDeviceContext"; import { Video } from "@/components/icons/Video"; import { Microphone } from "@/components/icons/Microphone"; import { Screen } from "@/components/icons/Screen"; @@ -9,7 +9,7 @@ import { Window } from "@/components/icons/Window"; import { ActionButton } from "@/components/recording/ActionButton"; import { Button } from "@cap/ui"; import { Logo } from "@/components/icons/Logo"; -import { emit, listen, UnlistenFn } from "@tauri-apps/api/event"; +import { emit } from "@tauri-apps/api/event"; import { invoke } from "@tauri-apps/api/tauri"; import { getLatestVideoId, saveLatestVideoId } from "@/utils/database/utils"; import { openLinkInBrowser } from "@/utils/helpers"; @@ -17,7 +17,6 @@ import toast, { Toaster } from "react-hot-toast"; import { authFetch } from "@/utils/auth/helpers"; import { appDataDir, join } from "@tauri-apps/api/path"; import { open } from "@tauri-apps/api/shell"; -import * as Tauri from "@tauri-apps/api"; declare global { interface Window { @@ -43,49 +42,52 @@ export const Recorder = () => { const [canStopRecording, setCanStopRecording] = useState(false); const [hasStartedRecording, setHasStartedRecording] = useState(false); - const handleContextClick = async (option: "video" | "audio") => { + const handleContextClick = async (option: string) => { const { showMenu } = await import("tauri-plugin-context-menu"); - const deviceKind = option === "video" ? "videoinput" : "audioinput"; - const isSelected = (device: Device | null) => { - if (device === null) { - return deviceKind === "videoinput" - ? selectedVideoDevice === null - : selectedAudioDevice === null; - } - - return deviceKind === "videoinput" - ? device.index === selectedVideoDevice?.index - : device.index === selectedAudioDevice?.index; - } - const select = async (device: Device | null) => { - // if (isSelected(device)) { - // return - // } - emit("change-device", { type: deviceKind, device: device }).catch((error) => { - console.log("Failed to emit change-device event:", error); - }); - } - - const devicesOfKind = devices.filter((device) => device.kind === deviceKind); - const menuItems = [ - { - label: "None", - checked: isSelected(null), - event: async() => select(null) - }, - ...devicesOfKind.map((device) => ( - { - label: device.label, - checked: isSelected(device), - event: async() => select(device) + const filteredDevices = devices + .filter((device) => + option === "video" + ? device.kind === "videoinput" + : device.kind === "audioinput" + ) + .map((device) => ({ + label: device.label, + disabled: + option === "video" + ? device.index === selectedVideoDevice?.index + : device.index === selectedAudioDevice?.index, + event: async () => { + try { + await emit("change-device", { type: option, device }); + } catch (error) { + console.error("Failed to emit change-device event:", error); + } + }, + })); + + filteredDevices.push({ + label: "None", + disabled: false, + event: async () => { + try { + await emit("change-device", { + type: option, + device: { + label: "None", + index: -1, + kind: option === "video" ? "videoinput" : "audioinput", + }, + }); + } catch (error) { + console.error("Failed to emit change-device event:", error); } - )) - ] - + }, + }); + await showMenu({ - items: [...menuItems], - ...(devicesOfKind.length === 0 && { + items: [...filteredDevices], + ...(filteredDevices.length === 0 && { items: [ { label: "Nothing found.", @@ -135,32 +137,6 @@ export const Recorder = () => { return data; }; - useEffect(() => { - let unlistenFn: UnlistenFn | null = null; - - const setupListener = async () => { - unlistenFn = await listen("tray-on-left-click", (_) => { - if (isRecording) { - handleStopAllRecordings(); - } - - const currentWindow = Tauri.window.getCurrent(); - if (!currentWindow.isVisible) { - currentWindow.show(); - } - currentWindow.setFocus(); - }); - }; - - setupListener(); - - return () => { - if (unlistenFn) { - unlistenFn(); - } - }; - }, [isRecording, canStopRecording]); - const startDualRecording = async (videoData: { id: string; user_id: string; @@ -178,13 +154,6 @@ export const Recorder = () => { if (window.fathom !== undefined) { window.fathom.trackEvent("start_recording"); } - Tauri.window.getAll().forEach((window) => { - if (window.label !== "camera") { - window.hide(); - } - }); - - emit("toggle-recording", true); await invoke("start_dual_recording", { options: { user_id: videoData.user_id, @@ -260,8 +229,6 @@ export const Recorder = () => { setIsRecording(false); setHasStartedRecording(false); setStoppingRecording(false); - setCanStopRecording(false); - emit("toggle-recording", false); } catch (error) { console.error("Error stopping recording:", error); } @@ -376,7 +343,7 @@ export const Recorder = () => { width="full" handler={() => handleContextClick("video")} icon={