Skip to content

Commit 313d7f1

Browse files
absolute mess
1 parent ea2bd20 commit 313d7f1

File tree

5 files changed

+58
-23
lines changed

5 files changed

+58
-23
lines changed

apps/desktop/src-tauri/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ async fn get_video_metadata(path: PathBuf) -> Result<VideoRecordingMetadata, Str
910910
.map(|s| recording_meta.path(&s.display.path))
911911
.collect(),
912912
},
913+
RecordingMetaInner::InProgress { .. } => todo!(),
913914
};
914915

915916
let duration = display_paths
@@ -1389,19 +1390,31 @@ async fn save_file_dialog(
13891390
}
13901391
}
13911392

1393+
// #[derive(Serialize, specta::Type)]
1394+
// #[serde(tag = "status")]
1395+
// pub enum RecordingStatus {
1396+
// Recording,
1397+
// Failed { error: String },
1398+
// Complete { mode: RecordingMode },
1399+
// }
1400+
//
1401+
// #[serde(flatten)]
1402+
// pub status: RecordingStatus,
1403+
13921404
#[derive(Serialize, specta::Type)]
13931405
pub struct RecordingMetaWithMode {
13941406
#[serde(flatten)]
13951407
pub inner: RecordingMeta,
1396-
pub mode: RecordingMode,
1408+
pub mode: Option<RecordingMode>,
13971409
}
13981410

13991411
impl RecordingMetaWithMode {
14001412
fn new(inner: RecordingMeta) -> Self {
14011413
Self {
14021414
mode: match &inner.inner {
1403-
RecordingMetaInner::Studio(_) => RecordingMode::Studio,
1404-
RecordingMetaInner::Instant(_) => RecordingMode::Instant,
1415+
RecordingMetaInner::Studio(_) => Some(RecordingMode::Studio),
1416+
RecordingMetaInner::Instant(_) => Some(RecordingMode::Instant),
1417+
RecordingMetaInner::InProgress { .. } => None,
14051418
},
14061419
inner,
14071420
}
@@ -2489,6 +2502,7 @@ fn open_project_from_path(path: &Path, app: AppHandle) -> Result<(), String> {
24892502
}
24902503
}
24912504
}
2505+
RecordingMetaInner::InProgress { recording } => todo!(),
24922506
}
24932507

24942508
Ok(())

apps/desktop/src-tauri/src/recording.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ pub async fn start_recording(
285285
RecordingMode::Studio => None,
286286
};
287287

288+
let date_time = if cfg!(windows) {
289+
// Windows doesn't support colon in file paths
290+
chrono::Local::now().format("%Y-%m-%d %H.%M.%S")
291+
} else {
292+
chrono::Local::now().format("%Y-%m-%d %H:%M:%S")
293+
};
294+
295+
let meta = RecordingMeta {
296+
platform: Some(Platform::default()),
297+
project_path: recording_dir.clone(),
298+
sharing: None, // TODO: Is this gonna be problematic as it was previously always set
299+
pretty_name: format!("{target_name} {date_time}"),
300+
inner: RecordingMetaInner::InProgress { recording: true },
301+
};
302+
303+
meta.save_for_project()
304+
.map_err(|e| format!("Failed to save recording meta: {e}"))?;
305+
288306
match &inputs.capture_target {
289307
ScreenCaptureTarget::Window { id: _id } => {
290308
if let Some(show) = inputs
@@ -843,21 +861,9 @@ async fn handle_recording_finish(
843861
}
844862
};
845863

846-
let date_time = if cfg!(windows) {
847-
// Windows doesn't support colon in file paths
848-
chrono::Local::now().format("%Y-%m-%d %H.%M.%S")
849-
} else {
850-
chrono::Local::now().format("%Y-%m-%d %H:%M:%S")
851-
};
852-
853-
let meta = RecordingMeta {
854-
platform: Some(Platform::default()),
855-
project_path: recording_dir.clone(),
856-
sharing,
857-
pretty_name: format!("{target_name} {date_time}"),
858-
inner: meta_inner,
859-
};
860-
864+
// TODO: Can we avoid reloading it from disk by parsing as arg?
865+
let mut meta = RecordingMeta::load_for_project(&recording_dir).unwrap();
866+
meta.inner = meta_inner;
861867
meta.save_for_project()
862868
.map_err(|e| format!("Failed to save recording meta: {e}"))?;
863869

apps/desktop/src/routes/(window-chrome)/settings/recordings.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function RecordingItem(props: {
187187
onCopyVideoToClipboard: () => void;
188188
}) {
189189
const [imageExists, setImageExists] = createSignal(true);
190-
const mode = () => props.recording.meta.mode;
190+
const mode = () => props.recording.meta.mode || "other"; // TODO: Fix this
191191
const firstLetterUpperCase = () =>
192192
mode().charAt(0).toUpperCase() + mode().slice(1);
193193

@@ -210,6 +210,8 @@ function RecordingItem(props: {
210210
/>
211211
</Show>
212212
<div class="flex flex-col gap-2">
213+
{"recording" in props.recording.meta ? "TRUE" : "FALSE"}
214+
213215
<span>{props.recording.prettyName}</span>
214216
<div
215217
class={cx(

apps/desktop/src/utils/tauri.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ export type ProjectConfiguration = { aspectRatio: AspectRatio | null; background
420420
export type ProjectRecordingsMeta = { segments: SegmentRecordings[] }
421421
export type RecordingDeleted = { path: string }
422422
export type RecordingEvent = { variant: "Countdown"; value: number } | { variant: "Started" } | { variant: "Stopped" } | { variant: "Failed"; error: string }
423-
export type RecordingMeta = (StudioRecordingMeta | InstantRecordingMeta) & { platform?: Platform | null; pretty_name: string; sharing?: SharingMeta | null }
424-
export type RecordingMetaWithMode = ((StudioRecordingMeta | InstantRecordingMeta) & { platform?: Platform | null; pretty_name: string; sharing?: SharingMeta | null }) & { mode: RecordingMode }
423+
export type RecordingMeta = (StudioRecordingMeta | InstantRecordingMeta | { recording: boolean }) & { platform?: Platform | null; pretty_name: string; sharing?: SharingMeta | null }
424+
export type RecordingMetaWithMode = ((StudioRecordingMeta | InstantRecordingMeta | { recording: boolean }) & { platform?: Platform | null; pretty_name: string; sharing?: SharingMeta | null }) & { mode: RecordingMode | null }
425425
export type RecordingMode = "studio" | "instant"
426426
export type RecordingOptionsChanged = null
427427
export type RecordingSettingsStore = { target: ScreenCaptureTarget | null; micName: string | null; cameraId: DeviceOrModelID | null; mode: RecordingMode | null; systemAudio: boolean }

crates/project/src/meta.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
path::{Path, PathBuf},
99
};
1010
use tracing::{debug, info, warn};
11-
// use tracing::{debug, warn};
1211

1312
use crate::{CaptionsData, CursorEvents, CursorImage, ProjectConfiguration, XY};
1413

@@ -70,15 +69,27 @@ pub struct RecordingMeta {
7069
pub sharing: Option<SharingMeta>,
7170
#[serde(flatten)]
7271
pub inner: RecordingMetaInner,
72+
// #[serde(default)]
73+
// pub upload: UploadState, // TODO: Put in `StudioRecordingMeta`, etc
7374
}
7475

75-
impl specta::Flatten for RecordingMetaInner {}
76+
// impl specta::Flatten for RecordingMetaInner {}
77+
78+
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
79+
pub enum UploadState {
80+
Uploading,
81+
Failed(String),
82+
Complete,
83+
}
7684

7785
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
7886
#[serde(untagged, rename_all = "camelCase")]
7987
pub enum RecordingMetaInner {
8088
Studio(StudioRecordingMeta),
8189
Instant(InstantRecordingMeta),
90+
// This is set while the recording is still active.
91+
InProgress { recording: bool },
92+
// Failed { error: String },
8293
}
8394

8495
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
@@ -91,6 +102,7 @@ impl RecordingMeta {
91102
pub fn path(&self, relative: &RelativePathBuf) -> PathBuf {
92103
relative.to_path(&self.project_path)
93104
}
105+
94106
pub fn load_for_project(project_path: &Path) -> Result<Self, Box<dyn Error>> {
95107
let meta_path = project_path.join("recording-meta.json");
96108
let mut meta: Self = serde_json::from_str(&std::fs::read_to_string(&meta_path)?)?;
@@ -135,6 +147,7 @@ impl RecordingMeta {
135147
match &self.inner {
136148
RecordingMetaInner::Instant(_) => self.project_path.join("content/output.mp4"),
137149
RecordingMetaInner::Studio(_) => self.project_path.join("output").join("result.mp4"),
150+
RecordingMetaInner::InProgress { recording } => todo!(),
138151
}
139152
}
140153

0 commit comments

Comments
 (0)