1+ <!doctype html>
2+ < html lang ="en ">
3+ < head > < link rel ="modulepreload " href ="/mini-note-dd0ee225576671bf.js " crossorigin =anonymous integrity ="sha384-KsnTD8RMZuTYNhdmh0d5MAS8OGc55h5HHSbzqCstI/LD0W37NJ99GIMog3YZZAb6 "> < link rel ="preload " href ="/mini-note-dd0ee225576671bf_bg.wasm " crossorigin =anonymous integrity ="sha384-gqTkPWMAsYcUvPapd2DLq91BmhOb5vnHmIi32ruM998yghWImzbmYdt/qIlzXBS3 " as ="fetch " type ="application/wasm "> </ head >
4+ < body >
5+ < script type ="module " nonce ="VEXomg5aQ5Rwu9MRIMLWJw== ">
6+ import init , * as bindings from '/mini-note-dd0ee225576671bf.js' ;
7+ const wasm = await init ( { module_or_path : '/mini-note-dd0ee225576671bf_bg.wasm' } ) ;
8+
9+
10+ window . wasmBindings = bindings ;
11+
12+
13+ dispatchEvent ( new CustomEvent ( "TrunkApplicationStarted" , { detail : { wasm} } ) ) ;
14+
15+ </ script > < script > "use strict" ;
16+
17+ ( function ( ) {
18+
19+ const address = '{{__TRUNK_ADDRESS__}}' ;
20+ const base = '{{__TRUNK_WS_BASE__}}' ;
21+ let protocol = '' ;
22+ protocol =
23+ protocol
24+ ? protocol
25+ : window . location . protocol === 'https:'
26+ ? 'wss'
27+ : 'ws' ;
28+ const url = protocol + '://' + address + base + '.well-known/trunk/ws' ;
29+
30+ class Overlay {
31+ constructor ( ) {
32+ // create an overlay
33+ this . _overlay = document . createElement ( "div" ) ;
34+ const style = this . _overlay . style ;
35+ style . height = "100vh" ;
36+ style . width = "100vw" ;
37+ style . position = "fixed" ;
38+ style . top = "0" ;
39+ style . left = "0" ;
40+ style . backgroundColor = "rgba(222, 222, 222, 0.5)" ;
41+ style . fontFamily = "sans-serif" ;
42+ // not sure that's the right approach
43+ style . zIndex = "1000000" ;
44+ style . backdropFilter = "blur(1rem)" ;
45+
46+ const container = document . createElement ( "div" ) ;
47+ // center it
48+ container . style . position = "absolute" ;
49+ container . style . top = "30%" ;
50+ container . style . left = "15%" ;
51+ container . style . maxWidth = "85%" ;
52+
53+ this . _title = document . createElement ( "div" ) ;
54+ this . _title . innerText = "Build failure" ;
55+ this . _title . style . paddingBottom = "2rem" ;
56+ this . _title . style . fontSize = "2.5rem" ;
57+
58+ this . _message = document . createElement ( "div" ) ;
59+ this . _message . style . whiteSpace = "pre-wrap" ;
60+
61+ const icon = document . createElement ( "div" ) ;
62+ icon . innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" fill="#dc3545" viewBox="0 0 16 16"><path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/></svg>' ;
63+ this . _title . prepend ( icon ) ;
64+
65+ container . append ( this . _title , this . _message ) ;
66+ this . _overlay . append ( container ) ;
67+
68+ this . _inject ( ) ;
69+ window . setInterval ( ( ) => {
70+ this . _inject ( ) ;
71+ } , 250 ) ;
72+ }
73+
74+ set reason ( reason ) {
75+ this . _message . textContent = reason ;
76+ }
77+
78+ _inject ( ) {
79+ if ( ! this . _overlay . isConnected ) {
80+ // prepend it
81+ document . body ?. prepend ( this . _overlay ) ;
82+ }
83+ }
84+
85+ }
86+
87+ class Client {
88+ constructor ( url ) {
89+ this . url = url ;
90+ this . poll_interval = 5000 ;
91+ this . _overlay = null ;
92+ }
93+
94+ start ( ) {
95+ const ws = new WebSocket ( this . url ) ;
96+ ws . onmessage = ( ev ) => {
97+ const msg = JSON . parse ( ev . data ) ;
98+ switch ( msg . type ) {
99+ case "reload" :
100+ this . reload ( ) ;
101+ break ;
102+ case "buildFailure" :
103+ this . buildFailure ( msg . data )
104+ break ;
105+ }
106+ } ;
107+ ws . onclose = this . onclose ;
108+ }
109+
110+ onclose ( ) {
111+ window . setTimeout (
112+ ( ) => {
113+ // when we successfully reconnect, we'll force a
114+ // reload (since we presumably lost connection to
115+ // trunk due to it being killed, so it will have
116+ // rebuilt on restart)
117+ const ws = new WebSocket ( this . url ) ;
118+ ws . onopen = ( ) => window . location . reload ( ) ;
119+ ws . onclose = this . onclose ;
120+ } ,
121+ this . poll_interval ) ;
122+ }
123+
124+ reload ( ) {
125+ window . location . reload ( ) ;
126+ }
127+
128+ buildFailure ( { reason} ) {
129+ // also log the console
130+ console . error ( "Build failed:" , reason ) ;
131+
132+ console . debug ( "Overlay" , this . _overlay ) ;
133+
134+ if ( ! this . _overlay ) {
135+ this . _overlay = new Overlay ( ) ;
136+ }
137+ this . _overlay . reason = reason ;
138+ }
139+ }
140+
141+ new Client ( url ) . start ( ) ;
142+
143+ } ) ( )
144+ </ script > </ body >
145+ </ html >
0 commit comments