gui, lib/api: Adds support for prefers-color-scheme (fixes #6115)
* gui, lib/api: Adds support for prefers-color-scheme on default theme (fixes #6115) - Renames current default theme into a new "light" theme - Modifies assets serving to allow getting assets from different themes * lib/api: Serve assets from arbitrary theme when path starts with "theme-assets" * lib/api: Moves constant out of function * Loads light theme in browsers without support for prefers-color-scheme * gui: Disables dark theme when printing * Prevents repeated injection and adds support for older browsers The CSS is always loaded if there is no support for `matchMedia`.
This commit is contained in:
committed by
Audrius Butkevicius
parent
65c172cd8d
commit
9b01e64c66
@@ -23,6 +23,8 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
)
|
||||
|
||||
const themePrefix = "theme-assets/"
|
||||
|
||||
type staticsServer struct {
|
||||
assetDir string
|
||||
assets map[string][]byte
|
||||
@@ -91,6 +93,20 @@ func (s *staticsServer) serveAsset(w http.ResponseWriter, r *http.Request) {
|
||||
modificationTime := s.lastThemeChange
|
||||
s.mut.RUnlock()
|
||||
|
||||
// If path starts with special prefix, get theme and file from path
|
||||
if strings.HasPrefix(file, themePrefix) {
|
||||
path := file[len(themePrefix):]
|
||||
i := strings.IndexRune(path, '/')
|
||||
|
||||
if i == -1 {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
theme = path[:i]
|
||||
file = path[i+1:]
|
||||
}
|
||||
|
||||
// Check for an override for the current theme.
|
||||
if s.assetDir != "" {
|
||||
p := filepath.Join(s.assetDir, theme, filepath.FromSlash(file))
|
||||
|
||||
Reference in New Issue
Block a user