renderer.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // This file is required by the index.html file and will
  2. // be executed in the renderer process for that window.
  3. // No Node.js APIs are available in this process because
  4. // `nodeIntegration` is turned off. Use `preload.js` to
  5. // selectively enable features needed in the rendering
  6. // process.
  7. function centerVideo(){
  8. let wrapLoca = document.getElementById('wrap')
  9. wrapLoca.style.left = `calc(50vw - ${wrapLoca.offsetWidth / 2}px)`
  10. wrapLoca.style.top = `calc(50vh - ${wrapLoca.offsetHeight / 2}px)`
  11. localStorage.setItem('playerTop', wrapLoca.style.top);
  12. localStorage.setItem('playerLeft', wrapLoca.style.left);
  13. console.log("new location save", wrapLoca.style.left, wrapLoca.style.top)
  14. }
  15. function addVideo(){
  16. let emptyFlag = document.getElementById('emptyFlag')
  17. let playlist = document.getElementById('playlist')
  18. const dialogConfig = {
  19. title: 'Select a file',
  20. buttonLabel: 'This one will do',
  21. properties: ['openFile', 'multiSelections']
  22. };
  23. electron.openDialog('showOpenDialog', dialogConfig)
  24. .then( (result) => {
  25. console.log(result)
  26. console.log('urlPath video local', result?.filePaths[0])
  27. window.videoPlayer.src = result?.filePaths[0]
  28. window.videoPlayer.play()
  29. emptyFlag.style.display = "none"
  30. result?.filePaths.forEach( (source) => {
  31. let pathfull = source.split("/")
  32. let filename = pathfull[pathfull.length - 1]
  33. let videoNeo = document.createElement('li')
  34. let delButton = document.createElement('button')
  35. delButton.className = "delete is-small"
  36. delButton.onclick = (event) => {
  37. console.log("remove !!!")
  38. removeVideo(event.srcElement.parentNode)
  39. }
  40. videoNeo.innerHTML = `<span class="hand">::</span>${filename}`
  41. videoNeo.setAttribute("path", source);
  42. videoNeo.setAttribute("index", playlist.getElementsByTagName('li').length);
  43. videoNeo.appendChild(delButton)
  44. videoNeo.onclick = () => {
  45. videoPlayer.src = videoNeo.getAttribute('path')
  46. window.curVideo = videoNeo.getAttribute('index')
  47. window.videoPlayer.play()
  48. }
  49. playlist.appendChild(videoNeo)
  50. console.log("window.playlist", window.playlist);
  51. })
  52. })
  53. .catch( (err) => {console.log("err", err)})
  54. }
  55. function removeVideo(val) {
  56. var emptyFlag = document.getElementById('emptyFlag')
  57. var listElements = document.getElementById("playlist");
  58. listElements.removeChild(val);
  59. // If playlist is empty
  60. if (listElements.childElementCount == 1) {
  61. emptyFlag.style.display = "flex"
  62. window.videoPlayer.pause()
  63. window.videoPlayer.src = "./assets/preview.mp4";
  64. window.videoPlayer.play()
  65. }
  66. }