Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: notification settings toggle

Richie McIlroy87edc6398f27
diff --git a/apps/desktop/package.json b/apps/desktop/package.json
index 022cce41b..6a46cedbb 100644
--- a/apps/desktop/package.json
+++ b/apps/desktop/package.json
@@ -39,6 +39,7 @@
"@tauri-apps/plugin-shell": ">=2.0.0-rc.0",
"@tauri-apps/plugin-store": "2.1.0",
"@tauri-apps/plugin-updater": "2.0.0-rc.0",
+ "@tauri-apps/plugin-notification": "2.0.0-rc.0",
"@types/react-tooltip": "^4.2.4",
"cva": "npm:class-variance-authority@^0.7.0",
"effect": "^3.7.2",
diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml
index f505a8a16..fe2fc0665 100644
--- a/apps/desktop/src-tauri/Cargo.toml
+++ b/apps/desktop/src-tauri/Cargo.toml
@@ -30,7 +30,7 @@ tauri-plugin-process = "2.0.0"
tauri-plugin-decorum = "1.0.0"
tauri-plugin-dialog = "2.0.0"
tauri-plugin-updater = "2.0.0"
-tauri-plugin-notification = "2.0.0"
+tauri-plugin-notification = "2.0.0-rc"
tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "v2" }
tauri-plugin-global-shortcut = "2.0.0"
tauri-specta = { version = "=2.0.0-rc.20", features = ["derive", "typescript"] }
diff --git a/apps/desktop/src-tauri/capabilities/default.json b/apps/desktop/src-tauri/capabilities/default.json
index 5666c4f65..46a5d0706 100644
--- a/apps/desktop/src-tauri/capabilities/default.json
+++ b/apps/desktop/src-tauri/capabilities/default.json
@@ -28,6 +28,7 @@
"process:default",
"oauth:allow-start",
"updater:default",
+ "notification:default",
{
"identifier": "http:default",
"allow": [{ "url": "https://cap.so" }]
diff --git a/apps/desktop/src-tauri/src/general_settings.rs b/apps/desktop/src-tauri/src/general_settings.rs
index 902c1e5da..1c5621e27 100644
--- a/apps/desktop/src-tauri/src/general_settings.rs
+++ b/apps/desktop/src-tauri/src/general_settings.rs
@@ -13,8 +13,12 @@ pub struct GeneralSettingsStore {
pub hide_dock_icon: bool,
#[serde(default)]
pub auto_create_shareable_link: bool,
- #[serde(default)]
- pub enable_tooltip_notifications: bool, // New field
+ #[serde(default = "default_enable_notifications")]
+ pub enable_notifications: bool,
+}
+
+fn default_enable_notifications() -> bool {
+ true
}
impl GeneralSettingsStore {
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index c7aca4d13..7245270e4 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -55,7 +55,7 @@ use std::{
};
use tauri::{AppHandle, Manager, Runtime, State, WindowEvent};
use tauri_nspanel::ManagerExt;
-use tauri_plugin_notification::NotificationExt;
+use tauri_plugin_notification::{NotificationExt, PermissionState};
use tauri_plugin_shell::ShellExt;
use tauri_specta::Event;
use tokio::task;
@@ -2334,6 +2334,36 @@ async fn seek_to(app: AppHandle, video_id: String, frame_number: u32) {
.await;
}
+async fn check_notification_permissions(app: &AppHandle) {
+ // Check if we've already requested permissions
+ if let Ok(Some(settings)) = GeneralSettingsStore::get(app) {
+ if settings.enable_notifications {
+ match app.notification().permission_state() {
+ Ok(state) if state != PermissionState::Granted => {
+ println!("Requesting notification permission");
+ match app.notification().request_permission() {
+ Ok(PermissionState::Granted) => {
+ println!("Notification permission granted");
+ }
+ Ok(_) | Err(_) => {
+ if let Ok(Some(mut s)) = GeneralSettingsStore::get(app) {
+ s.enable_notifications = false;
+ GeneralSettingsStore::set(app, s).ok();
+ }
+ }
+ }
+ }
+ Ok(_) => {
+ println!("Notification permission already granted");
+ }
+ Err(e) => {
+ eprintln!("Error checking notification permission state: {}", e);
+ }
+ }
+ }
+ }
+}
+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub async fn run() {
let specta_builder = tauri_specta::Builder::new()
@@ -2373,7 +2403,6 @@ pub async fn run() {
open_main_window,
permissions::open_permission_settings,
permissions::do_permissions_check,
- permissions::request_permission,
upload_rendered_video,
upload_screenshot,
get_recording_meta,
@@ -2452,6 +2481,13 @@ pub async fn run() {
let app_handle = app.handle().clone();
+ // Add this line to check notification permissions on startup
+ // Fix: Clone the app_handle and move it into the spawned task
+ let notification_handle = app_handle.clone();
+ tauri::async_runtime::spawn(async move {
+ check_notification_permissions(&notification_handle).await;
+ });
+
if permissions::do_permissions_check(true).necessary_granted() {
open_main_window(app_handle.clone());
} else {
diff --git a/apps/desktop/src-tauri/src/notifications.rs b/apps/desktop/src-tauri/src/notifications.rs
index e1be37c8a..24d3b1f6b 100644
--- a/apps/desktop/src-tauri/src/notifications.rs
+++ b/apps/desktop/src-tauri/src/notifications.rs
@@ -1,4 +1,4 @@
-use crate::{AppSounds, NewNotification};
+use crate::{general_settings::GeneralSettingsStore, AppSounds, NewNotification};
use tauri_plugin_notification::NotificationExt;
use tauri_specta::Event;
@@ -83,6 +83,15 @@ impl NotificationType {
}
pub fn send_notification(app: &tauri::AppHandle, notification_type: NotificationType) {
+ // Check if notifications are enabled in settings
+ let enable_notifications = GeneralSettingsStore::get(app)
+ .map(|settings| settings.map_or(false, |s| s.enable_notifications))
+ .unwrap_or(false);
+
+ if !enable_notifications {
+ return;
+ }
+
let (title, body, is_error) = notification_type.details();
app.notification()
diff --git a/apps/desktop/src-tauri/src/web_api.rs b/apps/desktop/src-tauri/src/web_api.rs
index bbb16f73c..b64a8ced3 100644
--- a/apps/desktop/src-tauri/src/web_api.rs
+++ b/apps/desktop/src-tauri/src/web_api.rs
@@ -5,7 +5,7 @@ use tauri_specta::Event;
use crate::auth::{AuthStore, AuthenticationInvalid};
pub fn make_url(pathname: impl AsRef<str>) -> String {
- let server_url_base = "http://localhost:3000"; //dotenvy_macro::dotenv!("NEXT_PUBLIC_URL");
+ let server_url_base = dotenvy_macro::dotenv!("NEXT_PUBLIC_URL");
format!("{server_url_base}{}", pathname.as_ref())
}
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
index 1d2612af8..30a7c6c42 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
@@ -2,6 +2,10 @@ import { createResource, Show, For } from "solid-js";
import { createStore } from "solid-js/store";
import { generalSettingsStore } from "~/store";
import { commands, type GeneralSettingsStore } from "~/utils/tauri";
+import {
+ isPermissionGranted,
+ requestPermission,
+} from "@tauri-apps/plugin-notification";
const settingsList = [
{
@@ -28,6 +32,13 @@ const settingsList = [
description:
"When enabled, a shareable link will be created automatically after stopping the recording. You'll be redirected to the URL while the upload continues in the background.",
},
+ {
+ key: "enable_notifications",
+ label: "Enable System Notifications",
+ description:
+ "Show system notifications for events like copying to clipboard, saving files, and more.",
+ requiresPermission: true,
+ },
];
export default function GeneralSettings() {
@@ -51,10 +62,36 @@ function Inner(props: { store: GeneralSettingsStore | null }) {
props.store ?? {
upload_individual_files: false,
open_editor_after_recording: false,
+ hide_dock_icon: false,
+ auto_create_shareable_link: false,
+ enable_notifications: true,
}
);
const handleChange = async (key: string, value: boolean) => {
+ console.log(`Handling settings change for ${key}: ${value}`);
+ // Special handling for notifications permission
+ if (key === "enable_notifications") {
+ if (value) {
+ // Check current permission state
+ console.log("Checking notification permission status");
+ const permissionGranted = await isPermissionGranted();
+ console.log(`Current permission status: ${permissionGranted}`);
+
+ if (!permissionGranted) {
+ // Request permission if not granted
+ console.log("Permission not granted, requesting permission");
+ const permission = await requestPermission();
+ console.log(`Permission request result: ${permission}`);
+ if (permission !== "granted") {
+ // If permission denied, don't enable the setting
+ console.log("Permission denied, aborting setting change");
+ return;
+ }
+ }
+ }
+ }
+
setSettings(key as keyof GeneralSettingsStore, value);
await commands.setGeneralSettings({
...settings,
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 8fca86e58..5077916ab 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -197,9 +197,6 @@ async openPermissionSettings(permission: OSPermission) : Promise<void> {
async doPermissionsCheck(initialCheck: boolean) : Promise<OSPermissionsCheck> {
return await TAURI_INVOKE("do_permissions_check", { initialCheck });
},
-async requestPermission(permission: OSPermission) : Promise<void> {
- await TAURI_INVOKE("request_permission", { permission });
-},
async uploadRenderedVideo(videoId: string, project: ProjectConfiguration, preCreatedVideo: PreCreatedVideo | null) : Promise<Result<UploadResult, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("upload_rendered_video", { videoId, project, preCreatedVideo }) };
@@ -389,7 +386,7 @@ export type CursorType = "pointer" | "circle"
export type Display = { path: string }
export type EditorStateChanged = { playhead_position: number }
export type Flags = { recordMouse: boolean; split: boolean; pauseResume: boolean; zoom: boolean }
-export type GeneralSettingsStore = { upload_individual_files: boolean; open_editor_after_recording: boolean; hide_dock_icon?: boolean; auto_create_shareable_link?: boolean; enable_tooltip_notifications?: boolean }
+export type GeneralSettingsStore = { upload_individual_files: boolean; open_editor_after_recording: boolean; hide_dock_icon?: boolean; auto_create_shareable_link?: boolean; enable_notifications?: boolean }
export type Hotkey = { code: string; meta: boolean; ctrl: boolean; alt: boolean; shift: boolean }
export type HotkeyAction = "startRecording" | "stopRecording" | "restartRecording" | "takeScreenshot"
export type HotkeysConfiguration = { show: boolean }
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 24f0d3d30..2190f63a9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -112,6 +112,9 @@ importers:
'@tauri-apps/plugin-http':
specifier: ^2.0.1
version: 2.0.1
+ '@tauri-apps/plugin-notification':
+ specifier: 2.0.0-rc.0
+ version: 2.0.0-rc.0
'@tauri-apps/plugin-os':
specifier: 2.0.0-rc.1
version: 2.0.0-rc.1
@@ -4266,6 +4269,9 @@ packages:
'@tauri-apps/[email protected]':
resolution: {integrity: sha512-j6IA3pVBybSCwPpsihpX4z8bs6PluuGtr06ahL/xy4D8HunNBTmRmadJrFOQi0gOAbaig4MkQ15nzNLBLy8R1A==}
+ '@tauri-apps/[email protected]':
+ resolution: {integrity: sha512-0qsT/kvxQ6Ky4g6eQ4SUiHXzM4szTVc6thjz9vnGPYaApLoZrCJ9GdG+vEqeB+cT2dvE+wmxUFETh3ZXYVw8UA==}
+
'@tauri-apps/[email protected]':
resolution: {integrity: sha512-PV8zlSTmYfiN2xzILUmlDSEycS7UYbH2yXk/ZqF+qQU6/s+OVQvmSth4EhllFjcpvPbtqELvpzfjw+2qEouchA==}
@@ -14176,6 +14182,10 @@ snapshots:
dependencies:
'@tauri-apps/api': 2.0.3
+ '@tauri-apps/[email protected]':
+ dependencies:
+ '@tauri-apps/api': 2.0.3
+
'@tauri-apps/[email protected]':
dependencies:
'@tauri-apps/api': 2.0.0-rc.5