From 4bac2b054216a68579a20d4e7e9ca8cf8bfd1cb6 Mon Sep 17 00:00:00 2001 From: Sneed Group Holder Date: Mon, 25 Nov 2024 14:26:46 -0600 Subject: [PATCH] add webcam button --- index.html | 1 + main.js | 4 +--- preload.js | 8 +++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 2ec69f4..7020ce4 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ +
diff --git a/main.js b/main.js index d4e4d32..cda1859 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,5 @@ // Modules to control application life and create native browser window -const {app, BrowserWindow, session, ipcMain, systemPreferences} = require('electron') +const {app, BrowserWindow, session, ipcMain} = require('electron') const path = require('path') const fetch = require("cross-fetch") const { ElectronChromeExtensions } = require('electron-chrome-extensions') @@ -239,6 +239,4 @@ app.on('ready', () => { 'https://cloudflare-dns.com/dns-query' ] }); - mic = systemPreferences.askForMediaAccess('microphone'); - cam = systemPreferences.askForMediaAccess('camera'); }); \ No newline at end of file diff --git a/preload.js b/preload.js index 533ea12..358888c 100644 --- a/preload.js +++ b/preload.js @@ -6,7 +6,7 @@ * https://www.electronjs.org/docs/latest/tutorial/sandbox */ -const { contextBridge, ipcRenderer } = require('electron'); +const { contextBridge, ipcRenderer, systemPreferences } = require('electron'); contextBridge.exposeInMainWorld('electron', { enforceDomainRestrictions: (url) => ipcRenderer.sendSync('check-domain', url), @@ -31,4 +31,10 @@ window.addEventListener('DOMContentLoaded', () => { makeWindowButton.addEventListener('click', () => { ipcRenderer.send('windowmaker', 'ping') }) + + const camButton = document.getElementById('camBtn'); + camButton.addEventListener('click', () => { + mic = systemPreferences.askForMediaAccess('microphone'); + cam = systemPreferences.askForMediaAccess('camera'); + }) })