Skip to content

Commit

Permalink
Merge branch 'main' into feat/improve-editor-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
clearlysid authored May 3, 2024
2 parents 206257e + b5fde42 commit 19d935e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
22 changes: 6 additions & 16 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,24 @@ use tauri::{AppHandle, Manager, WebviewUrl, WebviewWindowBuilder};
use tauri_plugin_global_shortcut;
use tauri_plugin_store::StoreBuilder;
use tokio::sync::Mutex;
use tauri_plugin_global_shortcut::ShortcutState;

#[cfg(target_os = "macos")]
use tauri::ActivationPolicy;

#[derive(Debug, PartialEq)]
pub enum Status {
Idle,
Cropper,
Recording,
Editing,
}

pub struct AppState {
cropped_area: Mutex<Vec<u32>>,
status: Mutex<Status>,
frames: Mutex<Vec<Frame>>,
recorder: Mutex<Option<Capturer>>,
cropped_area: Mutex<Vec<u32>>,
preview_path: Mutex<Option<PathBuf>>,
}

impl Default for AppState {
fn default() -> Self {
Self {
cropped_area: Mutex::new(Vec::new()),
status: Mutex::new(Status::Idle),
frames: Mutex::new(Vec::new()),
recorder: Mutex::new(None),
cropped_area: Mutex::new(Vec::new()),
preview_path: Mutex::new(None),
}
}
Expand All @@ -59,11 +50,10 @@ fn initialize_micro(app_handle: &AppHandle) {
tauri_plugin_global_shortcut::Builder::new()
.with_shortcut(SHORTCUT)
.expect("Failed to register global shortcut")
.with_handler(|app, _, event| match event.state {
tauri_plugin_global_shortcut::ShortcutState::Pressed => {
crate::cropper::toggle_cropper(app);
.with_handler(|app, _, event| {
if event.state == ShortcutState::Pressed {
cropper::toggle_cropper(app);
}
_ => {}
})
.build(),
)
Expand Down
7 changes: 1 addition & 6 deletions src-tauri/src/recorder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{sync::mpsc, thread};

use crate::{open_onboarding, AppState, Status};
use crate::{open_onboarding, AppState};

use tauri::{AppHandle, Manager};
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -146,11 +146,6 @@ pub async fn stop_recording(app_handle: AppHandle) {
(*recorder).as_mut().unwrap().stop_capture();
recorder.take();
drop(recorder);

// Update app state to editing
let mut status = state.status.lock().await;
*status = Status::Editing;
drop(status);
}

#[tauri::command]
Expand Down
6 changes: 1 addition & 5 deletions src-tauri/src/recorder/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AppState, Status};
use crate::AppState;
use rand::Rng;
use scap::{
capturer::{CGPoint, CGRect, CGSize, Capturer, Options, Resolution},
Expand All @@ -11,10 +11,6 @@ pub const FRAME_TYPE: FrameType = FrameType::BGRAFrame;
pub async fn start_frame_capture(app_handle: AppHandle) {
let state = app_handle.state::<AppState>();

let mut status = state.status.lock().await;
*status = Status::Recording;
drop(status);

// area is of the form [x1, y1, x2, y2]
// we need it of the form [x1, y1, x2-x1, y2-y1]
let area = state.cropped_area.lock().await.clone();
Expand Down
15 changes: 15 additions & 0 deletions src/pages/cropper.astro
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ import Base from "../components/base.astro";

selectableAreaEl!.addEventListener("mouseup", () => {
if (isSelecting) {
// Since our recorder expects coordinates in the
// [topX, topY, bottomX, bottomY] format, we interchange
// start and end values if required
if (startX > endX) {
const temp = startX;
startX = endX;
endX = temp;
}

if (startY > endY) {
const temp = startY;
startY = endY;
endY = temp;
}

const buttonX = startX > endX ? endX - 24 : endX;
const buttonY = startY > endY ? endY - 24 : endY;

Expand Down

0 comments on commit 19d935e

Please sign in to comment.