Browse Source

fix save issue with ipcRenderer

b3z 8 months ago
parent
commit
e279c1359e
3 changed files with 7 additions and 5 deletions
  1. 2 1
      .vscode/settings.json
  2. 1 1
      index.html
  3. 4 3
      src/main.ts

+ 2 - 1
.vscode/settings.json

@@ -4,5 +4,6 @@
         "**/.project": true,
         "**/.settings": true,
         "**/.factorypath": true
-    }
+    },
+    "god.tsconfig": "./tsconfig.json"
 }

+ 1 - 1
index.html

@@ -8,7 +8,7 @@
   <meta charset="UTF-8">
   <title></title>
   <link rel="stylesheet" type="text/css" href="application.css">
-  <script src="./libs/require.js" type="text/javascript"></script>
+ <!---- <script src="./libs/require.js" type="text/javascript"></script>-->
   <!--<script> var exports = {}; </script>-->
 </head>
 

+ 4 - 3
src/main.ts

@@ -11,6 +11,7 @@ function createWindow() {
     height: 600,
     title: "ims",
     webPreferences: {
+      nodeIntegration: true, // with this set we have nodeIntegration in index.html. No need to use require.js anymore.
       preload: path.join(__dirname, "preload.js"),
     },
     width: 800,
@@ -141,9 +142,9 @@ function handlePrintHello() {
 
 // should execute js code in index.html so it send the value of the editor back to us.
 function handleSave() {
-  let code = `const electron = require('electron');
-    const {icpRenderer} = electron;
-    icpRenderer.send('item:save', document.querySelector('#editor').value);`;
+  let code = `
+  var { ipcRenderer } = require('electron');
+  ipcRenderer.send('item:save', document.querySelector("#editor").value);`
   
     mainWindow.webContents.executeJavaScript(code);
 }