fix: macos screen capture prompt

This commit is contained in:
2026-02-10 19:40:42 +01:00
parent d349b226aa
commit 84a9f6f8bd
6 changed files with 82 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ interface HeliumElectronAPI {
venmicLink: (options: VenmicLinkOptions) => Promise<boolean>;
venmicUnlink: () => Promise<boolean>;
checkScreenPermission: () => Promise<string>;
openScreenPermissionSettings: () => Promise<boolean>;
}
declare global {
@@ -212,6 +213,28 @@ export function useElectron() {
return platformInfo.value.supportsLoopbackAudio || platformInfo.value.supportsVenmic;
});
const getScreenPermissionStatus = async (): Promise<string> => {
if (!checkElectron()) return "granted";
try {
return await window.heliumElectron!.checkScreenPermission();
} catch (error) {
console.error("[useElectron] Failed to check screen permission:", error);
return "unknown";
}
};
const openScreenPermissionSettings = async (): Promise<boolean> => {
if (!checkElectron()) return false;
try {
return await window.heliumElectron!.openScreenPermissionSettings();
} catch (error) {
console.error("[useElectron] Failed to open screen permission settings:", error);
return false;
}
};
onMounted(() => {
checkElectron();
if (isElectron.value) {
@@ -246,9 +269,10 @@ export function useElectron() {
linkAllAudio,
linkAppAudio,
unlinkVenmicAudio,
getScreenPermissionStatus,
openScreenPermissionSettings,
startScreenShareWithAudio,
stopScreenShare,
};
}

View File

@@ -56,6 +56,7 @@
<script setup lang="ts">
import { useWebSocket } from "@vueuse/core";
import { toast } from "vue-sonner";
import { Button } from "@/components/ui/button";
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
@@ -66,6 +67,7 @@ import { useElectron } from "~/composables/useElectron";
import PresetSelect from "~/components/app/PresetSelect.vue";
const streamerStore = useStreamerStore();
const { t } = useI18n();
const videofeedRef = ref<HTMLVideoElement | null>(null);
const localStream = ref<MediaStream | null>(null);
const wsUrl = useWebSocketUrl();
@@ -83,6 +85,8 @@ const {
linkAllAudio,
linkAppAudio,
unlinkVenmicAudio,
getScreenPermissionStatus,
openScreenPermissionSettings,
} = useElectron();
onMounted(async () => {
@@ -231,6 +235,7 @@ async function startScreenShare() {
);
} catch (error) {
console.error("Failed to start screen share:", error);
await handleScreenShareError(error);
cleanupStreaming();
}
}
@@ -293,9 +298,36 @@ async function changeScreenShareSource() {
}
} catch (error) {
console.error("Failed to change screen share source:", error);
await handleScreenShareError(error);
}
}
async function handleScreenShareError(error: unknown): Promise<void> {
const isPermissionDeniedError =
error instanceof DOMException && error.name === "NotAllowedError";
if (!isPermissionDeniedError || !isElectron.value || !platformInfo.value?.isMac) {
toast.error(t("failedToStartScreenShare"));
return;
}
const permissionStatus = await getScreenPermissionStatus();
if (permissionStatus === "granted") {
toast.error(t("failedToStartScreenShare"));
return;
}
const openedSettings = await openScreenPermissionSettings();
if (openedSettings) {
toast.error(t("screenRecordingPermissionRequired"));
return;
}
toast.error(t("screenRecordingPermissionRequiredNoShortcut"));
}
async function cleanupStreaming() {
if (localStream.value) {
localStream.value.getTracks().forEach((track) => {