Skip to content

Commit

Permalink
release: 0.1.7 - Check for early testing version and reset permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
richiemcilroy committed Mar 24, 2024
1 parent 63bb1b9 commit 1a50b78
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "desktop",
"private": true,
"version": "0.1.6",
"version": "0.1.7",
"scripts": {
"dev": "tauri dev",
"build": "tsc && next build",
Expand Down
21 changes: 21 additions & 0 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ fn main() {
.expect("failed to reset screen permissions");
}

#[tauri::command]
fn reset_microphone_permissions() {
#[cfg(target_os = "macos")]
std::process::Command::new("tccutil")
.arg("reset")
.arg("Microphone")
.arg("so.cap.desktop")
.spawn()
.expect("failed to reset microphone permissions");
}

fn reset_camera_permissions() {
#[cfg(target_os = "macos")]
std::process::Command::new("tccutil")
.arg("reset")
.arg("Camera")
.arg("so.cap.desktop")
.spawn()
.expect("failed to reset camera permissions");
}

let _guard = sentry::init(("https://efd3156d9c0a8a49bee3ee675bec80d8@o4506859771527168.ingest.us.sentry.io/4506859844403200", sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "Cap",
"version": "0.1.6"
"version": "0.1.7"
},
"tauri": {
"allowlist": {
Expand Down
29 changes: 29 additions & 0 deletions apps/desktop/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@ export default function CameraPage() {
const [permissions, setPermissions] = useState(getPermissions());
const [permissionsLoaded, setPermissionsLoaded] = useState(false);

useEffect(() => {
const checkVersion = async () => {
const storedVersion = localStorage.getItem("cap_test_build_version");
const appVersion = await getVersion();

if (!storedVersion) {
console.log("No version stored");
localStorage.setItem("cap_test_build_version", appVersion);

if (localStorage.getItem("permissions")) {
await invoke("reset_screen_permissions");
await invoke("reset_camera_permissions");
await invoke("reset_microphone_permissions");
const permissions = JSON.parse(
localStorage.getItem("permissions") || "{}"
);
permissions.screen = false;
permissions.camera = false;
permissions.microphone = false;
permissions.confirmed = false;
localStorage.setItem("permissions", JSON.stringify(permissions));
toast.error("Early version detected - permissions have been reset.");
}
}
};

checkVersion();
}, []);

useEffect(() => {
const checkPermissions = setInterval(() => {
const updatedPermissions = getPermissions();
Expand Down
34 changes: 30 additions & 4 deletions apps/desktop/src/components/windows/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const Permissions = () => {

const checkScreenCapture = async () => {
const hasAccess = await invoke("has_screen_capture_access");
console.log("hasAccess", hasAccess);
if (hasAccess) {
await savePermissions("screen", true);
setPermissions((prev) => ({
Expand All @@ -31,15 +30,28 @@ export const Permissions = () => {
const checkCameraAccess = async () => {
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
// Assuming access is granted if the above line doesn't throw an error
await savePermissions("camera", true);
setPermissions((prev) => ({
...prev,
camera: true,
}));
// Stop using the camera after checking access
stream.getTracks().forEach((track) => track.stop());
} catch (error) {
navigator.permissions
.query({ name: "camera" as PermissionName })
.then((permissionStatus) => {
if (permissionStatus.state === "denied") {
console.log("Camera access denied");
} else {
permissionStatus.onchange = () => {
if (permissionStatus.state === "denied") {
console.log("Camera access denied");
} else {
checkCameraAccess();
}
};
}
});
console.log("Camera access denied");
}
};
Expand All @@ -53,9 +65,23 @@ export const Permissions = () => {
...prev,
microphone: true,
}));
// Stop using the microphone after checking access
stream.getTracks().forEach((track) => track.stop());
} catch (error) {
navigator.permissions
.query({ name: "microphone" as PermissionName })
.then((permissionStatus) => {
if (permissionStatus.state === "denied") {
console.log("Microphone access denied");
} else {
permissionStatus.onchange = () => {
if (permissionStatus.state === "denied") {
console.log("Microphone access denied");
} else {
checkMicrophoneAccess();
}
};
}
});
console.log("Microphone access denied");
}
};
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "0.1.6",
"version": "0.1.7",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

1 comment on commit 1a50b78

@vercel
Copy link

@vercel vercel bot commented on 1a50b78 Mar 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.