package chrome import ( "net/url" "strings" "amadan.net/oficina/estilo.git/brand" ) // suite is the apps registered with the suite's identity service, in the // switcher's order: slug, then product name (the same in every locale). // Fichas, Mail and Files are deliberately absent; they are not registered. var suite = []struct{ slug, name string }{ {"docs", "Docs"}, {"sheets", "Sheets"}, {"slides", "Slides"}, {"calendar", "Calendar"}, {"memoria", "Memoria"}, {"calls", "Calls"}, } // SuiteApps is the switcher's tiles for the app whose slug is current, // derived from the hub directory's origin: an app's host is its slug // under the directory's host, so "https://oficina.works" gives // "https://docs.oficina.works/". Icons are brand.Path(slug), so every // caller must mount brand.Handler(). // // It returns nil when directory is not an absolute origin, which leaves // the switcher as the "All apps" link alone. A current slug that is not // in the suite marks no tile. func SuiteApps(directory, current string) []SwitcherApp { u, err := url.Parse(strings.TrimSuffix(directory, "/")) if err != nil || (u.Scheme != "https" && u.Scheme != "http") || u.Host == "" || u.User != nil || (u.Path != "" && u.Path != "/") || u.RawQuery != "" || u.Fragment != "" { return nil } apps := make([]SwitcherApp, len(suite)) for i, app := range suite { apps[i] = SwitcherApp{ Name: app.name, Href: u.Scheme + "://" + app.slug + "." + u.Host + "/", Icon: brand.Path(app.slug), Current: app.slug == current, } } return apps }