fixed unlimited creation of `openFile` listeners

feature/settings-window
Michael Ochmann 3 years ago
parent 610c7ebaee
commit 07451eadf2
  1. 13
      contextAPI.js
  2. 4
      src/ui/src/components/Ation.js

@ -2,8 +2,17 @@
const {contextBridge, ipcRenderer} = require("electron");
let fileOpenListener = null;
contextBridge.exposeInMainWorld("api", {
openFileDialog : () => ipcRenderer.send("WindowManager::openFileDialog"),
onFileOpen : callback => ipcRenderer.on("Ation::openFile", (_, presentation) => callback(presentation)),
openFile : filePath => ipcRenderer.send("WindowManager::openFile", filePath)
onFileOpen : callback => {
if (fileOpenListener)
ipcRenderer.off("Ation::openFile", fileOpenListener);
fileOpenListener = (_, presentation) => callback(presentation);
ipcRenderer.on("Ation::openFile", fileOpenListener);
},
openFile : filePath => ipcRenderer.send("WindowManager::openFile", filePath),
removeOnFileOpenListener : callback => ipcRenderer.off("Ation::openFile", callback)
});

@ -23,12 +23,12 @@ const Ation = () => {
const [newBasePath, slideDeck] = presentation;
if (!slideDeck)
return;
if (newBasePath !== basePath)
if (slide >= slideDeck.length)
setSlide(0);
setBasePath(newBasePath);
setDeck(slideDeck);
});
}, [basePath]);
}, [basePath, slide]);
const openFile = () => {
window.api.openFileDialog();

Loading…
Cancel
Save