-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathhtml.js
More file actions
46 lines (40 loc) · 1.22 KB
/
Copy pathhtml.js
File metadata and controls
46 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// const requireScript = require('node:module').createRequire(__filename);
// const { Application } = requireScript('../index.js');
const { Application } = require('../index.js');
const app = new Application();
const window = app.createBrowserWindow();
let count = 0;
const webview = window.createWebview({
html: `<!DOCTYPE html>
<html>
<head>
<title>Webview</title>
</head>
<body>
<h1 id="output">${count}</h1>
<button id="btn">Click me!</button>
<script>
btn.onclick = function send() {
window.ipc.postMessage('count');
}
</script>
</body>
</html>
`,
preload: `window.onIpcMessage = function(data) {
const output = document.getElementById('output');
output.innerText = \`\${data}\`;
return \`The current count is: \${data}\`
}`,
});
if (!webview.isDevtoolsOpen()) webview.openDevtools();
webview.onIpcMessage(() => {
webview.evaluateScriptWithCallback(`onIpcMessage("${++count}")`, (err, result) => {
if (err) {
console.error('Error evaluating script:', err);
} else {
console.log('[webview] >>', result);
}
});
});
app.run();