Skip to content

Commit e1a4391

Browse files
feat: Progressive upload during recording (faster Instant Mode) (#351)
* feat: Progressive upload, on the fly, during recording * fix: check for completed mp4 * remove all the unnecessary logs * back to commit before trying to remove logs/metadata * feat: do not read file each time * feat: 95% complete multipart * cleanup some apis * almost completely configure tracing * fix logs for instant recording * use compile-time env * dotenv * bruh * -_- * no cache pnpm * bruh * man idk * idk * smh * pnpm v * wha * cleanup --------- Co-authored-by: Brendan Allan <[email protected]>
1 parent 8ff41fc commit e1a4391

File tree

31 files changed

+1905
-871
lines changed

31 files changed

+1905
-871
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,7 @@ jobs:
5454
with:
5555
shared-key: ${{ matrix.settings.target }}
5656

57-
- name: Setup pnpm
58-
uses: pnpm/action-setup@v4
59-
with:
60-
version: 10.5.2
61-
62-
- name: Setup Node.js
63-
uses: actions/setup-node@v4
64-
with:
65-
node-version: "20"
66-
cache: pnpm
57+
- uses: ./.github/actions/setup-js
6758

6859
- name: Create .env file in root
6960
run: |
@@ -79,8 +70,7 @@ jobs:
7970
echo "NEXT_PUBLIC_CAP_AWS_REGION=${{ secrets.NEXT_PUBLIC_CAP_AWS_REGION }}" >> .env
8071
echo "NEXT_PUBLIC_CAP_AWS_BUCKET=${{ secrets.NEXT_PUBLIC_CAP_AWS_BUCKET }}" >> .env
8172
82-
- name: Copy .env to apps/desktop
83-
run: cp .env apps/desktop/.env
73+
cat .env >> $GITHUB_ENV
8474
8575
- name: Run setup
8676
run: |
@@ -116,19 +106,7 @@ jobs:
116106
with:
117107
shared-key: ${{ matrix.settings.target }}
118108

119-
- name: Setup pnpm
120-
uses: pnpm/action-setup@v4
121-
with:
122-
version: 10.5.2
123-
124-
- name: Setup Node.js
125-
uses: actions/setup-node@v4
126-
with:
127-
node-version: "20"
128-
cache: pnpm
129-
130-
- name: Install dependencies
131-
run: pnpm install
109+
- uses: ./.github/actions/setup-js
132110

133111
- name: Create .env file in root
134112
run: |

.github/workflows/main.yml

Lines changed: 0 additions & 85 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,7 @@ jobs:
170170
with:
171171
shared-key: ${{ matrix.settings.target }}
172172

173-
- name: Setup pnpm
174-
uses: pnpm/action-setup@v4
175-
with:
176-
version: 10.5.2
177-
178-
- name: Setup Node.js
179-
uses: actions/setup-node@v4
180-
with:
181-
node-version: "20"
182-
cache: pnpm
183-
184-
- name: Install dependencies
185-
run: pnpm install
173+
- uses: ./.github/actions/setup-js
186174

187175
- name: Create .env file in root
188176
run: |
@@ -200,17 +188,11 @@ jobs:
200188
echo "NEXT_PUBLIC_CAP_AWS_BUCKET=${{ secrets.NEXT_PUBLIC_CAP_AWS_BUCKET }}" >> .env
201189
echo 'RUST_TARGET_TRIPLE=${{ matrix.settings.target }}' >> .env
202190
203-
- name: Copy .env to apps/desktop
204-
run: cp .env apps/desktop/.env
205-
206-
- name: Output .env file
207-
run: cat apps/desktop/.env
208-
209191
- name: Build app
210192
working-directory: apps/desktop
211193
run: |
212194
pnpm -w cap-setup
213-
pnpm tauri build --target ${{ matrix.settings.target }} --config src-tauri/tauri.prod.conf.json
195+
pnpm build:tauri --target ${{ matrix.settings.target }} --config src-tauri/tauri.prod.conf.json
214196
env:
215197
# https://github.com/tauri-apps/tauri-action/issues/740
216198
CI: false

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@cap/desktop",
33
"type": "module",
44
"scripts": {
5-
"dev": "pnpm -w cap-setup && cross-env RUST_BACKTRACE=1 dotenv -e ../../.env -- pnpm run preparescript && tauri dev",
6-
"build:tauri": "dotenv -e ../../.env -- pnpm run preparescript && tauri build",
5+
"dev": "pnpm -w cap-setup && dotenv -e ../../.env -- pnpm run preparescript && pnpm tauri dev",
6+
"build:tauri": "dotenv -e ../../.env -- pnpm run preparescript && dotenv -e ../../.env -- pnpm tauri build",
77
"preparescript": "node scripts/prepare.js",
88
"localdev": "dotenv -e ../../.env -- vinxi dev --port 3001",
99
"build": "vinxi build",

apps/desktop/src-tauri/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[lib]
11-
name = "desktop_solid_lib"
11+
name = "cap_desktop"
1212
crate-type = ["lib", "cdylib", "staticlib"]
1313

1414
[build-dependencies]
@@ -44,7 +44,7 @@ tauri-plugin-deep-link = "2.2.0"
4444
tauri-plugin-clipboard-manager = "2.2.1"
4545

4646
serde = { version = "1", features = ["derive"] }
47-
serde_json = "1"
47+
serde_json = "1.0.111"
4848
specta.workspace = true
4949
specta-typescript = "0.0.7"
5050
tokio.workspace = true
@@ -57,9 +57,9 @@ anyhow.workspace = true
5757
futures = "0.3"
5858
axum = { version = "0.7.5", features = ["ws"] }
5959
tracing = "0.1.40"
60-
tempfile = "3.12.0"
60+
tempfile = "3.9.0"
6161
ffmpeg.workspace = true
62-
chrono = "0.4.38"
62+
chrono = { version = "0.4.31", features = ["serde"] }
6363
rodio = "0.19.0"
6464
png = "0.17.13"
6565
device_query = "2.1.0"
@@ -88,6 +88,7 @@ dirs = "6.0.0"
8888
relative-path = "1.9.3"
8989
cap-fail = { version = "0.1.0", path = "../../../crates/fail" }
9090
tokio-stream = { version = "0.1.17", features = ["sync"] }
91+
md5 = "0.7.0"
9192

9293
[target.'cfg(target_os = "macos")'.dependencies]
9394
core-graphics = "0.24.0"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl EditorInstances {
7272
}
7373
}
7474

75-
pub async fn remove(window: &Window) {
75+
pub async fn remove(window: Window) {
7676
let Some(instances) = window.try_state::<EditorInstances>() else {
7777
return;
7878
};

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use mp4::Mp4Reader;
5050
// use display::{list_capture_windows, Bounds, CaptureTarget, FPS};
5151
use notifications::NotificationType;
5252
use png::{ColorType, Encoder};
53-
use recording::RecordingActor;
53+
use recording::InProgressRecording;
5454
use relative_path::RelativePathBuf;
5555
use scap::capturer::Capturer;
5656
use scap::frame::Frame;
@@ -98,9 +98,9 @@ pub struct App {
9898
#[serde(skip)]
9999
handle: AppHandle,
100100
#[serde(skip)]
101-
current_recording: Option<RecordingActor>,
101+
current_recording: Option<InProgressRecording>,
102102
#[serde(skip)]
103-
pre_created_video: Option<PreCreatedVideo>,
103+
recording_logging_handle: LoggingHandle,
104104
}
105105

106106
#[derive(specta::Type, Serialize, Deserialize, Clone, Debug)]
@@ -126,14 +126,14 @@ pub struct VideoRecordingMetadata {
126126
}
127127

128128
#[derive(Clone, Serialize, Deserialize, specta::Type, Debug)]
129-
pub struct PreCreatedVideo {
129+
pub struct VideoUploadInfo {
130130
id: String,
131131
link: String,
132132
config: S3UploadMeta,
133133
}
134134

135135
impl App {
136-
pub fn set_current_recording(&mut self, actor: RecordingActor) {
136+
pub fn set_current_recording(&mut self, actor: InProgressRecording) {
137137
let current_recording = self.current_recording.insert(actor);
138138

139139
CurrentRecordingChanged.emit(&self.handle).ok();
@@ -148,7 +148,7 @@ impl App {
148148
}
149149
}
150150

151-
pub fn clear_current_recording(&mut self) -> Option<RecordingActor> {
151+
pub fn clear_current_recording(&mut self) -> Option<InProgressRecording> {
152152
self.close_occluder_window();
153153

154154
self.current_recording.take()
@@ -439,7 +439,6 @@ async fn get_recording_options(
439439
#[tauri::command]
440440
#[specta::specta]
441441
async fn set_recording_options(
442-
app: AppHandle,
443442
state: MutableState<'_, App>,
444443
options: RecordingOptions,
445444
) -> Result<(), String> {
@@ -1160,7 +1159,7 @@ pub struct UploadProgress {
11601159
#[derive(Deserialize, Type)]
11611160
pub enum UploadMode {
11621161
Initial {
1163-
pre_created_video: Option<PreCreatedVideo>,
1162+
pre_created_video: Option<VideoUploadInfo>,
11641163
},
11651164
Reupload,
11661165
}
@@ -1951,17 +1950,15 @@ async fn update_auth_plan(app: AppHandle) {
19511950
AuthStore::update_auth_plan(&app).await.ok();
19521951
}
19531952

1953+
pub type DynLoggingLayer =
1954+
Box<dyn tracing_subscriber::Layer<tracing_subscriber::Registry> + Send + Sync>;
1955+
type LoggingHandle =
1956+
tracing_subscriber::reload::Handle<Option<DynLoggingLayer>, tracing_subscriber::Registry>;
1957+
19541958
#[cfg_attr(mobile, tauri::mobile_entry_point)]
1955-
pub async fn run() {
1959+
pub async fn run(recording_logging_handle: LoggingHandle) {
19561960
let tauri_context = tauri::generate_context!();
19571961

1958-
// let _guard = configure_logging(
1959-
// &dirs::data_dir()
1960-
// .unwrap()
1961-
// .join(&tauri_context.config().identifier)
1962-
// .join("logs"),
1963-
// );
1964-
19651962
let specta_builder = tauri_specta::Builder::new()
19661963
.commands(tauri_specta::collect_commands![
19671964
get_recording_options,
@@ -2144,7 +2141,7 @@ pub async fn run() {
21442141
mode: RecordingMode::Studio,
21452142
},
21462143
current_recording: None,
2147-
pre_created_video: None,
2144+
recording_logging_handle,
21482145
})));
21492146

21502147
app.manage(Arc::new(RwLock::new(
@@ -2253,7 +2250,7 @@ pub async fn run() {
22532250
}
22542251
}
22552252
CapWindowId::Editor { .. } => {
2256-
EditorInstances::remove(window);
2253+
tokio::spawn(EditorInstances::remove(window.clone()));
22572254
}
22582255
CapWindowId::Settings | CapWindowId::Upgrade => {
22592256
// Don't quit the app when settings or upgrade window is closed

0 commit comments

Comments
 (0)