A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: expose protected ipcRenderer to renderer process
thecodrr3a30d57ae816
diff --git a/apps/web/public/electron.js b/apps/web/public/electron.jsindex 4ad5bba70..5dfbce809 100644--- a/apps/web/public/electron.js+++ b/apps/web/public/electron.js@@ -1,10 +1,9 @@-const { app, BrowserWindow, protocol } = require("electron");+const { app, BrowserWindow, protocol, ipcMain } = require("electron");const { autoUpdater } = require("electron-updater");const path = require("path");const url = require("url");const os = require("os");const isDev = require("electron-is-dev");-try {require("electron-reloader")(module);} catch (_) {}@@ -18,6 +17,11 @@ async function createWindow() {__dirname,os.platform() === "win32" ? "app.ico" : "favicon-72x72.png"),+ webPreferences: {+ devTools: isDev,+ nodeIntegration: true,+ preload: __dirname + "/preload.js",+ },});if (isDev)@@ -69,3 +73,7 @@ app.on("activate", () => {createWindow();}});++ipcMain.on("fromRenderer", (event, ...args) => {+ console.log(event, ...args);+});diff --git a/apps/web/public/index.html b/apps/web/public/index.htmlindex 798588c2c..b61a1edd3 100644--- a/apps/web/public/index.html+++ b/apps/web/public/index.html@@ -2,6 +2,9 @@<html lang="en"><head><meta charset="utf-8" />+ <!-- https://electronjs.org/docs/tutorial+ /security#csp-meta-tag -->+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" /><linkrel="apple-touch-icon"sizes="180x180"diff --git a/apps/web/public/preload.js b/apps/web/public/preload.jsnew file mode 100644index 000000000..c2f72385b--- /dev/null+++ b/apps/web/public/preload.js@@ -0,0 +1,20 @@+const { contextBridge, ipcRenderer } = require("electron");++// Expose protected methods that allow the renderer process to use+// the ipcRenderer without exposing the entire object+contextBridge.exposeInMainWorld("api", {+ send: (channel, data) => {+ // whitelist channels+ let validChannels = ["fromRenderer"];+ if (validChannels.includes(channel)) {+ ipcRenderer.send(channel, data);+ }+ },+ receive: (channel, func) => {+ let validChannels = ["fromMain"];+ if (validChannels.includes(channel)) {+ // Deliberately strip event as it includes `sender`+ ipcRenderer.on(channel, (event, ...args) => func(...args));+ }+ },+});diff --git a/apps/web/src/index.js b/apps/web/src/index.jsindex 18073bb15..ca73af8e8 100644--- a/apps/web/src/index.js+++ b/apps/web/src/index.js@@ -14,7 +14,6 @@ initializeDatabase().then(() => {import("./App").then(({ default: App }) => {render(<App />, document.getElementById("root"), async () => {document.getElementById("splash").remove();-import("react-modal").then(({ default: Modal }) => {Modal.setAppElement("#root");});