Skip to content

Commit

Permalink
commercial licensing
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Feb 15, 2025
1 parent 89b539e commit 30f750c
Show file tree
Hide file tree
Showing 19 changed files with 685 additions and 351 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tokio = { version = "1.39.3", features = [
"time",
] }
tauri = { version = "2.2.3", features = ["specta"] }
specta = { version = "=2.0.0-rc.20", features = ["derive"] }
specta = { version = "=2.0.0-rc.20", features = ["derive", "uuid"] }

scap = { git = "https://github.com/CapSoftware/scap", rev = "58d4410bf52f" }
nokhwa = { git = "https://github.com/CapSoftware/nokhwa", rev = "d37141b1883d", features = [
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"identifier": "http:default",
"allow": [
{ "url": "https://cap.so" },
{ "url": "https://l.cap.so" },
{ "url": "http://localhost:3000/*" }
]
},
Expand Down
57 changes: 38 additions & 19 deletions apps/desktop/src-tauri/src/general_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ use specta::Type;
use std::sync::Mutex;
use tauri::{AppHandle, Manager, Wry};
use tauri_plugin_store::StoreExt;
use uuid::Uuid;

#[derive(Serialize, Deserialize, Type, Default)]
#[derive(Serialize, Deserialize, Type, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GeneralSettingsStore {
#[serde(default = "uuid::Uuid::new_v4")]
pub instance_id: Uuid,
#[serde(default)]
pub upload_individual_files: bool,
#[serde(default)]
Expand All @@ -30,6 +33,39 @@ pub struct GeneralSettingsStore {
pub theme: AppTheme,
#[serde(default)]
pub recording_config: Option<RecordingConfig>,
#[serde(default)]
pub commercial_license: Option<CommercialLicense>,
#[serde(default)]
pub last_version: Option<String>,
}

#[derive(Serialize, Deserialize, Type, Debug)]
#[serde(rename_all = "camelCase")]
pub struct CommercialLicense {
license_key: String,
expiry_date: u32,
refresh: u32,
activated_on: u32,
}

impl Default for GeneralSettingsStore {
fn default() -> Self {
Self {
instance_id: uuid::Uuid::new_v4(),
upload_individual_files: false,
open_editor_after_recording: false,
hide_dock_icon: false,
haptics_enabled: true,
auto_create_shareable_link: false,
enable_notifications: true,
disable_auto_open_links: false,
has_completed_startup: false,
theme: AppTheme::System,
recording_config: None,
commercial_license: None,
last_version: None,
}
}
}

#[derive(Default, Debug, Copy, Clone, Serialize, Deserialize, Type)]
Expand Down Expand Up @@ -71,7 +107,7 @@ impl GeneralSettingsStore {
// Handle potential deserialization errors gracefully
match serde_json::from_value(store) {
Ok(settings) => Ok(Some(settings)),
Err(_) => Ok(Some(GeneralSettingsStore::default())),
Err(_) => Err("Failed to deserialize general settings store".to_string()),
}
}
_ => Ok(None),
Expand Down Expand Up @@ -102,20 +138,3 @@ pub fn init(app: &AppHandle) {
app.manage(GeneralSettingsState::new(store));
println!("GeneralSettingsState managed");
}

#[tauri::command]
#[specta::specta]
pub async fn get_recording_config(app: AppHandle) -> Result<RecordingConfig, String> {
let settings = GeneralSettingsStore::get(&app)?;
Ok(settings
.and_then(|s| s.recording_config)
.unwrap_or_default())
}

#[tauri::command]
#[specta::specta]
pub async fn set_recording_config(app: AppHandle, config: RecordingConfig) -> Result<(), String> {
GeneralSettingsStore::update(&app, |settings| {
settings.recording_config = Some(config);
})
}
5 changes: 2 additions & 3 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,7 @@ pub async fn run() {
CapWindowId::Camera.label().as_str(),
CapWindowId::RecordingsOverlay.label().as_str(),
CapWindowId::InProgressRecording.label().as_str(),
CapWindowId::Upgrade.label().as_str(),
])
.map_label(|label| match label {
label if label.starts_with("editor-") => "editor",
Expand Down Expand Up @@ -2173,9 +2174,7 @@ pub async fn run() {

if !permissions.screen_recording.permitted()
|| !permissions.accessibility.permitted()
|| GeneralSettingsStore::get(&app)
.ok()
.flatten()
|| dbg!(GeneralSettingsStore::get(&app).ok().flatten())
.map(|s| !s.has_completed_startup)
.unwrap_or(false)
{
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl CapWindowId {
Self::Editor { .. } => (900.0, 800.0),
Self::Settings => (600.0, 450.0),
Self::Camera => (460.0, 920.0),
Self::Upgrade => (800.0, 850.0),
_ => return None,
})
}
Expand Down Expand Up @@ -200,7 +201,6 @@ impl ShowCapWindow {
.build()?,
Self::Upgrade => self
.window_builder(app, "/upgrade")
.inner_size(800.0, 800.0)
.resizable(false)
.focused(true)
.always_on_top(true)
Expand Down
12 changes: 7 additions & 5 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ function Inner() {
fallback={(e: Error) => {
console.error(e);
return (
<div class="w-screen h-screen flex flex-col justify-center items-center bg-gray-100 border-gray-200 max-h-screen overflow-hidden transition-[border-radius] duration-200 text-[--text-secondary] gap-y-4">
<IconCapLogo />
<h1 class="text-[--text-primary] text-3xl font-bold">
<div class="w-screen h-screen flex flex-col justify-center items-center bg-gray-100 border-gray-200 max-h-screen overflow-hidden transition-[border-radius] duration-200 text-[--text-secondary] gap-y-4 max-sm:gap-y-2 px-8 text-center">
<IconCapLogo class="max-sm:size-16" />
<h1 class="text-[--text-primary] text-3xl max-sm:text-xl font-bold">
An Error Occured
</h1>
<p>We're very sorry, but something has gone wrong.</p>
<div class="flex flex-row gap-x-4">
<p class="max-sm:text-sm mb-2">
We're very sorry, but something has gone wrong.
</p>
<div class="flex max-sm:flex-col flex-row max-sm:gap-2 gap-4">
<Button
onClick={() => {
writeText(`${e.toString()}\n\n${e.stack}`);
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default createHandler(() => (
{assets}
</head>
<body class="w-screen h-screen select-none cursor-default">
<div id="app" class="h-full">
<div id="app" class="h-full text-[--text-primary]">
{children}
</div>
{scripts}
Expand Down
Loading

0 comments on commit 30f750c

Please sign in to comment.