Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

os notifications + delay window showing

Brendan Allaneaa4f3945309
diff --git a/Cargo.lock b/Cargo.lock
index 375224379..d978865e4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -216,6 +216,30 @@ dependencies = [
"pin-project-lite",
]
+[[package]]
+name = "async-executor"
+version = "1.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "30ca9a001c1e8ba5149f91a74362376cc6bc5b919d92d988668657bd570bdcec"
+dependencies = [
+ "async-task",
+ "concurrent-queue",
+ "fastrand",
+ "futures-lite",
+ "slab",
+]
+
+[[package]]
+name = "async-fs"
+version = "2.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebcd09b382f40fcd159c2d695175b2ae620ffa5f3bd6f664131efff4e8b9e04a"
+dependencies = [
+ "async-lock",
+ "blocking",
+ "futures-lite",
+]
+
[[package]]
name = "async-io"
version = "2.3.4"
@@ -1574,6 +1598,7 @@ dependencies = [
"tauri-plugin-fs",
"tauri-plugin-global-shortcut",
"tauri-plugin-http",
+ "tauri-plugin-notification",
"tauri-plugin-oauth",
"tauri-plugin-os",
"tauri-plugin-process",
@@ -1622,6 +1647,16 @@ dependencies = [
"dirs-sys",
]
+[[package]]
+name = "dirs-next"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
+dependencies = [
+ "cfg-if 1.0.0",
+ "dirs-sys-next",
+]
+
[[package]]
name = "dirs-sys"
version = "0.4.1"
@@ -1634,6 +1669,17 @@ dependencies = [
"windows-sys 0.48.0",
]
+[[package]]
+name = "dirs-sys-next"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
+dependencies = [
+ "libc",
+ "redox_users",
+ "winapi",
+]
+
[[package]]
name = "dispatch"
version = "0.2.0"
@@ -3359,7 +3405,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [
"cfg-if 1.0.0",
- "windows-targets 0.48.5",
+ "windows-targets 0.52.6",
]
[[package]]
@@ -3476,6 +3522,19 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
+[[package]]
+name = "mac-notification-sys"
+version = "0.6.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dce8f34f3717aa37177e723df6c1fc5fb02b2a1087374ea3fe0ea42316dc8f91"
+dependencies = [
+ "cc",
+ "dirs-next",
+ "objc-foundation",
+ "objc_id",
+ "time",
+]
+
[[package]]
name = "mach2"
version = "0.4.2"
@@ -3913,6 +3972,19 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"
+[[package]]
+name = "notify-rust"
+version = "4.11.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5134a72dc570b178bff81b01e81ab14a6fcc015391ed4b3b14853090658cd3a3"
+dependencies = [
+ "log",
+ "mac-notification-sys",
+ "serde",
+ "tauri-winrt-notification",
+ "zbus",
+]
+
[[package]]
name = "ntapi"
version = "0.4.1"
@@ -4877,6 +4949,15 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
+[[package]]
+name = "quick-xml"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "quick-xml"
version = "0.32.0"
@@ -6465,6 +6546,25 @@ dependencies = [
"urlpattern 0.2.0",
]
+[[package]]
+name = "tauri-plugin-notification"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef492a2d19b6376bb4c9e0c4fab3f3bf8a220ea112d24f35027b737ff55de20c"
+dependencies = [
+ "log",
+ "notify-rust",
+ "rand 0.8.5",
+ "serde",
+ "serde_json",
+ "serde_repr",
+ "tauri",
+ "tauri-plugin",
+ "thiserror",
+ "time",
+ "url",
+]
+
[[package]]
name = "tauri-plugin-oauth"
version = "0.0.0-alpha.0"
@@ -6693,6 +6793,17 @@ dependencies = [
"toml 0.7.8",
]
+[[package]]
+name = "tauri-winrt-notification"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f89f5fb70d6f62381f5d9b2ba9008196150b40b75f3068eb24faeddf1c686871"
+dependencies = [
+ "quick-xml 0.31.0",
+ "windows 0.56.0",
+ "windows-version",
+]
+
[[package]]
name = "tempfile"
version = "3.12.0"
@@ -7527,8 +7638,8 @@ dependencies = [
"webview2-com-sys",
"windows 0.58.0",
"windows-core 0.58.0",
- "windows-implement",
- "windows-interface",
+ "windows-implement 0.58.0",
+ "windows-interface 0.58.0",
]
[[package]]
@@ -7754,6 +7865,16 @@ dependencies = [
"windows-targets 0.52.6",
]
+[[package]]
+name = "windows"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1de69df01bdf1ead2f4ac895dc77c9351aefff65b2f3db429a343f9cbf05e132"
+dependencies = [
+ "windows-core 0.56.0",
+ "windows-targets 0.52.6",
+]
+
[[package]]
name = "windows"
version = "0.58.0"
@@ -7804,19 +7925,42 @@ dependencies = [
"windows-targets 0.52.6",
]
+[[package]]
+name = "windows-core"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4698e52ed2d08f8658ab0c39512a7c00ee5fe2688c65f8c0a4f06750d729f2a6"
+dependencies = [
+ "windows-implement 0.56.0",
+ "windows-interface 0.56.0",
+ "windows-result 0.1.2",
+ "windows-targets 0.52.6",
+]
+
[[package]]
name = "windows-core"
version = "0.58.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99"
dependencies = [
- "windows-implement",
- "windows-interface",
+ "windows-implement 0.58.0",
+ "windows-interface 0.58.0",
"windows-result 0.2.0",
"windows-strings",
"windows-targets 0.52.6",
]
+[[package]]
+name = "windows-implement"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.85",
+]
+
[[package]]
name = "windows-implement"
version = "0.58.0"
@@ -7828,6 +7972,17 @@ dependencies = [
"syn 2.0.85",
]
+[[package]]
+name = "windows-interface"
+version = "0.56.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.85",
+]
+
[[package]]
name = "windows-interface"
version = "0.58.0"
@@ -8225,9 +8380,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b8e3d6ae3342792a6cc2340e4394334c7402f3d793b390d2c5494a4032b3030"
dependencies = [
"async-broadcast",
+ "async-executor",
+ "async-fs",
+ "async-io",
+ "async-lock",
"async-process",
"async-recursion",
+ "async-task",
"async-trait",
+ "blocking",
"derivative",
"enumflags2",
"event-listener",
diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml
index c42966c28..f505a8a16 100644
--- a/apps/desktop/src-tauri/Cargo.toml
+++ b/apps/desktop/src-tauri/Cargo.toml
@@ -30,6 +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-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/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 30c5c8a36..c7aca4d13 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -55,6 +55,7 @@ use std::{
};
use tauri::{AppHandle, Manager, Runtime, State, WindowEvent};
use tauri_nspanel::ManagerExt;
+use tauri_plugin_notification::NotificationExt;
use tauri_plugin_shell::ShellExt;
use tauri_specta::Event;
use tokio::task;
@@ -360,6 +361,10 @@ async fn start_recording(app: AppHandle, state: MutableState<'_, App>) -> Result
if let Some(window) = (CapWindow::InProgressRecording { position: None }).get(&app) {
window.eval("window.location.reload()").unwrap();
window.show().unwrap();
+ } else {
+ CapWindow::InProgressRecording { position: None }
+ .show(&app)
+ .ok();
}
AppSounds::StartRecording.play();
@@ -1470,16 +1475,16 @@ async fn remove_fake_window(
Ok(())
}
-#[tauri::command(async)]
-#[specta::specta]
-fn show_notifications_window(app: AppHandle) {
- if app.get_webview_window("notifications").is_some() {
- println!("notifications window already exists");
- return;
- }
+// #[tauri::command(async)]
+// #[specta::specta]
+// fn show_notifications_window(app: AppHandle) {
+// if app.get_webview_window("notifications").is_some() {
+// println!("notifications window already exists");
+// return;
+// }
- CapWindow::Notifications.show(&app).unwrap();
-}
+// CapWindow::Notifications.show(&app).unwrap();
+// }
#[tauri::command(async)]
#[specta::specta]
@@ -2345,7 +2350,7 @@ pub async fn run() {
list_capture_screens,
list_audio_devices,
show_previous_recordings_window,
- show_notifications_window,
+ // show_notifications_window,
close_previous_recordings_window,
set_fake_window_bounds,
remove_fake_window,
@@ -2437,6 +2442,7 @@ pub async fn run() {
.plugin(tauri_plugin_oauth::init())
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_updater::Builder::new().build())
+ .plugin(tauri_plugin_notification::init())
.plugin(flags::plugin::init())
.invoke_handler(specta_builder.invoke_handler())
.setup(move |app| {
@@ -2552,12 +2558,6 @@ pub async fn run() {
});
});
- let app_handle_clone = app_handle.clone();
- tauri::async_runtime::spawn(async move {
- tokio::time::sleep(Duration::from_secs(5)).await;
- AuthenticationInvalid.emit(&app_handle_clone).ok();
- });
-
let app_handle_clone = app_handle.clone();
AuthenticationInvalid::listen_any(app, move |_| {
let app_handle = app_handle_clone.clone();
diff --git a/apps/desktop/src-tauri/src/notifications.rs b/apps/desktop/src-tauri/src/notifications.rs
index aae036452..e1be37c8a 100644
--- a/apps/desktop/src-tauri/src/notifications.rs
+++ b/apps/desktop/src-tauri/src/notifications.rs
@@ -1,4 +1,5 @@
use crate::{AppSounds, NewNotification};
+use tauri_plugin_notification::NotificationExt;
use tauri_specta::Event;
pub enum NotificationType {
@@ -84,6 +85,13 @@ impl NotificationType {
pub fn send_notification(app: &tauri::AppHandle, notification_type: NotificationType) {
let (title, body, is_error) = notification_type.details();
+ app.notification()
+ .builder()
+ .title(title)
+ .body(body)
+ .show()
+ .ok();
+
println!(
"Sending notification: Title: '{}', Body: '{}', Error: {}",
title, body, is_error
@@ -91,10 +99,10 @@ pub fn send_notification(app: &tauri::AppHandle, notification_type: Notification
AppSounds::Notification.play();
- let _ = NewNotification {
- title: title.to_string(),
- body: body.to_string(),
- is_error,
- }
- .emit(app);
+ // let _ = NewNotification {
+ // title: title.to_string(),
+ // body: body.to_string(),
+ // is_error,
+ // }
+ // .emit(app);
}
diff --git a/apps/desktop/src/routes/(window-chrome).tsx b/apps/desktop/src/routes/(window-chrome).tsx
index 82919cbf7..a3a89eb9a 100644
--- a/apps/desktop/src/routes/(window-chrome).tsx
+++ b/apps/desktop/src/routes/(window-chrome).tsx
@@ -11,6 +11,10 @@ export const route = {
};
export default function (props: RouteSectionProps) {
+ onMount(() => {
+ if (location.pathname === "/") getCurrentWindow().show();
+ });
+
return (
<div class="rounded-[1.5rem] bg-gray-100 border border-gray-200 w-screen h-screen flex flex-col overflow-hidden">
<Header />
@@ -39,7 +43,7 @@ export default function (props: RouteSectionProps) {
function Inner(props: ParentProps) {
onMount(() => {
- getCurrentWindow().show();
+ if (location.pathname !== "/") getCurrentWindow().show();
});
return <>{props.children}</>;
diff --git a/apps/desktop/src/routes/(window-chrome)/index.tsx b/apps/desktop/src/routes/(window-chrome)/index.tsx
index 5cf87828f..60acc1db4 100644
--- a/apps/desktop/src/routes/(window-chrome)/index.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/index.tsx
@@ -73,7 +73,7 @@ export default function () {
onMount(async () => {
await commands.showPreviousRecordingsWindow();
- await commands.showNotificationsWindow();
+ // await commands.showNotificationsWindow();
});
const isRecording = () => !!currentRecording.data;
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index e9a4c1e35..8fca86e58 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -81,9 +81,6 @@ async listAudioDevices() : Promise<Result<string[], null>> {
async showPreviousRecordingsWindow() : Promise<void> {
await TAURI_INVOKE("show_previous_recordings_window");
},
-async showNotificationsWindow() : Promise<void> {
- await TAURI_INVOKE("show_notifications_window");
-},
async closePreviousRecordingsWindow() : Promise<void> {
await TAURI_INVOKE("close_previous_recordings_window");
},