2021-11-22 11:26:10 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-04-22 17:38:40 +02:00
|
|
|
"path"
|
2021-11-22 11:26:10 +01:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2021-11-22 11:36:46 +01:00
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/i18n"
|
|
|
|
|
2022-04-22 17:38:40 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/clean"
|
2021-11-22 11:36:46 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
|
|
|
"github.com/photoprism/photoprism/pkg/txt"
|
2021-11-22 11:26:10 +01:00
|
|
|
)
|
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
// DefaultTheme returns the default user interface theme name.
|
|
|
|
func (c *Config) DefaultTheme() string {
|
2022-04-22 17:38:40 +02:00
|
|
|
if c.options.DefaultTheme == "" || c.NoSponsor() {
|
2022-04-15 09:42:07 +02:00
|
|
|
return "default"
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.options.DefaultTheme
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultLocale returns the default user interface language locale name.
|
|
|
|
func (c *Config) DefaultLocale() string {
|
|
|
|
if c.options.DefaultLocale == "" {
|
|
|
|
return i18n.Default.Locale()
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.options.DefaultLocale
|
|
|
|
}
|
|
|
|
|
2021-11-29 14:39:21 +01:00
|
|
|
// AppIcon returns the app icon when installed on a device.
|
|
|
|
func (c *Config) AppIcon() string {
|
2021-11-29 18:12:35 +01:00
|
|
|
defaultIcon := "logo"
|
2021-11-29 14:39:21 +01:00
|
|
|
|
2022-04-22 17:38:40 +02:00
|
|
|
if c.NoSponsor() || c.options.AppIcon == "" || c.options.AppIcon == defaultIcon {
|
2021-11-29 14:39:21 +01:00
|
|
|
// Default.
|
|
|
|
} else if fs.FileExists(c.AppIconsPath(c.options.AppIcon, "512.png")) {
|
|
|
|
return c.options.AppIcon
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultIcon
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppIconsPath returns the path to the app icons.
|
|
|
|
func (c *Config) AppIconsPath(name ...string) string {
|
|
|
|
if len(name) > 0 {
|
2022-04-22 17:38:40 +02:00
|
|
|
filePath := []string{c.StaticPath(), "icons"}
|
|
|
|
filePath = append(filePath, name...)
|
|
|
|
return filepath.Join(filePath...)
|
2021-11-29 14:39:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Join(c.StaticPath(), "icons")
|
|
|
|
}
|
|
|
|
|
2021-11-22 11:26:10 +01:00
|
|
|
// AppName returns the app name when installed on a device.
|
|
|
|
func (c *Config) AppName() string {
|
|
|
|
name := strings.TrimSpace(c.options.AppName)
|
|
|
|
|
2022-04-22 17:38:40 +02:00
|
|
|
if c.NoSponsor() || name == "" {
|
2021-11-22 11:26:10 +01:00
|
|
|
name = c.SiteTitle()
|
|
|
|
}
|
|
|
|
|
2022-07-05 23:13:34 +02:00
|
|
|
name = strings.Map(func(r rune) rune {
|
2021-11-22 11:26:10 +01:00
|
|
|
switch r {
|
|
|
|
case '\'', '"':
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
2022-07-05 23:13:34 +02:00
|
|
|
}, name)
|
2021-11-22 11:26:10 +01:00
|
|
|
|
|
|
|
return txt.Clip(name, 32)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppMode returns the app mode when installed on a device.
|
|
|
|
func (c *Config) AppMode() string {
|
|
|
|
switch c.options.AppMode {
|
|
|
|
case "fullscreen", "standalone", "minimal-ui", "browser":
|
|
|
|
return c.options.AppMode
|
|
|
|
default:
|
|
|
|
return "standalone"
|
|
|
|
}
|
|
|
|
}
|
2022-04-22 17:38:40 +02:00
|
|
|
|
|
|
|
// WallpaperUri returns the login screen background image `URI`.
|
|
|
|
func (c *Config) WallpaperUri() string {
|
|
|
|
if c.NoSponsor() {
|
|
|
|
return ""
|
|
|
|
} else if strings.Contains(c.options.WallpaperUri, "/") {
|
|
|
|
return c.options.WallpaperUri
|
|
|
|
}
|
|
|
|
|
|
|
|
assetPath := "img/wallpaper"
|
|
|
|
|
|
|
|
// Empty URI?
|
|
|
|
if c.options.WallpaperUri == "" {
|
|
|
|
if !fs.PathExists(filepath.Join(c.StaticPath(), assetPath)) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-04-22 18:46:16 +02:00
|
|
|
c.options.WallpaperUri = "welcome.jpg"
|
2022-04-22 17:38:40 +02:00
|
|
|
} else if !strings.Contains(c.options.WallpaperUri, ".") {
|
|
|
|
c.options.WallpaperUri += fs.ExtJPEG
|
|
|
|
}
|
|
|
|
|
|
|
|
// Valid URI? Local file?
|
|
|
|
if p := clean.Path(c.options.WallpaperUri); p == "" {
|
2022-07-05 23:13:34 +02:00
|
|
|
c.options.WallpaperUri = ""
|
2022-04-22 17:38:40 +02:00
|
|
|
} else if fs.FileExists(filepath.Join(c.StaticPath(), assetPath, p)) {
|
|
|
|
c.options.WallpaperUri = path.Join(c.StaticUri(), assetPath, p)
|
|
|
|
} else {
|
|
|
|
c.options.WallpaperUri = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.options.WallpaperUri
|
|
|
|
}
|