Skip to content

Commit

Permalink
Add scale factor setting
Browse files Browse the repository at this point in the history
Implementation copied from grafana#77
  • Loading branch information
koliyo committed May 31, 2023
1 parent 8c5d489 commit bfba9c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -123,6 +125,7 @@ general:
autofit: true
lxde: true
lxde-home: /home/pi
scale-factor: 1.0

target:
login-method: anon
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/grafana-kiosk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Args struct {
PasswordField string
WindowPosition string
WindowSize string
ScaleFactor string
}

// ProcessArgs processes and handles CLI arguments.
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/kiosk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions pkg/kiosk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit bfba9c7

Please sign in to comment.