5 changed files with 794 additions and 628 deletions
@ -1,77 +1,91 @@
|
||||
const { ipcRenderer } = require('electron'); |
||||
const { ipcRenderer } = require("electron"); |
||||
|
||||
let sourceList, contentList, typeButtons, shareButton, cancelButton, activeItem, activeTab = 'screen'; |
||||
let sourceList, |
||||
contentList, |
||||
typeButtons, |
||||
shareButton, |
||||
cancelButton, |
||||
activeItem, |
||||
activeTab = "screen"; |
||||
|
||||
const getItemDOM = item => { |
||||
const li = document.createElement('li'); |
||||
li.setAttribute('data-id', item.id); |
||||
const getItemDOM = (item) => { |
||||
const li = document.createElement("li"); |
||||
li.setAttribute("data-id", item.id); |
||||
li.innerHTML = `<div class="content"><div class="img-wrapper"><img src="${item.thumbnail}" /></div><span>${item.name}</span></div>`; |
||||
li.addEventListener('click', onItemClick, false); |
||||
li.addEventListener("click", onItemClick, false); |
||||
return li; |
||||
}; |
||||
|
||||
const updateTab = () => { |
||||
const sources = sourceList.filter(it => it.id.indexOf(activeTab) === 0); |
||||
contentList.innerHTML = ''; |
||||
sources.forEach(source => contentList.appendChild(getItemDOM(source))); |
||||
const sources = sourceList.filter((it) => it.id.indexOf(activeTab) === 0); |
||||
contentList.innerHTML = ""; |
||||
sources.forEach((source) => contentList.appendChild(getItemDOM(source))); |
||||
}; |
||||
|
||||
const bindTypeClick = () => { |
||||
typeButtons.forEach(it => it.addEventListener('click', onChangeType, false)); |
||||
typeButtons.forEach((it) => |
||||
it.addEventListener("click", onChangeType, false) |
||||
); |
||||
}; |
||||
|
||||
const bindActionsClick = () => { |
||||
shareButton.addEventListener('click', onShareClick, false); |
||||
cancelButton.addEventListener('click', onCancelClick, false); |
||||
shareButton.addEventListener("click", onShareClick, false); |
||||
cancelButton.addEventListener("click", onCancelClick, false); |
||||
}; |
||||
|
||||
const onChangeType = event => { |
||||
const onChangeType = (event) => { |
||||
event.preventDefault(); |
||||
if (!event.target.classList.contains('active')) { |
||||
if (!event.target.classList.contains("active")) { |
||||
activeTab = event.target.dataset.type; |
||||
typeButtons.forEach(it => it.classList.remove('active')); |
||||
event.target.classList.add('active'); |
||||
typeButtons.forEach((it) => it.classList.remove("active")); |
||||
event.target.classList.add("active"); |
||||
updateTab(); |
||||
} |
||||
}; |
||||
|
||||
const onItemClick = event => { |
||||
const onItemClick = (event) => { |
||||
event.preventDefault(); |
||||
if (!event.currentTarget.classList.contains('active')) { |
||||
if (!event.currentTarget.classList.contains("active")) { |
||||
activeItem = event.currentTarget.dataset.id; |
||||
document.querySelectorAll('.preview li').forEach(it => it.classList.remove('active')); |
||||
event.currentTarget.classList.add('active'); |
||||
document |
||||
.querySelectorAll(".preview li") |
||||
.forEach((it) => it.classList.remove("active")); |
||||
event.currentTarget.classList.add("active"); |
||||
changeShareState(); |
||||
} |
||||
}; |
||||
|
||||
const onCancelClick = event => { |
||||
const onCancelClick = (event) => { |
||||
event.preventDefault(); |
||||
ipcRenderer.send('screenShare:cancelSelection'); |
||||
ipcRenderer.send("screenShare:cancelSelection"); |
||||
}; |
||||
|
||||
const onShareClick = event => { |
||||
const onShareClick = (event) => { |
||||
event.preventDefault(); |
||||
if (activeItem) { |
||||
ipcRenderer.send('screenShare:selectScreen', activeItem); |
||||
ipcRenderer.send("screenShare:selectScreen", activeItem); |
||||
} |
||||
}; |
||||
|
||||
const changeShareState = () => { |
||||
if (shareButton.getAttribute('disabled') !== null) { |
||||
shareButton.removeAttribute('disabled'); |
||||
if (shareButton.getAttribute("disabled") !== null) { |
||||
shareButton.removeAttribute("disabled"); |
||||
} |
||||
}; |
||||
|
||||
window.addEventListener('load', async () => { |
||||
sourceList = await ipcRenderer.invoke('screenShare:getSources'); |
||||
window.addEventListener( |
||||
"load", |
||||
async () => { |
||||
sourceList = await ipcRenderer.invoke("screenShare:getSources"); |
||||
|
||||
contentList = document.querySelector('.preview'); |
||||
typeButtons = document.querySelectorAll('.type li'); |
||||
shareButton = document.querySelector('#share'); |
||||
cancelButton = document.querySelector('#cancel'); |
||||
contentList = document.querySelector(".preview"); |
||||
typeButtons = document.querySelectorAll(".type li"); |
||||
shareButton = document.querySelector("#share"); |
||||
cancelButton = document.querySelector("#cancel"); |
||||
|
||||
bindTypeClick(); |
||||
bindActionsClick(); |
||||
updateTab(); |
||||
}, false); |
||||
}, |
||||
false |
||||
); |
||||
|
Loading…
Reference in new issue