penguin/homekey-go

homekey-go

commit ab260ac789c68e3238035518c67e480826144dee

author斟酌 鵬兄 <tgckpg@gmail.com>
date2026-10-05T11:29:04Z
subjectRemoved old settings import
commit ab260ac789c68e3238035518c67e480826144dee
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2026-10-05T11:29:04Z

    Removed old settings import
---
 Makefile                 |  3 +++
 cmd/homekey/main.go      | 11 +++++++----
 internal/app/pairing.go  |  3 ++-
 internal/app/settings.go | 17 ++++++++---------
 4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index e427c0a..4168413 100644
--- a/Makefile
+++ b/Makefile
@@ -51,6 +51,9 @@ push:
 		-t $(IMAGE_NAME):$(IMAGE_TAG) \
 		--push .
 
+image-info:
+	docker buildx imagetools inspect $(IMAGE_NAME):$(IMAGE_TAG)
+
 clean:
 	rm -rf bin
 
diff --git a/cmd/homekey/main.go b/cmd/homekey/main.go
index f73f26d..4f7220b 100644
--- a/cmd/homekey/main.go
+++ b/cmd/homekey/main.go
@@ -52,18 +52,21 @@ func run() error {
 		defer unlock()
 	}
 	activeConfig := *config
-	seed := ""
 	if *ingress {
 		activeConfig = filepath.Join(*state, "config.json")
-		seed = *config
 	}
-	processCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
+
+	processCtx, stop := signal.NotifyContext(
+		context.Background(), os.Interrupt, syscall.SIGTERM,
+	)
 	defer stop()
+
 	for {
-		settings, err := app.OpenSettings(activeConfig, seed, *status)
+		settings, err := app.OpenSettings(activeConfig, *status)
 		if err != nil {
 			return err
 		}
+
 		err = serve(processCtx, *state, *webAddr, *ingress, *status, settings)
 		if !errors.Is(err, errReload) {
 			return err
diff --git a/internal/app/pairing.go b/internal/app/pairing.go
index d0a347e..55c4b86 100644
--- a/internal/app/pairing.go
+++ b/internal/app/pairing.go
@@ -97,7 +97,8 @@ func (l *Lock) Status() LockStatus {
 	defer l.pairing.Unlock()
 	s := LockStatus{LockConfig: l.Config, Summary: l.Store.Summary()}
 	if s.Summary.PairedControllers == 0 && time.Now().Before(l.until) {
-		s.PIN = l.pin[:3] + "-" + l.pin[3:5] + "-" + l.pin[5:]
+		// Follow the format shown in home app XXXX-XXXX
+		s.PIN = l.pin[:4] + "-" + l.pin[4:]
 		s.Until = l.until
 	}
 	return s
diff --git a/internal/app/settings.go b/internal/app/settings.go
index e314834..b0d22a3 100644
--- a/internal/app/settings.go
+++ b/internal/app/settings.go
@@ -23,22 +23,21 @@ type Settings struct {
 	Reload     func()
 }
 
-func OpenSettings(path, seed string, readOnly ...bool) (*Settings, error) {
+func OpenSettings(path string, readOnly ...bool) (*Settings, error) {
 	c, err := Load(path)
-	if errors.Is(err, os.ErrNotExist) && seed != "" {
-		c, err = Load(seed)
-		if err != nil {
-			return nil, err
-		}
+	if errors.Is(err, os.ErrNotExist) {
+		c = Config{}
+		c.Normalize()
+
 		if len(readOnly) == 0 || !readOnly[0] {
-			if err = writeConfig(path, c); err != nil {
+			if err := writeConfig(path, c); err != nil {
 				return nil, err
 			}
 		}
-	}
-	if err != nil {
+	} else if err != nil {
 		return nil, err
 	}
+
 	return &Settings{path: path, config: c}, nil
 }
 func revision(c Config) string {