Open browser on startup automatically, with configuration option to disable.

This commit is contained in:
2022-05-01 11:55:20 +09:30
parent 0c2fafdc7a
commit 06ac259e0a
10 changed files with 57 additions and 12 deletions

View File

@@ -38,8 +38,16 @@ type ConfigV2 struct {
Watchers []Watcher
}
type ConfigV3 struct {
WatchInterval int
Version int
Port int
OpenBrowserOnStart bool
Watchers []Watcher
}
type ConfigService struct {
Config *ConfigV2
Config *ConfigV3
Changed chan bool
ConfigFilename string
}
@@ -66,11 +74,12 @@ func (c *ConfigService) LoadOrInit() error {
}
}
func DefaultConfig() *ConfigV2 {
c := ConfigV2{}
c.Version = 2
func DefaultConfig() *ConfigV3 {
c := ConfigV3{}
c.Version = 3
c.WatchInterval = 10
c.Port = 9090
c.OpenBrowserOnStart = true
w := Watcher{
WebHookURL: "https://webhook.url.here",
Path: "/your/screenshot/dir/here",
@@ -122,6 +131,13 @@ func (c *ConfigService) Load() error {
c.Config.Watchers = []Watcher{onlyWatcher}
}
if c.Config.Version == 2 {
// need to migrate this
daulog.Info("Migrating config to V3")
c.Config.Version = 3
c.Config.OpenBrowserOnStart = true
}
return nil
}

View File

@@ -22,8 +22,8 @@ func TestNoConfig(t *testing.T) {
t.Errorf("unexpected failure from load: %s", err)
}
if c.Config.Version != 2 {
t.Error("not version 2 starting config")
if c.Config.Version != 3 {
t.Error("not version 3 starting config")
}
if fileSize(c.ConfigFilename) < 40 {
@@ -45,7 +45,7 @@ func TestEmptyFileConfig(t *testing.T) {
}
func TestMigrateFromV1toV2(t *testing.T) {
func TestMigrateFromV1toV3(t *testing.T) {
c := ConfigService{}
c.ConfigFilename = v1Config()
@@ -53,8 +53,12 @@ func TestMigrateFromV1toV2(t *testing.T) {
if err != nil {
t.Error("unexpected error from LoadOrInit()")
}
if c.Config.Version != 2 {
t.Errorf("Version %d not 2", c.Config.Version)
if c.Config.Version != 3 {
t.Errorf("Version %d not 3", c.Config.Version)
}
if c.Config.OpenBrowserOnStart != true {
t.Errorf("Open browser on start not true")
}
if len(c.Config.Watchers) != 1 {