| 1 | package chrome |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "strings" |
| 6 | |
| 7 | "amadan.net/oficina/estilo.git/brand" |
| 8 | ) |
| 9 | |
| 10 | // suite is the apps registered with the suite's identity service, in the |
| 11 | // switcher's order: slug, then product name (the same in every locale). |
| 12 | // Fichas, Mail and Files are deliberately absent; they are not registered. |
| 13 | var suite = []struct{ slug, name string }{ |
| 14 | {"docs", "Docs"}, |
| 15 | {"sheets", "Sheets"}, |
| 16 | {"slides", "Slides"}, |
| 17 | {"calendar", "Calendar"}, |
| 18 | {"memoria", "Memoria"}, |
| 19 | {"calls", "Calls"}, |
| 20 | } |
| 21 | |
| 22 | // SuiteApps is the switcher's tiles for the app whose slug is current, |
| 23 | // derived from the hub directory's origin: an app's host is its slug |
| 24 | // under the directory's host, so "https://oficina.works" gives |
| 25 | // "https://docs.oficina.works/". Icons are brand.Path(slug), so every |
| 26 | // caller must mount brand.Handler(). |
| 27 | // |
| 28 | // It returns nil when directory is not an absolute origin, which leaves |
| 29 | // the switcher as the "All apps" link alone. A current slug that is not |
| 30 | // in the suite marks no tile. |
| 31 | func SuiteApps(directory, current string) []SwitcherApp { |
| 32 | u, err := url.Parse(strings.TrimSuffix(directory, "/")) |
| 33 | if err != nil || (u.Scheme != "https" && u.Scheme != "http") || u.Host == "" || u.User != nil || (u.Path != "" && u.Path != "/") || u.RawQuery != "" || u.Fragment != "" { |
| 34 | return nil |
| 35 | } |
| 36 | apps := make([]SwitcherApp, len(suite)) |
| 37 | for i, app := range suite { |
| 38 | apps[i] = SwitcherApp{ |
| 39 | Name: app.name, |
| 40 | Href: u.Scheme + "://" + app.slug + "." + u.Host + "/", |
| 41 | Icon: brand.Path(app.slug), |
| 42 | Current: app.slug == current, |
| 43 | } |
| 44 | } |
| 45 | return apps |
| 46 | } |
| 47 | |