mirror of
https://github.com/SrIzan10/helium.git
synced 2026-06-06 00:56:58 +00:00
fix: macos screen capture prompt
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user