Skip to content

Commit

Permalink
chore: examples
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Nov 6, 2024
1 parent db9d597 commit 974d6ce
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ const { Application } = require('@webviewjs/webview');

const app = new Application();
const window = app.createBrowserWindow();
const webview = window.createWebview();

window.loadUrl('https://nodejs.org');
webview.loadUrl('https://nodejs.org');

app.run();
```
Expand All @@ -56,7 +57,8 @@ app.onIpcMessage((data) => {
window.evaluateScript(`onIpcMessage("${reply}")`);
});

const window = app.createBrowserWindow({
const window = app.createBrowserWindow();
const webview = window.createWebview({
html: `<!DOCTYPE html>
<html>
<head>
Expand Down
15 changes: 8 additions & 7 deletions examples/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
const { Application } = require('../index.js');

const app = new Application();
const window = app.createBrowserWindow();

app.onIpcMessage((data) => {
const reply = `You sent ${data.body.toString('utf-8')}`;
window.evaluateScript(`onIpcMessage("${reply}")`)
})

const window = app.createBrowserWindow({
const webview = window.createWebview({
html: `<!DOCTYPE html>
<html>
<head>
Expand All @@ -32,6 +28,11 @@ const window = app.createBrowserWindow({
}`
});

window.setTitle('WebviewJS + Node');
if (!webview.isDevtoolsOpen()) webview.openDevtools();

webview.onIpcMessage((data) => {
const reply = `You sent ${data.body.toString('utf-8')}`;
window.evaluateScript(`onIpcMessage("${reply}")`)
})

app.run();
5 changes: 3 additions & 2 deletions examples/http/webview.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ function createWindow() {

const app = new Application();
const window = app.createBrowserWindow();
const webview = window.createWebview();

if (!window.isDevtoolsOpen()) window.openDevtools();
window.loadUrl('http://localhost:3000');
if (!webview.isDevtoolsOpen()) webview.openDevtools();
webview.loadUrl('http://localhost:3000');

app.run();
}
4 changes: 2 additions & 2 deletions examples/multiple.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Application } from '../index.js'

const webview1 = new Application();

webview1.createBrowserWindow({ url: 'https://nodejs.org' });
webview1.createBrowserWindow().createWebview({ url: 'https://nodejs.org' });

const webview2 = new Application();
webview2.createBrowserWindow({ url: 'https://wikipedia.org' });
webview2.createBrowserWindow().createWebview({ url: 'https://wikipedia.org' });

await Promise.all([webview1.run(), webview2.run()]);
4 changes: 3 additions & 1 deletion examples/url.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Application, Theme } from '../index.js';

const app = new Application();
const window = app.createBrowserWindow({
const window = app.createBrowserWindow();

window.createWebview({
title: 'Hello world',
url: 'https://nodejs.org',
});
Expand Down

0 comments on commit 974d6ce

Please sign in to comment.