Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Hide the main window instead of quitting the app

Ilya406830c24924
diff --git a/apps/desktop/src-tauri/capabilities/migrated.json b/apps/desktop/src-tauri/capabilities/migrated.json
index d39dbac1a..e169e27f0 100644
--- a/apps/desktop/src-tauri/capabilities/migrated.json
+++ b/apps/desktop/src-tauri/capabilities/migrated.json
@@ -6,6 +6,8 @@
"permissions": [
"core:default",
"core:window:allow-close",
+ "core:window:allow-hide",
+ "core:window:allow-show",
"core:window:allow-center",
"core:window:allow-minimize",
"core:window:allow-unminimize",
diff --git a/apps/desktop/src-tauri/gen/schemas/capabilities.json b/apps/desktop/src-tauri/gen/schemas/capabilities.json
index 80a1f4157..2e3da0d28 100644
--- a/apps/desktop/src-tauri/gen/schemas/capabilities.json
+++ b/apps/desktop/src-tauri/gen/schemas/capabilities.json
@@ -1 +1 @@
-{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main","camera"],"permissions":["core:default","core:window:allow-close","core:window:allow-center","core:window:allow-minimize","core:window:allow-unminimize","core:window:allow-maximize","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-start-dragging","core:window:allow-set-position","core:webview:allow-create-webview-window","shell:default","fs:allow-read-text-file","fs:allow-resource-read-recursive","fs:default","decorum:allow-show-snap-overlay","os:default"]}}
\ No newline at end of file
+{"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main","camera"],"permissions":["core:default","core:window:allow-close","core:window:allow-hide","core:window:allow-show","core:window:allow-center","core:window:allow-minimize","core:window:allow-unminimize","core:window:allow-maximize","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-start-dragging","core:window:allow-set-position","core:webview:allow-create-webview-window","shell:default","fs:allow-read-text-file","fs:allow-resource-read-recursive","fs:default","decorum:allow-show-snap-overlay","os:default"]}}
\ No newline at end of file
diff --git a/apps/desktop/src/components/WindowActions.tsx b/apps/desktop/src/components/WindowActions.tsx
index ad9fd9d48..b4993654d 100644
--- a/apps/desktop/src/components/WindowActions.tsx
+++ b/apps/desktop/src/components/WindowActions.tsx
@@ -18,7 +18,7 @@ export const WindowActions = () => {
window.fathom.trackEvent("exit_clicked");
}
tauriWindow.then(({ getCurrentWindow }) => {
- getCurrentWindow().close();
+ getCurrentWindow().hide();
});
}}
className={`bg-red-500 hover:bg-red-700 transition-all ${actionButtonBase}`}
diff --git a/apps/desktop/src/components/windows/inner/Recorder.tsx b/apps/desktop/src/components/windows/inner/Recorder.tsx
index 7b58e8869..45a2f5aa1 100644
--- a/apps/desktop/src/components/windows/inner/Recorder.tsx
+++ b/apps/desktop/src/components/windows/inner/Recorder.tsx
@@ -133,14 +133,16 @@ export const Recorder = () => {
useEffect(() => {
let unlisten: UnlistenFn | null = null;
const setup = async () => {
- unlisten = await listen<void>("cap://tray/clicked", (_) => {
+ unlisten = await listen<void>("cap://tray/clicked", async (_) => {
if (isRecording) {
- handleStopAllRecordings();
- } else {
- tauriWindow.then(({ getAllWindows }) =>
- getAllWindows().forEach((window) => window.setFocus())
- );
+ await handleStopAllRecordings();
}
+
+ tauriWindow.then(({ getAllWindows }) =>
+ getAllWindows().forEach((window) => {
+ window.show();
+ })
+ );
});
};
setup();
diff --git a/apps/desktop/src/utils/tray.ts b/apps/desktop/src/utils/tray.ts
index 6666006ce..e359c2492 100644
--- a/apps/desktop/src/utils/tray.ts
+++ b/apps/desktop/src/utils/tray.ts
@@ -7,8 +7,8 @@ import {
} from "@tauri-apps/api/menu";
import { TrayIcon } from "@tauri-apps/api/tray";
import { emit } from "@tauri-apps/api/event";
-import { WebviewWindow } from "@tauri-apps/api/webviewWindow";
import { Device, DeviceKind } from "./recording/MediaDeviceContext";
+import { Window } from "@tauri-apps/api/window";
const TRAY_ID = "cap_main";
const TRAY_ICON_DEFAULT = "icons/tray-default-icon.png";
@@ -81,7 +81,7 @@ export const setTrayMenu = async (
await MenuItem.new({
text: "Show",
action: () => {
- WebviewWindow.getByLabel("main")?.setFocus();
+ Window.getCurrent()?.show();
},
}),
await PredefinedMenuItem.new({