Created
September 9, 2024 13:15
-
-
Save VerteDinde/28e1411bc74df9e4e263b547b7a807e1 to your computer and use it in GitHub Desktop.
useSystemPicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<button id="startButton" class="button">Start</button> | |
<button id="stopButton" class="button">Stop</button> | |
<button id="pauseButton" class="button">Pause</button> | |
<video width="320" height="240" autoplay></video> | |
<script src="./renderer.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modules to control application life and create native browser window | |
const { app, BrowserWindow, desktopCapturer, session } = require('electron') | |
const path = require('node:path') | |
function createWindow () { | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
} | |
app.whenReady().then(() => { | |
createWindow() | |
session.defaultSession.setDisplayMediaRequestHandler((req, callback) => { | |
desktopCapturer.getSources({ types: ['screen', 'window'] }).then((sources) => { | |
callback({ video: sources[0] }) | |
}).catch((err) => { | |
console.log('Error: ', err); | |
}) | |
// If we should use the system picker | |
// Note: this is currently experimental | |
}, { useSystemPicker: true }) | |
// }) | |
app.on('activate', function () { | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "useSystemPicker", | |
"productName": "useSystemPicker", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "khammond", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "999.999.999" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', () => { | |
const replaceText = (selector, text) => { | |
const element = document.getElementById(selector) | |
if (element) element.innerText = text | |
} | |
for (const type of ['chrome', 'node', 'electron']) { | |
replaceText(`${type}-version`, process.versions[type]) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// renderer.js | |
const startButton = document.getElementById('startButton') | |
const stopButton = document.getElementById('stopButton') | |
const video = document.querySelector('video') | |
startButton.addEventListener('click', () => { | |
console.log('inside displayMedia') | |
navigator.mediaDevices.getDisplayMedia({ | |
audio: true, | |
video: { | |
width: 320, | |
height: 240, | |
frameRate: 30, | |
// displaySurface: 'no_preference' | |
} | |
}).then(stream => { | |
video.srcObject = stream; | |
video.onloadedmetadata = (e) => video.play(); | |
}).catch(e => console.log("Failed in getDisplayMedia", e)) | |
}) | |
pauseButton.addEventListener('click', () => { | |
video.pause() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment