From 8e512d70d93f5df59c6b756817ec9505c7129af0 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Mon, 24 Nov 2025 21:34:04 +0300 Subject: [PATCH] feat: save config --- src/internal/config/config.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/internal/config/config.go b/src/internal/config/config.go index 9417a36..8a3638f 100644 --- a/src/internal/config/config.go +++ b/src/internal/config/config.go @@ -126,6 +126,38 @@ func initializeViper(appName string) (*viper.Viper, string, error) { return v, configFile, nil } +func (c *Config) Save() error { + v, _, err := initializeViper(constants.AppName) + if err != nil { + return fmt.Errorf("failed to initialize viper: %w", err) + } + + v.Set("app.settings_reviewed", c.App.SettingsReviewed) + v.Set("app.enable_alarm", c.App.EnableAlarm) + v.Set("app.enable_link_opening", c.App.EnableLinkOpening) + v.Set("app.use_attendance_journal_api", c.App.UseAttendanceJounralApi) + v.Set("app.browser", c.App.Browser) + v.Set("app.enable_checking_updates", c.App.EnableCheckingUpdates) + + v.Set("logging.level", c.Logging.Level) + v.Set("logging.output", c.Logging.Output) + + v.Set("telemetry.enable_statistics_collection", c.Telemetry.EnableStatisticsCollection) + v.Set("telemetry.enable_anonymous_error_reports", c.Telemetry.EnableAnonymousErrorReports) + + if c.Communication.QrUrl != "" { + v.Set("communication.self_approve_url", c.Communication.QrUrl) + } + if c.Communication.QrQueryToken != "" { + v.Set("communication.qr_query_token", c.Communication.QrQueryToken) + } + if c.Communication.ApiSelfApproveMethod != "" { + v.Set("communication.api_self_approve_method", c.Communication.ApiSelfApproveMethod) + } + + return v.WriteConfig() +} + func NewConfig() (*Config, error) { v, configFile, err := initializeViper(constants.AppName) if err != nil {