Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop-gpui): add a Show Cap outcome after Instant recordings

Richie McIlroybcdc3478d991
diff --git a/apps/desktop-gpui/locales/de.toml b/apps/desktop-gpui/locales/de.toml
index d1ba2c5ba..cb71a925e 100644
--- a/apps/desktop-gpui/locales/de.toml
+++ b/apps/desktop-gpui/locales/de.toml
@@ -405,6 +405,8 @@ instant_copy_link = "Nur Link kopieren"
instant_copy_link_hint = "Nichts wird geöffnet"
instant_open_link = "Link öffnen"
instant_open_link_hint = "In Ihrem Browser"
+instant_show_cap = "Cap anzeigen"
+instant_show_cap_hint = "Zurück zum Rekorder"
saved_to_library = "In der Bibliothek gespeichert"
screenshot_copy = "Kopieren"
screenshot_copy_and_edit = "Kopieren und bearbeiten"
diff --git a/apps/desktop-gpui/locales/en.toml b/apps/desktop-gpui/locales/en.toml
index b5560c51a..a131b7e53 100644
--- a/apps/desktop-gpui/locales/en.toml
+++ b/apps/desktop-gpui/locales/en.toml
@@ -407,6 +407,8 @@ instant_copy_link = "Copy link only"
instant_copy_link_hint = "Nothing opens"
instant_open_link = "Open link"
instant_open_link_hint = "In your browser"
+instant_show_cap = "Show Cap"
+instant_show_cap_hint = "Back to the recorder"
saved_to_library = "Saved to library"
screenshot_copy = "Copy"
screenshot_copy_and_edit = "Copy and edit"
diff --git a/apps/desktop-gpui/locales/es.toml b/apps/desktop-gpui/locales/es.toml
index ef1f98c30..a7f14bdb9 100644
--- a/apps/desktop-gpui/locales/es.toml
+++ b/apps/desktop-gpui/locales/es.toml
@@ -405,6 +405,8 @@ instant_copy_link = "Solo copiar el enlace"
instant_copy_link_hint = "No se abre nada"
instant_open_link = "Abrir el enlace"
instant_open_link_hint = "En tu navegador"
+instant_show_cap = "Mostrar Cap"
+instant_show_cap_hint = "Volver a la grabadora"
saved_to_library = "Se guarda en la biblioteca"
screenshot_copy = "Copiar"
screenshot_copy_and_edit = "Copiar y editar"
diff --git a/apps/desktop-gpui/locales/fr.toml b/apps/desktop-gpui/locales/fr.toml
index 0b981c420..fc0ba2fb4 100644
--- a/apps/desktop-gpui/locales/fr.toml
+++ b/apps/desktop-gpui/locales/fr.toml
@@ -405,6 +405,8 @@ instant_copy_link = "Copier le lien seulement"
instant_copy_link_hint = "Rien ne s'ouvre"
instant_open_link = "Ouvrir le lien"
instant_open_link_hint = "Dans votre navigateur"
+instant_show_cap = "Afficher Cap"
+instant_show_cap_hint = "Retour à l'enregistreur"
saved_to_library = "Enregistré dans la bibliothèque"
screenshot_copy = "Copier"
screenshot_copy_and_edit = "Copier et modifier"
diff --git a/apps/desktop-gpui/locales/hi.toml b/apps/desktop-gpui/locales/hi.toml
index 8bff04092..cb8580cf6 100644
--- a/apps/desktop-gpui/locales/hi.toml
+++ b/apps/desktop-gpui/locales/hi.toml
@@ -405,6 +405,8 @@ instant_copy_link = "सिर्फ़ लिंक कॉपी करें"
instant_copy_link_hint = "कुछ नहीं खुलता"
instant_open_link = "लिंक खोलें"
instant_open_link_hint = "आपके ब्राउज़र में"
+instant_show_cap = "Cap दिखाएँ"
+instant_show_cap_hint = "रिकॉर्डर पर वापस"
saved_to_library = "लाइब्रेरी में सेव"
screenshot_copy = "कॉपी करें"
screenshot_copy_and_edit = "कॉपी और एडिट"
diff --git a/apps/desktop-gpui/locales/ja.toml b/apps/desktop-gpui/locales/ja.toml
index c2854b005..b399668f1 100644
--- a/apps/desktop-gpui/locales/ja.toml
+++ b/apps/desktop-gpui/locales/ja.toml
@@ -405,6 +405,8 @@ instant_copy_link = "リンクのコピーのみ"
instant_copy_link_hint = "何も開きません"
instant_open_link = "リンクを開く"
instant_open_link_hint = "ブラウザで"
+instant_show_cap = "Capを表示"
+instant_show_cap_hint = "レコーダーに戻る"
saved_to_library = "ライブラリに保存"
screenshot_copy = "コピー"
screenshot_copy_and_edit = "コピーして編集"
diff --git a/apps/desktop-gpui/locales/zh-CN.toml b/apps/desktop-gpui/locales/zh-CN.toml
index ecc9cadf5..74f089d80 100644
--- a/apps/desktop-gpui/locales/zh-CN.toml
+++ b/apps/desktop-gpui/locales/zh-CN.toml
@@ -405,6 +405,8 @@ instant_copy_link = "仅复制链接"
instant_copy_link_hint = "不打开任何内容"
instant_open_link = "打开链接"
instant_open_link_hint = "在浏览器中"
+instant_show_cap = "显示 Cap"
+instant_show_cap_hint = "回到录制器"
saved_to_library = "保存到资料库"
screenshot_copy = "复制"
screenshot_copy_and_edit = "复制并编辑"
diff --git a/apps/desktop-gpui/src/i18n/settings_surface_tests.rs b/apps/desktop-gpui/src/i18n/settings_surface_tests.rs
index 1d1cd608f..75b4ccc4e 100644
--- a/apps/desktop-gpui/src/i18n/settings_surface_tests.rs
+++ b/apps/desktop-gpui/src/i18n/settings_surface_tests.rs
@@ -363,6 +363,14 @@ fn settings_surfaces_match_the_literals_they_replaced() {
tr::settings::shortcuts::outcome::instant_open_link_hint(),
"In your browser",
),
+ (
+ tr::settings::shortcuts::outcome::instant_show_cap(),
+ "Show Cap",
+ ),
+ (
+ tr::settings::shortcuts::outcome::instant_show_cap_hint(),
+ "Back to the recorder",
+ ),
(
tr::settings::shortcuts::outcome::instant_copy_link(),
"Copy link only",
diff --git a/apps/desktop-gpui/src/settings_pages.rs b/apps/desktop-gpui/src/settings_pages.rs
index d7f73b1ed..25a792481 100644
--- a/apps/desktop-gpui/src/settings_pages.rs
+++ b/apps/desktop-gpui/src/settings_pages.rs
@@ -1023,10 +1023,10 @@ const STUDIO_OUTCOMES: [(store::PostStudioBehaviour, OutcomeOption); 3] = [
),
];
-/// `disableAutoOpenLinks`, phrased as what an Instant recording does.
-const INSTANT_OUTCOMES: [(bool, OutcomeOption); 2] = [
+/// [`store::PostInstantBehaviour`], phrased as what an Instant recording does.
+const INSTANT_OUTCOMES: [(store::PostInstantBehaviour, OutcomeOption); 3] = [
(
- false,
+ store::PostInstantBehaviour::OpenLink,
OutcomeOption {
icon: "icons/globe.svg",
label: tr::settings::shortcuts::outcome::instant_open_link,
@@ -1034,7 +1034,15 @@ const INSTANT_OUTCOMES: [(bool, OutcomeOption); 2] = [
},
),
(
- true,
+ store::PostInstantBehaviour::ShowCap,
+ OutcomeOption {
+ icon: "icons/app-window.svg",
+ label: tr::settings::shortcuts::outcome::instant_show_cap,
+ hint: tr::settings::shortcuts::outcome::instant_show_cap_hint,
+ },
+ ),
+ (
+ store::PostInstantBehaviour::CopyLink,
OutcomeOption {
icon: "icons/link.svg",
label: tr::settings::shortcuts::outcome::instant_copy_link,
@@ -1630,14 +1638,17 @@ impl SettingsWindow {
tr::settings::shortcuts::after_instant::hint(),
&INSTANT_OUTCOMES
.iter()
- .map(|(disabled, option)| {
- (*option, *disabled == self.settings.disable_auto_open_links)
+ .map(|(value, option)| {
+ (*option, *value == self.settings.post_instant_behaviour())
})
.collect::<Vec<_>>(),
|this, index, cx| {
- if let Some((disabled, _)) = INSTANT_OUTCOMES.get(index) {
- this.settings.disable_auto_open_links = *disabled;
- this.write_bool("disableAutoOpenLinks", *disabled, cx);
+ if let Some((value, _)) = INSTANT_OUTCOMES.get(index) {
+ let (disable_open, show_main) = value.store_values();
+ this.settings.disable_auto_open_links = disable_open;
+ this.settings.show_main_window_after_instant = show_main;
+ this.write_bool("disableAutoOpenLinks", disable_open, cx);
+ this.write_bool(store::SHOW_MAIN_WINDOW_AFTER_INSTANT_KEY, show_main, cx);
}
},
cx,
@@ -8547,12 +8558,13 @@ mod tests {
1
);
}
- for disabled in [false, true] {
+ for value in [
+ store::PostInstantBehaviour::OpenLink,
+ store::PostInstantBehaviour::ShowCap,
+ store::PostInstantBehaviour::CopyLink,
+ ] {
assert_eq!(
- INSTANT_OUTCOMES
- .iter()
- .filter(|(v, _)| *v == disabled)
- .count(),
+ INSTANT_OUTCOMES.iter().filter(|(v, _)| *v == value).count(),
1
);
}
diff --git a/apps/desktop-gpui/src/store.rs b/apps/desktop-gpui/src/store.rs
index 782e5fe91..8c1afdd07 100644
--- a/apps/desktop-gpui/src/store.rs
+++ b/apps/desktop-gpui/src/store.rs
@@ -1017,6 +1017,11 @@ pub struct GeneralSettings {
pub enable_notifications: bool,
pub instant_mode_max_resolution: u32,
pub disable_auto_open_links: bool,
+ /// GPUI-only `showMainWindowAfterInstantRecording`: whether the main
+ /// window comes back after an Instant recording whose link did not open.
+ /// Absent, it follows `disableAutoOpenLinks`, which is what "copy link
+ /// only" did before the key existed. See [`Self::post_instant_behaviour`].
+ pub show_main_window_after_instant: bool,
pub studio_recording_quality: StudioQuality,
pub recording_countdown: Option<u32>,
pub main_window_recording_start_behaviour: MainWindowStartBehaviour,
@@ -1059,6 +1064,30 @@ pub struct GeneralSettings {
pub studio_sound_by_default: bool,
}
+pub const SHOW_MAIN_WINDOW_AFTER_INSTANT_KEY: &str = "showMainWindowAfterInstantRecording";
+
+/// What follows a cleanly stopped Instant recording, the link always copied.
+/// Not one key: `disableAutoOpenLinks` (shared with the Tauri app) decides
+/// whether the link opens, `showMainWindowAfterInstantRecording` whether the
+/// main window comes back when it does not.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum PostInstantBehaviour {
+ OpenLink,
+ ShowCap,
+ CopyLink,
+}
+
+impl PostInstantBehaviour {
+ /// `(disableAutoOpenLinks, showMainWindowAfterInstantRecording)`.
+ pub fn store_values(self) -> (bool, bool) {
+ match self {
+ Self::OpenLink => (false, false),
+ Self::ShowCap => (true, true),
+ Self::CopyLink => (true, false),
+ }
+ }
+}
+
/// The section names, so the write calls read as the store keys they are.
pub const GENERAL_SETTINGS: &str = "general_settings";
pub const RECORDING_START_SAFETY: &str = "recording_start_safety";
@@ -1360,6 +1389,16 @@ impl Default for GeneralSettings {
}
impl GeneralSettings {
+ pub fn post_instant_behaviour(&self) -> PostInstantBehaviour {
+ if !self.disable_auto_open_links {
+ PostInstantBehaviour::OpenLink
+ } else if self.show_main_window_after_instant {
+ PostInstantBehaviour::ShowCap
+ } else {
+ PostInstantBehaviour::CopyLink
+ }
+ }
+
pub fn load() -> Self {
let store = cached_store(&tauri_store_path()).unwrap_or_default();
let empty = Map::new();
@@ -1383,6 +1422,11 @@ impl GeneralSettings {
enable_notifications: bool_at(general, "enableNotifications", true),
instant_mode_max_resolution: u32_at(general, "instantModeMaxResolution", 1920),
disable_auto_open_links: bool_at(general, "disableAutoOpenLinks", false),
+ show_main_window_after_instant: bool_at(
+ general,
+ SHOW_MAIN_WINDOW_AFTER_INSTANT_KEY,
+ bool_at(general, "disableAutoOpenLinks", false),
+ ),
studio_recording_quality: enum_at(general, "studioRecordingQuality"),
recording_countdown: opt_u32_at(general, "recordingCountdown"),
main_window_recording_start_behaviour: enum_at(
@@ -3358,4 +3402,49 @@ mod tests {
let cleared = GeneralSettings::from_sections(&general, &Map::new(), &Map::new());
assert!(cleared.excluded_windows.is_empty());
}
+
+ /// A store written before `showMainWindowAfterInstantRecording` keeps
+ /// what it did: "copy link only" brought the main window back, so it reads
+ /// as Show Cap; every outcome round-trips through its two keys.
+ #[test]
+ fn post_instant_behaviour_reads_old_stores_and_round_trips() {
+ let settings = |pairs: &[(&str, bool)]| {
+ let general = pairs
+ .iter()
+ .map(|(key, value)| (key.to_string(), Value::Bool(*value)))
+ .collect::<Map<_, _>>();
+ GeneralSettings::from_sections(&general, &Map::new(), &Map::new())
+ .post_instant_behaviour()
+ };
+ assert_eq!(settings(&[]), PostInstantBehaviour::OpenLink);
+ assert_eq!(
+ settings(&[("disableAutoOpenLinks", false)]),
+ PostInstantBehaviour::OpenLink
+ );
+ assert_eq!(
+ settings(&[("disableAutoOpenLinks", true)]),
+ PostInstantBehaviour::ShowCap
+ );
+ assert_eq!(
+ settings(&[
+ ("disableAutoOpenLinks", false),
+ (SHOW_MAIN_WINDOW_AFTER_INSTANT_KEY, true)
+ ]),
+ PostInstantBehaviour::OpenLink
+ );
+ for behaviour in [
+ PostInstantBehaviour::OpenLink,
+ PostInstantBehaviour::ShowCap,
+ PostInstantBehaviour::CopyLink,
+ ] {
+ let (disable_open, show_main) = behaviour.store_values();
+ assert_eq!(
+ settings(&[
+ ("disableAutoOpenLinks", disable_open),
+ (SHOW_MAIN_WINDOW_AFTER_INSTANT_KEY, show_main),
+ ]),
+ behaviour
+ );
+ }
+ }
}