180 lines
4.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
content="script-src 'self' 'unsafe-inline';"
/>
<title>Screen Sharing Selection</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
padding: 20px;
}
h1 {
font-size: 24px;
}
#list-of-screens {
/* display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-gap: 10px;
justify-items: center;
align-items: start;
margin: 20px 0; */
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 16px; /* Adjust the gap as needed for spacing */
align-items: stretch; /* Makes all rows the same height */
/* Additional styling for the grid container */
padding: 16px;
background-color: #f0f0f0;
}
.screen-item {
border: 1px solid #ccc;
padding: 10px;
cursor: pointer;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transition: background-color 0.3s, border-color 0.3s;
}
.screen-item:hover {
background-color: #f5f5f5;
}
.screen-item img {
max-width: 100px;
max-height: 100px;
margin-bottom: 10px;
}
.screen-item span {
padding: 10px;
font-weight: bold;
text-align: center;
}
#footer {
position: fixed;
bottom: 0;
width: 95%;
height: 50px;
background: #f0f0f0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 0px;
}
#share-btn,
#cancel-btn {
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
#share-btn {
background-color: #007bff;
}
#cancel-btn {
background-color: rgb(151, 28, 28);
}
.screen-name {
font-weight: bold;
}
</style>
</head>
<body>
<h1>Select a Screen to Share</h1>
<div id="list-of-screens"></div>
<div id="footer">
<button id="cancel-btn" onclick="cancelSelection()">Cancel</button>
<button id="share-btn" onclick="sendScreenSelection()" disabled>
Share Screen
</button>
</div>
</body>
<script>
// Define arrays to store available screens and HTML elements
var availableScreens = [];
var htmlElements = [];
var selectedElement;
// Import required Electron modules
const desktopCapturer = require('@electron/remote').desktopCapturer;
const ipcRenderer = require('electron').ipcRenderer;
// Call Electron API to list all available screens
desktopCapturer
.getSources({
types: ['window', 'screen'],
})
.then(async (sources) => {
const list = document.getElementById('list-of-screens');
sources.forEach((source) => {
// Add new element to the list with the thumbnail of the screen
var el = document.createElement('div');
el.className = 'screen-item';
el.onclick = () => {
// Style the new selected screen and store it as the current selection
htmlElements.forEach((e) => {
e.style.border = 'none';
e.style.background = 'none';
});
el.style.border = '2px solid #0088aa';
el.style.background = 'rgba(0, 0, 0, 0.06)';
selectedElement = el;
document.getElementById('share-btn').disabled = false;
};
// Store the new source and the new created HTML element
availableScreens.push(source);
htmlElements.push(el);
var img = document.createElement('img');
var name = document.createElement('span');
img.src = source.thumbnail.toDataURL();
name.innerHTML = source.name;
img.style.width = '100px';
img.style.height = '100px';
// Append new elements to the template
el.appendChild(img);
el.appendChild(name);
list.appendChild(el);
});
});
function sendScreenSelection() {
ipcRenderer.send(
'screen-share-selected',
availableScreens[htmlElements.indexOf(selectedElement)].id
);
closeWindow();
}
function cancelSelection() {
ipcRenderer.send('screen-share-selected', undefined);
closeWindow();
}
function closeWindow() {
require('@electron/remote').getCurrentWindow().close();
}
</script>
</html>