@@ -28,6 +28,7 @@ import (
2828 "github.com/cozy/cozy-stack/pkg/jsonapi"
2929 "github.com/cozy/cozy-stack/pkg/registry"
3030 "github.com/cozy/cozy-stack/web/auth"
31+ "github.com/cozy/cozy-stack/web/intents"
3132 "github.com/cozy/cozy-stack/web/middlewares"
3233 "github.com/cozy/cozy-stack/web/settings"
3334 "github.com/cozy/cozy-stack/web/statik"
@@ -272,8 +273,6 @@ func ServeAppFile(c echo.Context, i *instance.Instance, fs appfs.FileServer, web
272273 intentDoc = handleIntent (c , i , slug , intentID )
273274 }
274275
275- _ = intentDoc // threaded into serveParams in the next change
276-
277276 if route .Public && slug == consts .DataProxySlug {
278277 // Allow to dataproxy to be embedded in a iframe from the login page of the
279278 // stack for cleaning.
@@ -296,7 +295,7 @@ func ServeAppFile(c echo.Context, i *instance.Instance, fs appfs.FileServer, web
296295 // XXX: Force include Warnings template in all app indexes
297296 tmplText := string (buf )
298297 if closeTagIdx := strings .Index (tmplText , "</head>" ); closeTagIdx >= 0 {
299- tmplText = tmplText [:closeTagIdx ] + "\n {{.Warnings}}\n " + tmplText [closeTagIdx :]
298+ tmplText = tmplText [:closeTagIdx ] + "\n {{.Warnings}}\n {{.IntentData}} \n " + tmplText [closeTagIdx :]
300299 } else {
301300 needsOpenTag := true
302301 if openTagIdx := strings .Index (tmplText , "<head>" ); openTagIdx >= 0 {
@@ -313,7 +312,7 @@ func ServeAppFile(c echo.Context, i *instance.Instance, fs appfs.FileServer, web
313312 tmplText += "\n <head>"
314313 }
315314
316- tmplText += "\n {{.Warnings}}\n </head>\n " + after
315+ tmplText += "\n {{.Warnings}}\n {{.IntentData}} \n </head>\n " + after
317316 }
318317 }
319318
@@ -335,7 +334,7 @@ func ServeAppFile(c echo.Context, i *instance.Instance, fs appfs.FileServer, web
335334 }
336335 }
337336 }
338- params := buildServeParams (c , i , webapp , isLoggedIn , sessID )
337+ params := buildServeParams (c , i , webapp , intentDoc , isLoggedIn , sessID )
339338
340339 generated := & bytes.Buffer {}
341340 if err := tmpl .Execute (generated , params ); err != nil {
@@ -365,6 +364,7 @@ func buildServeParams(
365364 c echo.Context ,
366365 inst * instance.Instance ,
367366 webapp * app.WebappManifest ,
367+ intentDoc * intent.Intent ,
368368 isLoggedIn bool ,
369369 sessID string ,
370370) serveParams {
@@ -388,6 +388,7 @@ func buildServeParams(
388388 Token : token ,
389389 SubDomain : subdomainsType ,
390390 Tracking : tracking ,
391+ intent : intentDoc ,
391392 webapp : webapp ,
392393 instance : inst ,
393394 isLoggedIn : isLoggedIn ,
@@ -496,6 +497,7 @@ type serveParams struct {
496497 Token string
497498 SubDomain string
498499 Tracking bool
500+ intent * intent.Intent
499501 webapp * app.WebappManifest
500502 instance * instance.Instance
501503 isLoggedIn bool
@@ -627,9 +629,26 @@ func (s serveParams) Warnings() (template.HTML, error) {
627629 return warningsHTML (s .instance , s .isLoggedIn )
628630}
629631
632+ func (s serveParams ) IntentData () (template.HTML , error ) {
633+ if s .intent == nil {
634+ return "" , nil
635+ }
636+ api := intents .NewAPIIntent (s .intent , s .instance )
637+ raw , err := jsonapi .MarshalObject (api )
638+ if err != nil {
639+ return "" , err
640+ }
641+ buf := new (bytes.Buffer )
642+ if err := intentTemplate .Execute (buf , string (raw )); err != nil {
643+ return "" , err
644+ }
645+ return template .HTML (buf .String ()), nil
646+ }
647+
630648var clientTemplate * template.Template
631649var barTemplate * template.Template
632650var warningsTemplate * template.Template
651+ var intentTemplate * template.Template
633652
634653// BuildTemplates ensure that cozy-client-js and the bar can be injected in templates
635654func BuildTemplates () {
@@ -650,6 +669,10 @@ func BuildTemplates() {
650669{{end}}
651670{{end}}` ,
652671 ))
672+
673+ intentTemplate = template .Must (template .New ("intent-data" ).Parse (
674+ `<script>window.__COZY_INTENT__ = JSON.parse({{.}})</script>` ,
675+ ))
653676}
654677
655678func cozyclientjsHTML (i * instance.Instance ) (template.HTML , error ) {
0 commit comments