Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

'hide icon from dock' setting

Brendan Allan5e74656c54dd
diff --git a/apps/desktop/src-tauri/src/general_settings.rs b/apps/desktop/src-tauri/src/general_settings.rs
index fe04b3a47..8a1b58e1a 100644
--- a/apps/desktop/src-tauri/src/general_settings.rs
+++ b/apps/desktop/src-tauri/src/general_settings.rs
@@ -2,17 +2,19 @@ use serde::{Deserialize, Serialize};
use serde_json::json;
use specta::Type;
use std::sync::Mutex;
-use tauri::{AppHandle, Manager, Wry};
+use tauri::{AppHandle, Manager, Runtime, Wry};
use tauri_plugin_store::{with_store, StoreCollection};
#[derive(Serialize, Deserialize, Type, Default)]
pub struct GeneralSettingsStore {
pub upload_individual_files: bool,
pub open_editor_after_recording: bool,
+ #[serde(default)]
+ pub hide_dock_icon: bool,
}
impl GeneralSettingsStore {
- pub fn get(app: &AppHandle) -> Result<Option<Self>, String> {
+ pub fn get(app: &AppHandle<Wry>) -> Result<Option<Self>, String> {
println!("Attempting to get GeneralSettingsStore");
let stores = app
.try_state::<StoreCollection<Wry>>()
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 51e04e27b..25eea8d20 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -2254,6 +2254,8 @@ pub async fn run() {
let (camera_tx, camera_rx) = watch::channel(None);
let camera_ws_port = camera::create_camera_ws(camera_rx.clone()).await;
+ tauri::async_runtime::set(tokio::runtime::Handle::current());
+
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.plugin(tauri_nspanel::init())
@@ -2403,6 +2405,39 @@ pub async fn run() {
});
}
}
+
+ let app = window.app_handle();
+
+ match event {
+ WindowEvent::Destroyed => {
+ if window.label() == "main" {
+ if let Some(w) = app.get_webview_window(camera::WINDOW_LABEL) {
+ w.close().ok();
+ }
+ }
+
+ if let Some(settings) = GeneralSettingsStore::get(app).unwrap() {
+ if settings.hide_dock_icon
+ && app
+ .webview_windows()
+ .keys()
+ .all(|label| !window_activates_dock(label))
+ {
+ #[cfg(target_os = "macos")]
+ app.set_activation_policy(tauri::ActivationPolicy::Accessory)
+ .ok();
+ }
+ }
+ }
+ WindowEvent::Focused(focused) if *focused => {
+ if window_activates_dock(label) {
+ #[cfg(target_os = "macos")]
+ app.set_activation_policy(tauri::ActivationPolicy::Regular)
+ .ok();
+ }
+ }
+ _ => {}
+ }
})
.build(tauri::generate_context!())
.expect("error while running tauri application")
@@ -2413,6 +2448,10 @@ pub async fn run() {
});
}
+fn window_activates_dock(label: &str) -> bool {
+ label == "main" || label.starts_with("editor-") || label == "settings"
+}
+
type EditorInstancesState = Arc<Mutex<HashMap<String, Arc<EditorInstance>>>>;
pub async fn remove_editor_instance(
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
index d58986482..2a08867f9 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
@@ -16,6 +16,12 @@ const settingsList = [
description:
"The editor will be shown immediately after you finish recording.",
},
+ {
+ key: "hide_dock_icon",
+ label: "Hide dock icon",
+ description:
+ "The dock icon will be hidden when there are no windows available to close.",
+ },
];
export default function GeneralSettings() {
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 8e3059b2b..eb02a2f8d 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -375,7 +375,7 @@ export type CursorType = "pointer" | "circle"
export type Display = { path: string }
export type DisplaySource = { variant: "screen" } | { variant: "window"; bounds: Bounds }
export type EditorStateChanged = { playhead_position: number }
-export type GeneralSettingsStore = { upload_individual_files: boolean; open_editor_after_recording: boolean }
+export type GeneralSettingsStore = { upload_individual_files: boolean; open_editor_after_recording: boolean; hide_dock_icon?: 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 }