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"); const {contextBridge, ipcRenderer} = require("electron");
let fileOpenListener = null;
contextBridge.exposeInMainWorld("api", { contextBridge.exposeInMainWorld("api", {
openFileDialog : () => ipcRenderer.send("WindowManager::openFileDialog"), openFileDialog : () => ipcRenderer.send("WindowManager::openFileDialog"),
onFileOpen : callback => ipcRenderer.on("Ation::openFile", (_, presentation) => callback(presentation)), onFileOpen : callback => {
openFile : filePath => ipcRenderer.send("WindowManager::openFile", filePath) 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; const [newBasePath, slideDeck] = presentation;
if (!slideDeck) if (!slideDeck)
return; return;
if (newBasePath !== basePath) if (slide >= slideDeck.length)
setSlide(0); setSlide(0);
setBasePath(newBasePath); setBasePath(newBasePath);
setDeck(slideDeck); setDeck(slideDeck);
}); });
}, [basePath]); }, [basePath, slide]);
const openFile = () => { const openFile = () => {
window.api.openFileDialog(); window.api.openFileDialog();

Loading…
Cancel
Save