2022-11-27 21:08:34 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-12-02 23:18:13 +01:00
|
|
|
"os"
|
2022-11-27 21:08:34 +01:00
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
// UserConfig
|
|
|
|
SavePassword bool `json:"save_password,omitempty"`
|
|
|
|
SavedPassword string `json:"saved_password,omitempty"`
|
|
|
|
// Technical
|
2023-01-08 22:57:17 +01:00
|
|
|
IdentityFile string `json:"identity_file,omitempty"`
|
2022-11-27 21:08:34 +01:00
|
|
|
StoragePath string `json:"storage_path,omitempty"`
|
|
|
|
MaxIdsPerUser int `json:"max_ids_per_user,omitempty"`
|
|
|
|
MsgDbRollingPeriod int `json:"msg_db_rolling_period,omitempty"`
|
2022-12-18 21:52:03 +01:00
|
|
|
Chunksize int64 `json:"chunksize,omitempty"`
|
2022-11-27 21:08:34 +01:00
|
|
|
ServerPollInterval int `json:"server_poll_interval,omitempty"`
|
2023-02-15 22:08:17 +01:00
|
|
|
DbSize int `json:"db_size,omitempty"`
|
2022-11-27 21:08:34 +01:00
|
|
|
// GUI
|
|
|
|
LastOpenChat string `json:"last_open_chat,omitempty"`
|
|
|
|
SoundNotification bool `json:"sound_notification,omitempty"`
|
|
|
|
DefaultNotificationSound string `json:"default_notification_sound,omitempty"`
|
|
|
|
NotificationVibe string `json:"notification_vibe,omitempty"`
|
|
|
|
DefaultNotificationVibe string `json:"default_notification_vibe,omitempty"`
|
|
|
|
NotificationLED string `json:"notification_led,omitempty"`
|
|
|
|
DefaultNotificationLEDColor string `json:"default_notification_led_color,omitempty"`
|
|
|
|
VisualNotification bool `json:"visual_notification,omitempty"`
|
|
|
|
VisualNotifiactionModes string `json:"visual_notifiaction_modes,omitempty"`
|
|
|
|
PrivateChatNotifiactions bool `json:"private_chat_notifiactions,omitempty"`
|
|
|
|
GroupChatNotifiactions bool `json:"group_chat_notifiactions,omitempty"`
|
|
|
|
ChannelNotifications bool `json:"channel_notifications,omitempty"`
|
2023-02-15 22:08:17 +01:00
|
|
|
// Debug
|
|
|
|
DbSuffix string `json:"db_suffix,omitempty"`
|
2023-01-08 22:57:17 +01:00
|
|
|
|
2022-11-27 21:08:34 +01:00
|
|
|
// Inner
|
2023-02-15 22:08:17 +01:00
|
|
|
memoryPassword string `json:"memory_password,omitempty"`
|
|
|
|
additionalPasswords []string `json:"additional_passwords,omitempty"`
|
|
|
|
me *Identity `json:"me,omitempty"`
|
2022-11-27 21:08:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var instance *Config
|
|
|
|
var once sync.Once
|
|
|
|
|
|
|
|
func GetConfig() *Config {
|
|
|
|
once.Do(func() {
|
|
|
|
instance = &Config{}
|
|
|
|
})
|
|
|
|
return instance
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) Load(filename string) error {
|
2022-12-02 23:18:13 +01:00
|
|
|
data, err := os.ReadFile(filename)
|
2022-11-27 21:08:34 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = json.Unmarshal(data, c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) Save(filename string) error {
|
|
|
|
data, err := json.Marshal(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-02 23:18:13 +01:00
|
|
|
os.WriteFile(filename, data, 0644)
|
2022-11-27 21:08:34 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) SetMemPass(pass string) {
|
|
|
|
c.memoryPassword = pass
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) GetMemPass() string {
|
|
|
|
return c.memoryPassword
|
|
|
|
}
|
2023-01-07 00:39:05 +01:00
|
|
|
|
|
|
|
func (c *Config) SaveIdentity() error {
|
|
|
|
return c.me.Save()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) Clean() {
|
|
|
|
c.additionalPasswords = []string{}
|
|
|
|
}
|