WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
31 changes: 30 additions & 1 deletion apps/desktop/src-tauri/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use serde::{Deserialize, Serialize};
use serde_json::json;
use specta::Type;
use tauri::AppHandle;
use tracing::{instrument, trace};

Expand Down Expand Up @@ -32,7 +33,7 @@ pub async fn upload_multipart_initiate(
.map_err(|err| format!("api/upload_multipart_initiate/request: {err}"))?;

if !resp.status().is_success() {
let status = resp.status();
let status = resp.status().as_u16();
let error_body = resp
.text()
.await
Expand Down Expand Up @@ -255,3 +256,31 @@ pub async fn desktop_video_progress(

Ok(())
}

#[derive(Serialize, Deserialize, Type, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Organization {
pub id: String,
pub name: String,
pub owner_id: String,
}

pub async fn fetch_organizations(app: &AppHandle) -> Result<Vec<Organization>, AuthedApiError> {
let resp = app
.authed_api_request("/api/desktop/organizations", |client, url| client.get(url))
.await
.map_err(|err| format!("api/fetch_organizations/request: {err}"))?;

if !resp.status().is_success() {
let status = resp.status().as_u16();
let error_body = resp
.text()
.await
.unwrap_or_else(|_| "<no response body>".to_string());
return Err(format!("api/fetch_organizations/{status}: {error_body}").into());
}

resp.json()
.await
.map_err(|err| format!("api/fetch_organizations/response: {err}").into())
}
10 changes: 9 additions & 1 deletion apps/desktop/src-tauri/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ use tauri_plugin_store::StoreExt;

use web_api::ManagerExt;

use crate::web_api;
use crate::{
api::{self, Organization},
web_api,
};

#[derive(Serialize, Deserialize, Type, Debug)]
pub struct AuthStore {
pub secret: AuthSecret,
pub user_id: Option<String>,
pub plan: Option<Plan>,
pub intercom_hash: Option<String>,
#[serde(default)]
pub organizations: Vec<Organization>,
}

#[derive(Serialize, Deserialize, Type, Debug)]
Expand Down Expand Up @@ -96,6 +101,9 @@ impl AuthStore {
manual: auth.plan.as_ref().is_some_and(|p| p.manual),
});
auth.intercom_hash = Some(plan_response.intercom_hash.unwrap_or_default());
auth.organizations = api::fetch_organizations(app)
.await
.map_err(|e| e.to_string())?;

Self::set(app, Some(auth))?;

Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/src/deeplink_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ impl DeepLinkAction {
};

let inputs = StartRecordingInputs {
mode,
capture_target,
capture_system_audio,
mode,
organization_id: None,
};

crate::recording::start_recording(app.clone(), state, inputs)
Expand Down
16 changes: 9 additions & 7 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use tauri_plugin_opener::OpenerExt;
use tauri_plugin_shell::ShellExt;
use tauri_specta::Event;
use tokio::sync::{RwLock, oneshot};
use tracing::{error, instrument, trace, warn};
use tracing::*;
use upload::{create_or_get_video, upload_image, upload_video};
use web_api::AuthedApiError;
use web_api::ManagerExt as WebManagerExt;
Expand Down Expand Up @@ -1081,6 +1081,7 @@ async fn upload_exported_video(
path: PathBuf,
mode: UploadMode,
channel: Channel<UploadProgress>,
organization_id: Option<String>,
) -> Result<UploadResult, String> {
let Ok(Some(auth)) = AuthStore::get(&app) else {
AuthStore::set(&app, None).map_err(|e| e.to_string())?;
Expand Down Expand Up @@ -1127,6 +1128,7 @@ async fn upload_exported_video(
video_id,
Some(meta.pretty_name.clone()),
Some(metadata.clone()),
organization_id,
)
.await
}
Expand Down Expand Up @@ -1656,6 +1658,7 @@ async fn check_upgraded_and_update(app: AppHandle) -> Result<bool, String> {
manual: auth.plan.map(|p| p.manual).unwrap_or(false),
last_checked: chrono::Utc::now().timestamp() as i32,
}),
organizations: auth.organizations,
};
println!("Updating auth store with new pro status");
AuthStore::set(&app, Some(updated_auth)).map_err(|e| e.to_string())?;
Expand Down Expand Up @@ -2323,19 +2326,18 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {
let _ = set_mic_input(app.state(), settings.mic_name).await;
let _ = set_camera_input(app.clone(), app.state(), settings.camera_id).await;

let _ = start_recording(
app.clone(),
app.state(),
let _ = start_recording(app.clone(), app.state(), {
recording::StartRecordingInputs {
capture_target: settings.target.unwrap_or_else(|| {
ScreenCaptureTarget::Display {
id: Display::primary().id(),
}
}),
capture_system_audio: settings.system_audio,
mode: event.mode,
},
)
capture_system_audio: settings.system_audio,
organization_id: settings.organization_id,
}
})
.await;
});

Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/src/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ pub struct StartRecordingInputs {
#[serde(default)]
pub capture_system_audio: bool,
pub mode: RecordingMode,
#[serde(default)]
pub organization_id: Option<String>,
}

#[derive(tauri_specta::Event, specta::Type, Clone, Debug, serde::Serialize)]
Expand Down Expand Up @@ -313,6 +315,7 @@ pub async fn start_recording(
chrono::Local::now().format("%Y-%m-%d %H:%M:%S")
)),
None,
inputs.organization_id.clone(),
)
.await
{
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/src/recording_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct RecordingSettingsStore {
pub camera_id: Option<DeviceOrModelID>,
pub mode: Option<RecordingMode>,
pub system_audio: bool,
pub organization_id: Option<String>,
}

impl RecordingSettingsStore {
Expand Down
7 changes: 6 additions & 1 deletion apps/desktop/src-tauri/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub async fn upload_image(
.ok_or("Invalid file path")?
.to_string();

let s3_config = create_or_get_video(app, true, None, None, None).await?;
let s3_config = create_or_get_video(app, true, None, None, None, None).await?;

let (stream, total_size) = file_reader_stream(file_path).await?;
singlepart_uploader(
Expand Down Expand Up @@ -206,6 +206,7 @@ pub async fn create_or_get_video(
video_id: Option<String>,
name: Option<String>,
meta: Option<S3VideoMeta>,
organization_id: Option<String>,
) -> Result<S3UploadMeta, AuthedApiError> {
let mut s3_config_url = if let Some(id) = video_id {
format!("/api/desktop/video/create?recordingMode=desktopMP4&videoId={id}")
Expand All @@ -228,6 +229,10 @@ pub async fn create_or_get_video(
}
}

if let Some(org_id) = organization_id {
s3_config_url.push_str(&format!("&orgId={}", org_id));
}

let response = app
.authed_api_request(s3_config_url, |client, url| client.get(url))
.await?;
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/routes/(window-chrome)/new-main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ function Page() {
currentWindow.setSize(new LogicalSize(size.width, size.height));
});

commands.updateAuthPlan();

onCleanup(async () => {
(await unlistenFocus)?.();
(await unlistenResize)?.();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ function RecordingItem(props: {
props.recording.path,
"Reupload",
new Channel<UploadProgress>((progress) => {}),
null,
),
}));

Expand Down
Loading