Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sonjek committed Apr 9, 2024
1 parent 61a28ed commit c1c911b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"fmt"

"github.com/sonjek/mouse-stay-up/pkg/config"
)

Expand Down Expand Up @@ -36,14 +38,15 @@ type Config struct {

func init() {
// Create a folder to save the config file if it doesn't exist yet
config.CreateConfigFolder(appName)
if err := config.CreateConfigFolder(appName); err != nil {
fmt.Println(err)
}

// Calculate the configuration file path for saving when app parameters change
configFilePath = config.GetConfigFilePath(appName, configFileName)
}

func NewConfig() *Config {

// Define the default Config struct
appConfig := &Config{
Enabled: true,
Expand All @@ -56,7 +59,7 @@ func NewConfig() *Config {

// Saves the struct to an configuration file if it doesn't exist yet
if !isRestored {
config.SaveStructToFile(configFilePath, appConfig)
saveConfig(appConfig)
}

return appConfig
Expand All @@ -65,11 +68,17 @@ func NewConfig() *Config {
func (c *Config) ToggleEnableDisable() {
c.Enabled = !c.Enabled

config.SaveStructToFile(configFilePath, c)
saveConfig(c)
}

func (c *Config) SetWorkingHoursInterval(interval string) {
c.WorkingHoursInterval = interval

config.SaveStructToFile(configFilePath, c)
saveConfig(c)
}

func saveConfig(appConfig *Config) {
if err := config.SaveStructToFile(configFilePath, appConfig); err != nil {
fmt.Println(err)
}
}
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetConfigFilePath(appName, configFileName string) string {
}

// Saves the struct to an configuration file
func SaveStructToFile(configFilePath string, config interface{}) error {
func SaveStructToFile(configFilePath string, config any) error {
// Reflect data sources from given struct
cfg := ini.Empty()
if err := ini.ReflectFrom(cfg, config); err != nil {
Expand All @@ -53,7 +53,7 @@ func SaveStructToFile(configFilePath string, config interface{}) error {
}

// Restores the configuration file into the struct
func LoadFileToStruct(configFilePath string, config interface{}) bool {
func LoadFileToStruct(configFilePath string, config any) bool {
// Try to load the configuration file from disk if it exists
cfg, err := ini.Load(configFilePath)
if err != nil {
Expand Down

0 comments on commit c1c911b

Please sign in to comment.