11<!DOCTYPE html>
22< html >
3+ < head >
4+ < style >
5+ # response {
6+ white-space : pre-wrap;
7+ }
8+ </ style >
9+ </ head >
310
4- < head >
5- < style >
6- # response {
7- white-space : pre-wrap;
8- }
9- </ style >
10- </ head >
11+ < body >
12+ < div id ="window-label "> </ div >
13+ < div id ="container "> </ div >
14+ < div id ="response "> </ div >
1115
12- < body >
13- < div id ="window-label "> </ div >
14- < div id ="container "> </ div >
15- < div id ="response "> </ div >
16+ < script >
17+ var WebviewWindow = window . __TAURI__ . window . WebviewWindow
18+ var appWindow = window . __TAURI__ . window . appWindow
19+ var windowLabel = appWindow . label
20+ var windowLabelContainer = document . getElementById ( 'window-label' )
21+ windowLabelContainer . innerText = 'This is the ' + windowLabel + ' window.'
1622
17- < script >
18- var WebviewWindow = window . __TAURI__ . window . WebviewWindow
19- var appWindow = window . __TAURI__ . window . appWindow
20- var windowLabel = appWindow . label
21- var windowLabelContainer = document . getElementById ( 'window-label' )
22- windowLabelContainer . innerText = 'This is the ' + windowLabel + ' window.'
23+ var container = document . getElementById ( 'container' )
2324
24- var container = document . getElementById ( 'container' )
25+ function createWindowMessageBtn ( label ) {
26+ var tauriWindow = WebviewWindow . getByLabel ( label )
27+ var button = document . createElement ( 'button' )
28+ button . innerText = 'Send message to ' + label
29+ button . addEventListener ( 'click' , function ( ) {
30+ tauriWindow . emit ( 'clicked' , 'message from ' + windowLabel )
31+ } )
32+ container . appendChild ( button )
33+ }
2534
26- function createWindowMessageBtn ( label ) {
27- var tauriWindow = WebviewWindow . getByLabel ( label )
28- var button = document . createElement ( 'button' )
29- button . innerText = 'Send message to ' + label
30- button . addEventListener ( 'click' , function ( ) {
31- tauriWindow . emit ( 'clicked' , 'message from ' + windowLabel )
35+ // global listener
36+ window . __TAURI__ . event . listen ( 'clicked' , function ( event ) {
37+ responseContainer . innerHTML +=
38+ 'Got ' + JSON . stringify ( event ) + ' on global listener\n\n'
39+ } )
40+ window . __TAURI__ . event . listen ( 'tauri://window-created' , function ( event ) {
41+ createWindowMessageBtn ( event . payload . label )
3242 } )
33- container . appendChild ( button )
34- }
35-
36- // global listener
37- window . __TAURI__ . event . listen ( 'clicked' , function ( event ) {
38- responseContainer . innerHTML +=
39- 'Got ' + JSON . stringify ( event ) + ' on global listener\n\n'
40- } )
41- window . __TAURI__ . event . listen ( 'tauri://window-created' , function ( event ) {
42- createWindowMessageBtn ( event . payload . label )
43- } )
44-
45- var responseContainer = document . getElementById ( 'response' )
46- // listener tied to this window
47- appWindow . listen ( 'clicked' , function ( event ) {
48- responseContainer . innerText +=
49- 'Got ' + JSON . stringify ( event ) + ' on window listener\n\n'
50- } )
5143
52- var createWindowButton = document . createElement ( 'button' )
53- createWindowButton . innerHTML = 'Create window'
54- createWindowButton . addEventListener ( 'click' , function ( ) {
55- var webviewWindow = new WebviewWindow ( Math . random ( ) . toString ( ) . replace ( '.' , '' ) )
56- webviewWindow . once ( 'tauri://created' , function ( ) {
57- responseContainer . innerHTML += 'Created new webview'
44+ var responseContainer = document . getElementById ( 'response' )
45+ // listener tied to this window
46+ appWindow . listen ( 'clicked' , function ( event ) {
47+ responseContainer . innerText +=
48+ 'Got ' + JSON . stringify ( event ) + ' on window listener\n\n'
5849 } )
59- webviewWindow . once ( 'tauri://error' , function ( e ) {
60- responseContainer . innerHTML += 'Error creating new webview'
50+
51+ var createWindowButton = document . createElement ( 'button' )
52+ createWindowButton . innerHTML = 'Create window'
53+ createWindowButton . addEventListener ( 'click' , function ( ) {
54+ var webviewWindow = new WebviewWindow (
55+ Math . random ( ) . toString ( ) . replace ( '.' , '' )
56+ )
57+ webviewWindow . once ( 'tauri://created' , function ( ) {
58+ responseContainer . innerHTML += 'Created new webview'
59+ } )
60+ webviewWindow . once ( 'tauri://error' , function ( e ) {
61+ responseContainer . innerHTML += 'Error creating new webview'
62+ } )
6163 } )
62- } )
63- container . appendChild ( createWindowButton )
64+ container . appendChild ( createWindowButton )
6465
65- var globalMessageButton = document . createElement ( 'button' )
66- globalMessageButton . innerHTML = 'Send global message'
67- globalMessageButton . addEventListener ( 'click' , function ( ) {
68- // emit to all windows
69- window . __TAURI__ . event . emit ( 'clicked' , 'message from ' + windowLabel )
70- } )
71- container . appendChild ( globalMessageButton )
66+ var globalMessageButton = document . createElement ( 'button' )
67+ globalMessageButton . innerHTML = 'Send global message'
68+ globalMessageButton . addEventListener ( 'click' , function ( ) {
69+ // emit to all windows
70+ window . __TAURI__ . event . emit ( 'clicked' , 'message from ' + windowLabel )
71+ } )
72+ container . appendChild ( globalMessageButton )
7273
73- var allWindows = window . __TAURI__ . window . getAll ( )
74- for ( var index in allWindows ) {
75- var label = allWindows [ index ] . label
76- if ( label === windowLabel ) {
77- continue
74+ var allWindows = window . __TAURI__ . window . getAll ( )
75+ for ( var index in allWindows ) {
76+ var label = allWindows [ index ] . label
77+ if ( label === windowLabel ) {
78+ continue
79+ }
80+ createWindowMessageBtn ( label )
7881 }
79- createWindowMessageBtn ( label )
80- }
81- </ script >
82- </ body >
83-
84- </ html >
82+ </ script >
83+ </ body >
84+ </ html >
0 commit comments