feat: client auth — login/password flow, auto device reg, sync interval + improved sync UI

This commit is contained in:
2026-06-01 23:36:19 +08:00
parent 241a9d8c06
commit f8dc436709
4 changed files with 129 additions and 16 deletions
+30 -1
View File
@@ -846,6 +846,7 @@ type SyncStatusDTO struct {
DeviceID string `json:"deviceId"`
UnpushedOps int `json:"unpushedOps"`
LastSyncAt string `json:"lastSyncAt"`
SyncInterval int `json:"syncInterval"`
}
func (a *App) SyncStatus() (*SyncStatusDTO, error) {
@@ -863,11 +864,23 @@ func (a *App) SyncStatus() (*SyncStatusDTO, error) {
}
if cfg != nil {
dto.DeviceID = cfg.Sync.DeviceID
dto.SyncInterval = cfg.Sync.SyncInterval
}
return dto, nil
}
func (a *App) SyncConfigure(serverURL, apiKey string) error {
func (a *App) SyncConfigure(serverURL, username, password string) error {
// Register device on server with user credentials.
hostname, _ := os.Hostname()
if hostname == "" {
hostname = "unknown"
}
client := syncsvc.NewClient(serverURL, "", "", a.vault)
deviceID, apiKey, err := client.RegisterDeviceWithAuth(hostname, username, password)
if err != nil {
return fmt.Errorf("register: %w", err)
}
if err := a.sync.SetState(serverURL, apiKey); err != nil {
return err
}
@@ -878,6 +891,22 @@ func (a *App) SyncConfigure(serverURL, apiKey string) error {
}
cfg.Sync.ServerURL = serverURL
cfg.Sync.APIKey = apiKey
cfg.Sync.DeviceID = deviceID
return config.Save(a.vault, cfg)
}
func (a *App) SyncTestConnection(serverURL, username, password string) error {
client := syncsvc.NewClient(serverURL, "", "", a.vault)
_, _, err := client.RegisterDeviceWithAuth("test-connection", username, password)
return err
}
func (a *App) SyncSetInterval(minutes int) error {
cfg, err := config.Load(a.vault)
if err != nil {
return err
}
cfg.Sync.SyncInterval = minutes
return config.Save(a.vault, cfg)
}