From bfba9c743e0345822cac4f43da178a7e7f170a39 Mon Sep 17 00:00:00 2001 From: Nils Hjelte Date: Wed, 31 May 2023 14:45:48 +0200 Subject: [PATCH] Add scale factor setting Implementation copied from https://github.com/grafana/grafana-kiosk/pull/77 --- README.md | 5 +++++ pkg/cmd/grafana-kiosk/main.go | 5 +++++ pkg/kiosk/config.go | 1 + pkg/kiosk/utils.go | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 9b47bbb..4cbd0a1 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ NOTE: Flags with parameters should use an "equals" Top Left Position of Kiosk (default "0,0") -window-size string Size of Kiosk in pixels (e.g. "1920,1080") + -scale-factor string + Scale factor of Kiosk. This is sort of like zoom. (default: "1") ``` ### Using a configuration file @@ -123,6 +125,7 @@ general: autofit: true lxde: true lxde-home: /home/pi + scale-factor: 1.0 target: login-method: anon @@ -153,6 +156,8 @@ They can also be used instead of a configuration file. Top Left Position of Kiosk (default "0,0") KIOSK_WINDOW_SIZE string Size of Kiosk in pixels (e.g. "1920,1080") + KIOSK_SCALE_FACTOR string + Scale factor, like zoom KIOSK_IGNORE_CERTIFICATE_ERRORS bool Ignore SSL/TLS certificate errors (default "false") KIOSK_IS_PLAYLIST bool diff --git a/pkg/cmd/grafana-kiosk/main.go b/pkg/cmd/grafana-kiosk/main.go index e5678a5..6501a6c 100644 --- a/pkg/cmd/grafana-kiosk/main.go +++ b/pkg/cmd/grafana-kiosk/main.go @@ -40,6 +40,7 @@ type Args struct { PasswordField string WindowPosition string WindowSize string + ScaleFactor string } // ProcessArgs processes and handles CLI arguments. @@ -56,6 +57,7 @@ func ProcessArgs(cfg interface{}) Args { flagSettings.StringVar(&processedArgs.URL, "URL", "https://play.grafana.org", "URL to Grafana server") flagSettings.StringVar(&processedArgs.WindowPosition, "window-position", "0,0", "Top Left Position of Kiosk") flagSettings.StringVar(&processedArgs.WindowSize, "window-size", "", "Size of Kiosk in pixels (width,height)") + flagSettings.StringVar(&processedArgs.ScaleFactor, "scale-factor", "1.0", "Scale factor, sort of zoom") flagSettings.BoolVar(&processedArgs.IsPlayList, "playlists", false, "URL is a playlist") flagSettings.BoolVar(&processedArgs.AutoFit, "autofit", true, "Fit panels to screen") flagSettings.BoolVar(&processedArgs.LXDEEnabled, "lxde", false, "Initialize LXDE for kiosk mode") @@ -122,6 +124,8 @@ func summary(cfg *kiosk.Config) { log.Println("Mode:", cfg.General.Mode) log.Println("WindowPosition:", cfg.General.WindowPosition) log.Println("WindowSize:", cfg.General.WindowSize) + log.Println("ScaleFactor:", cfg.General.ScaleFactor) + // target log.Println("URL:", cfg.Target.URL) log.Println("LoginMethod:", cfg.Target.LoginMethod) @@ -182,6 +186,7 @@ func main() { cfg.General.Mode = args.Mode cfg.General.WindowPosition = args.WindowPosition cfg.General.WindowSize = args.WindowSize + cfg.General.ScaleFactor = args.ScaleFactor // cfg.GOAUTH.AutoLogin = args.OauthAutoLogin cfg.GOAUTH.UsernameField = args.UsernameField diff --git a/pkg/kiosk/config.go b/pkg/kiosk/config.go index 42c6513..3a4b6c8 100644 --- a/pkg/kiosk/config.go +++ b/pkg/kiosk/config.go @@ -12,6 +12,7 @@ type Config struct { Mode string `yaml:"kiosk-mode" env:"KIOSK_MODE" env-default:"full" env-description:"[full|tv|disabled]"` WindowPosition string `yaml:"window-position" env:"KIOSK_WINDOW_POSITION" env-default:"0,0" env-description:"Top Left Position of Kiosk"` WindowSize string `yaml:"window-size" env:"KIOSK_WINDOW_SIZE" env-default:"" env-description:"Size of Kiosk in pixels (width,height)"` + ScaleFactor string `yaml:"scale-factor" env:"KIOSK_SCALE_FACTOR" env-default:"1.0" env-description:"Scale factor, like zoom"` } `yaml:"general"` Target struct { IgnoreCertificateErrors bool `yaml:"ignore-certificate-errors" env:"KIOSK_IGNORE_CERTIFICATE_ERRORS" env-description:"ignore SSL/TLS certificate errors" env-default:"false"` diff --git a/pkg/kiosk/utils.go b/pkg/kiosk/utils.go index 934cd8a..1977cb5 100644 --- a/pkg/kiosk/utils.go +++ b/pkg/kiosk/utils.go @@ -73,5 +73,9 @@ func generateExecutorOptions(dir string, cfg *Config) []chromedp.ExecAllocatorOp execAllocatorOption = append(execAllocatorOption, chromedp.Flag("window-size", cfg.General.WindowSize)) } + if cfg.General.ScaleFactor != "" { + execAllocatorOption = append(execAllocatorOption, chromedp.Flag("force-device-scale-factor", cfg.General.ScaleFactor)) + } + return execAllocatorOption }