Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Append default excluded windows; show UI warning

Richie McIlroy0defe618a946
diff --git a/apps/desktop/src-tauri/src/general_settings.rs b/apps/desktop/src-tauri/src/general_settings.rs
index d96b1cb32..2c31abf20 100644
--- a/apps/desktop/src-tauri/src/general_settings.rs
+++ b/apps/desktop/src-tauri/src/general_settings.rs
@@ -109,6 +109,19 @@ pub fn default_excluded_windows() -> Vec<WindowExclusion> {
.collect()
}
+fn append_missing_default_excluded_windows(excluded_windows: &mut Vec<WindowExclusion>) -> bool {
+ let mut changed = false;
+
+ for default in default_excluded_windows() {
+ if !excluded_windows.contains(&default) {
+ excluded_windows.push(default);
+ changed = true;
+ }
+ }
+
+ changed
+}
+
// When adding fields here, #[serde(default)] defines the value to use for existing configurations,
// and `Default::default` defines the value to use for new configurations.
// Things that affect the user experience should only be enabled by default for new configurations.
@@ -360,7 +373,7 @@ fn sync_dock_visibility_on_general_settings_change(app: &AppHandle) {
pub fn init(app: &AppHandle) {
println!("Initializing GeneralSettingsStore");
- let store = match GeneralSettingsStore::get(app) {
+ let mut store = match GeneralSettingsStore::get(app) {
Ok(Some(store)) => store,
Ok(None) => GeneralSettingsStore::default(),
Err(e) => {
@@ -369,6 +382,7 @@ pub fn init(app: &AppHandle) {
}
};
+ append_missing_default_excluded_windows(&mut store.excluded_windows);
crate::posthog::set_telemetry_enabled(store.enable_telemetry);
register_bundled_muxer_binary(app);
@@ -428,3 +442,52 @@ fn bundled_muxer_bin_name() -> &'static str {
pub fn get_default_excluded_windows() -> Vec<WindowExclusion> {
default_excluded_windows()
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn title_exclusion(title: &str) -> WindowExclusion {
+ WindowExclusion {
+ bundle_identifier: None,
+ owner_name: None,
+ window_title: Some(title.to_string()),
+ }
+ }
+
+ #[test]
+ fn appends_missing_default_excluded_windows() {
+ let mut excluded_windows = vec![
+ title_exclusion("Cap"),
+ WindowExclusion {
+ bundle_identifier: None,
+ owner_name: Some("Preview".to_string()),
+ window_title: Some("Private Preview".to_string()),
+ },
+ ];
+
+ let changed = append_missing_default_excluded_windows(&mut excluded_windows);
+
+ assert!(changed);
+ assert!(
+ default_excluded_windows()
+ .iter()
+ .all(|default| excluded_windows.contains(default))
+ );
+ assert!(excluded_windows.iter().any(|entry| {
+ entry.owner_name.as_deref() == Some("Preview")
+ && entry.window_title.as_deref() == Some("Private Preview")
+ }));
+ }
+
+ #[test]
+ fn does_not_duplicate_default_excluded_windows() {
+ let mut excluded_windows = default_excluded_windows();
+ let len = excluded_windows.len();
+
+ let changed = append_missing_default_excluded_windows(&mut excluded_windows);
+
+ assert!(!changed);
+ assert_eq!(excluded_windows.len(), len);
+ }
+}
diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
index e4e52d5e6..2d8a5256c 100644
--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx
@@ -41,6 +41,7 @@ import {
type StudioRecordingQuality,
type WindowExclusion,
} from "~/utils/tauri";
+import IconLucideAlertTriangle from "~icons/lucide/alert-triangle";
import IconLucidePlus from "~icons/lucide/plus";
import IconLucideX from "~icons/lucide/x";
import {
@@ -75,6 +76,34 @@ const getWindowOptionLabel = (window: CaptureWindow) => {
return parts.join(" • ");
};
+const isSameExclusion = (a: WindowExclusion, b: WindowExclusion) =>
+ (a.bundleIdentifier ?? null) === (b.bundleIdentifier ?? null) &&
+ (a.ownerName ?? null) === (b.ownerName ?? null) &&
+ (a.windowTitle ?? null) === (b.windowTitle ?? null);
+
+const coversDefaultExclusion = (
+ entry: WindowExclusion,
+ defaultEntry: WindowExclusion,
+) => {
+ if (isSameExclusion(entry, defaultEntry)) return true;
+ if (
+ defaultEntry.windowTitle &&
+ entry.windowTitle === defaultEntry.windowTitle
+ ) {
+ return true;
+ }
+ if (
+ defaultEntry.bundleIdentifier &&
+ entry.bundleIdentifier === defaultEntry.bundleIdentifier
+ ) {
+ return true;
+ }
+ if (defaultEntry.ownerName && entry.ownerName === defaultEntry.ownerName) {
+ return !entry.windowTitle || entry.windowTitle === defaultEntry.windowTitle;
+ }
+ return false;
+};
+
type ExtendedGeneralSettingsStore = GeneralSettingsStore;
const MAX_FPS_OPTIONS = [
@@ -237,6 +266,12 @@ function Inner(props: { initialStore: GeneralSettingsStore | null }) {
initialValue: [] as CaptureWindow[],
},
);
+ const [defaultExcludedWindows] = createResource(
+ () => commands.getDefaultExcludedWindows(),
+ {
+ initialValue: [] as WindowExclusion[],
+ },
+ );
const handleChange = async <K extends keyof typeof settings>(
key: K,
@@ -257,6 +292,14 @@ function Inner(props: { initialStore: GeneralSettingsStore | null }) {
const ostype: OsType = type();
const excludedWindows = createMemo(() => settings.excludedWindows ?? []);
+ const missingDefaultExclusions = createMemo(() =>
+ defaultExcludedWindows().filter(
+ (defaultEntry) =>
+ !excludedWindows().some((entry) =>
+ coversDefaultExclusion(entry, defaultEntry),
+ ),
+ ),
+ );
const matchesExclusion = (
exclusion: WindowExclusion,
@@ -593,6 +636,7 @@ function Inner(props: { initialStore: GeneralSettingsStore | null }) {
<ExcludedWindowsCard
excludedWindows={excludedWindows()}
+ missingDefaultExclusions={missingDefaultExclusions()}
availableWindows={availableWindows()}
onRequestAvailableWindows={refreshAvailableWindows}
onRemove={handleRemoveExclusion}
@@ -1056,6 +1100,7 @@ function DefaultProjectNameCard(props: {
function ExcludedWindowsCard(props: {
excludedWindows: WindowExclusion[];
+ missingDefaultExclusions: WindowExclusion[];
availableWindows: CaptureWindow[];
onRequestAvailableWindows: () => Promise<CaptureWindow[]>;
onRemove: (index: number) => Promise<void>;
@@ -1065,7 +1110,15 @@ function ExcludedWindowsCard(props: {
isWindows: boolean;
}) {
const hasExclusions = () => props.excludedWindows.length > 0;
+ const hasMissingDefaultExclusions = () =>
+ props.missingDefaultExclusions.length > 0;
+ const missingDefaultLabels = () =>
+ props.missingDefaultExclusions.map(getExclusionPrimaryLabel).join(", ");
const canAdd = () => !props.isLoading;
+ const handleResetClick = () => {
+ if (props.isLoading) return;
+ void props.onReset();
+ };
const handleAddClick = async (event: MouseEvent) => {
event.preventDefault();
@@ -1134,10 +1187,7 @@ function ExcludedWindowsCard(props: {
variant="gray"
size="sm"
disabled={props.isLoading}
- onClick={() => {
- if (props.isLoading) return;
- void props.onReset();
- }}
+ onClick={handleResetClick}
>
Reset
</Button>
@@ -1155,6 +1205,31 @@ function ExcludedWindowsCard(props: {
}
>
<SectionCard padded>
+ <Show when={hasMissingDefaultExclusions()}>
+ <div class="mb-3 rounded-lg border border-amber-6 bg-amber-3/30 px-3 py-2.5">
+ <div class="flex items-start gap-2">
+ <IconLucideAlertTriangle class="mt-0.5 size-4 shrink-0 text-amber-11" />
+ <div class="min-w-0 flex-1 space-y-1">
+ <p class="text-xs font-medium text-amber-11">
+ Recommended Cap windows are not excluded
+ </p>
+ <p class="text-[10px] leading-snug text-amber-11">
+ Camera, settings, or recording windows can appear as black
+ boxes in screen recordings. Missing: {missingDefaultLabels()}.
+ </p>
+ </div>
+ <Button
+ variant="gray"
+ size="sm"
+ disabled={props.isLoading}
+ onClick={handleResetClick}
+ class="shrink-0"
+ >
+ Restore
+ </Button>
+ </div>
+ </div>
+ </Show>
<Show when={!props.isLoading} fallback={<ExcludedWindowsSkeleton />}>
<Show
when={hasExclusions()}