-
Notifications
You must be signed in to change notification settings - Fork 18
/
webview.js
40 lines (30 loc) · 1 KB
/
webview.js
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
// npm run build && npm run prepare && RUST_BACKTRACE=1 node examples/webview.js
// npm run build && npm run prepare && RUST_BACKTRACE=1 deno run -A --unstable examples/webview.js
import { App, AppWindow, WebView } from '../lib/index.js'
const app = await App.init()
const w = new AppWindow()
const HTML = `
<style>
body { font-family: sans-serif }
</style>
<h1>WebView <span id="time"></span></h1>
<p>
Useful for external sign-in and for showing web content. You can also
start your own web-server and point it there if you want. Or pass HTML in
data url like here.
</p>
<a href="https://excalidraw.com/">Excalidraw</a>
<a href="https://vole.wtf/kilobytes-gambit/">Kilobyte's gambit</a>
`
const webview = new WebView()
webview.attach(w)
webview.loadURL(`data:text/html,${encodeURIComponent(HTML)}`)
// TODO: events
setInterval(
() =>
webview.eval(
`document.querySelector('#time').innerHTML = ${JSON.stringify(new Date().toLocaleTimeString())}`
),
1000
)
app.run()