@@ -27,6 +27,7 @@ import (
2727
2828const TsunamiListenAddrEnvVar = "TSUNAMI_LISTENADDR"
2929const DefaultListenAddr = "localhost:0"
30+ const DefaultComponentName = "App"
3031
3132type SSEvent struct {
3233 Event string
@@ -37,8 +38,6 @@ type AppOpts struct {
3738 Title string // window title
3839 CloseOnCtrlC bool
3940 GlobalKeyboardEvents bool
40- GlobalStyles []byte
41- RootComponentName string // defaults to "App"
4241}
4342
4443type Client struct {
@@ -47,11 +46,11 @@ type Client struct {
4746 Root * comp.RootElem
4847 RootElem * vdom.VDomElem
4948 CurrentClientId string
49+ ServerId string
5050 IsDone bool
5151 DoneReason string
5252 DoneCh chan struct {}
5353 SSEventCh chan SSEvent
54- Opts rpctypes.VDomBackendOpts
5554 GlobalEventHandler func (client * Client , event vdom.VDomEvent )
5655 GlobalStylesOption * FileHandlerOption
5756 UrlHandlerMux * mux.Router
@@ -65,6 +64,8 @@ func MakeClient(appOpts AppOpts) *Client {
6564 DoneCh : make (chan struct {}),
6665 SSEventCh : make (chan SSEvent , 100 ),
6766 UrlHandlerMux : mux .NewRouter (),
67+ ServerId : uuid .New ().String (),
68+ RootElem : vdom .E (DefaultComponentName ),
6869 }
6970 client .SetAppOpts (appOpts )
7071 return client
@@ -114,27 +115,27 @@ func (c *Client) SetAppOpts(appOpts AppOpts) {
114115 c .Lock .Lock ()
115116 defer c .Lock .Unlock ()
116117
117- if appOpts .RootComponentName == "" {
118- appOpts .RootComponentName = "App"
119- }
120-
121118 c .AppOpts = appOpts
119+ }
120+
121+ func getFaviconPath () string {
122+ if staticFS != nil {
123+ faviconNames := []string {"favicon.ico" , "favicon.png" , "favicon.svg" , "favicon.gif" , "favicon.jpg" }
124+ for _ , name := range faviconNames {
125+ if _ , err := staticFS .Open (name ); err == nil {
126+ return "/static/" + name
127+ }
128+ }
129+ }
130+ return "/wave-logo-256.png"
131+ }
122132
123- // Update the VDomBackendOpts
124- c .Opts .CloseOnCtrlC = appOpts .CloseOnCtrlC
125- c .Opts .GlobalKeyboardEvents = appOpts .GlobalKeyboardEvents
126- c .Opts .Title = appOpts .Title
127-
128- // Update RootElem if component name changed
129- c .RootElem = vdom .E (appOpts .RootComponentName )
130-
131- // Update global styles
132- if len (appOpts .GlobalStyles ) > 0 {
133- c .Opts .GlobalStyles = true
134- c .GlobalStylesOption = & FileHandlerOption {Data : appOpts .GlobalStyles , MimeType : "text/css" }
135- } else {
136- c .Opts .GlobalStyles = false
137- c .GlobalStylesOption = nil
133+ func (c * Client ) makeBackendOpts () * rpctypes.VDomBackendOpts {
134+ return & rpctypes.VDomBackendOpts {
135+ Title : c .AppOpts .Title ,
136+ CloseOnCtrlC : c .AppOpts .CloseOnCtrlC ,
137+ GlobalKeyboardEvents : c .AppOpts .GlobalKeyboardEvents ,
138+ FaviconPath : getFaviconPath (),
138139 }
139140}
140141
@@ -275,10 +276,11 @@ func (c *Client) fullRender() (*rpctypes.VDomBackendUpdate, error) {
275276 renderedVDom = makeNullVDom ()
276277 }
277278 return & rpctypes.VDomBackendUpdate {
278- Type : "backendupdate" ,
279- Ts : time .Now ().UnixMilli (),
280- HasWork : len (c .Root .EffectWorkQueue ) > 0 ,
281- Opts : & c .Opts ,
279+ Type : "backendupdate" ,
280+ Ts : time .Now ().UnixMilli (),
281+ ServerId : c .ServerId ,
282+ HasWork : len (c .Root .EffectWorkQueue ) > 0 ,
283+ Opts : c .makeBackendOpts (),
282284 RenderUpdates : []rpctypes.VDomRenderUpdate {
283285 {UpdateType : "root" , VDom : renderedVDom },
284286 },
@@ -295,8 +297,9 @@ func (c *Client) incrementalRender() (*rpctypes.VDomBackendUpdate, error) {
295297 renderedVDom = makeNullVDom ()
296298 }
297299 return & rpctypes.VDomBackendUpdate {
298- Type : "backendupdate" ,
299- Ts : time .Now ().UnixMilli (),
300+ Type : "backendupdate" ,
301+ Ts : time .Now ().UnixMilli (),
302+ ServerId : c .ServerId ,
300303 RenderUpdates : []rpctypes.VDomRenderUpdate {
301304 {UpdateType : "root" , VDom : renderedVDom },
302305 },
0 commit comments