config

package
v0.11.0-beta.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Enhanced config.go for the client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureClientConfigDir

func EnsureClientConfigDir() error

EnsureClientConfigDir creates the resolved client config directory if needed.

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the platform-appropriate configuration directory

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the full path to the config file using the same directory rules as ResolveClientConfigDir (MARCHAT_CONFIG_DIR when set, otherwise GetConfigDir).

func GetKeystorePath

func GetKeystorePath() (string, error)

GetKeystorePath returns the full path to the keystore file. Resolution order: (1) keystore next to config (ResolveClientConfigDir/keystore.dat); (2) the standard per-user marchat directory from GetConfigDir when that file exists (so an existing keystore is still found if MARCHAT_CONFIG_DIR is set but has no keystore yet); (3) ./keystore.dat in the process working directory (legacy); (4) otherwise the primary path where a new keystore would be created. Legacy cwd is last so a stray keystore in a repo clone does not override the real user profile keystore.

func MigrateKeystoreToNewLocation

func MigrateKeystoreToNewLocation() error

MigrateKeystoreToNewLocation copies ./keystore.dat from the working directory into ResolveClientConfigDir()/keystore.dat when the destination does not exist yet.

func NextDefaultProfileName

func NextDefaultProfileName(profiles []ConnectionProfile) string

NextDefaultProfileName returns "Profile-<n>" where n is one greater than the highest existing "Profile-<digits>" name. Falls back to len(profiles)+1 when no numbered profiles exist (avoids colliding after duplicates inflated len).

func ResolveClientConfigDir

func ResolveClientConfigDir() string

ResolveClientConfigDir returns the client configuration directory using the same rules as the marchat client binary: MARCHAT_CONFIG_DIR if set, otherwise the per-user application data directory from GetConfigDir (same when developing from a git clone or using a release binary). The server uses ./config in-repo for .env and the database; the client does not use that path unless you set MARCHAT_CONFIG_DIR.

func RunProfileSelection

func RunProfileSelection(profiles []ConnectionProfile) (int, error)

RunProfileSelection runs the profile selection UI (for quick-start)

func RunSensitiveDataPrompt

func RunSensitiveDataPrompt(isAdmin, useE2E bool) (adminKey, keystorePass string, err error)

RunSensitiveDataPrompt runs the sensitive data prompt UI

func SaveConfig

func SaveConfig(path string, cfg Config) error

Types

type Config

type Config struct {
	// Connection settings
	Username  string `json:"username"`
	ServerURL string `json:"server_url"`

	// Admin settings (optional)
	IsAdmin  bool   `json:"is_admin,omitempty"`
	AdminKey string `json:"admin_key,omitempty"` // Note: Consider security implications

	// E2E Encryption settings (optional)
	UseE2E bool `json:"use_e2e,omitempty"`

	// UI settings
	Theme          string `json:"theme"`
	TwentyFourHour bool   `json:"twenty_four_hour"`
	SkipTLSVerify  bool   `json:"skip_tls_verify,omitempty"`

	// Bell notification settings (legacy - kept for backward compatibility)
	EnableBell    bool `json:"enable_bell,omitempty"`     // Enable/disable bell
	BellOnMention bool `json:"bell_on_mention,omitempty"` // Only bell on mentions

	// Enhanced notification settings
	NotificationMode     string `json:"notification_mode,omitempty"`     // "none", "bell", "desktop", "both"
	DesktopNotifications bool   `json:"desktop_notifications,omitempty"` // Enable desktop notifications
	DesktopOnMention     bool   `json:"desktop_on_mention,omitempty"`    // Desktop notify on mentions
	DesktopOnDM          bool   `json:"desktop_on_dm,omitempty"`         // Desktop notify on DMs
	DesktopOnAll         bool   `json:"desktop_on_all,omitempty"`        // Desktop notify on all messages
	QuietHoursEnabled    bool   `json:"quiet_hours_enabled,omitempty"`   // Enable quiet hours
	QuietHoursStart      int    `json:"quiet_hours_start,omitempty"`     // Quiet hours start (hour 0-23)
	QuietHoursEnd        int    `json:"quiet_hours_end,omitempty"`       // Quiet hours end (hour 0-23)

	// Quick start settings
	SaveCredentials bool  `json:"save_credentials"`
	LastUsed        int64 `json:"last_used,omitempty"`
}

func LoadConfig

func LoadConfig(path string) (Config, error)

func RunInteractiveConfig

func RunInteractiveConfig() (*Config, string, error)

RunInteractiveConfig runs the interactive configuration UI

type ConfigUIModel

type ConfigUIModel struct {
	// contains filtered or unexported fields
}

func NewConfigUI

func NewConfigUI() ConfigUIModel

func (ConfigUIModel) GetConfig

func (m ConfigUIModel) GetConfig() *Config

GetConfig returns the built configuration

func (ConfigUIModel) GetKeystorePassphrase

func (m ConfigUIModel) GetKeystorePassphrase() string

GetKeystorePassphrase returns the keystore passphrase

func (ConfigUIModel) Init

func (m ConfigUIModel) Init() tea.Cmd

func (ConfigUIModel) IsCancelled

func (m ConfigUIModel) IsCancelled() bool

IsCancelled returns true if the user cancelled the configuration

func (ConfigUIModel) IsFinished

func (m ConfigUIModel) IsFinished() bool

IsFinished returns true if the user completed the configuration

func (ConfigUIModel) Update

func (m ConfigUIModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (ConfigUIModel) View

func (m ConfigUIModel) View() string

type ConnectionProfile

type ConnectionProfile struct {
	Name      string `json:"name"`
	ServerURL string `json:"server_url"`
	Username  string `json:"username"`
	IsAdmin   bool   `json:"is_admin"`
	UseE2E    bool   `json:"use_e2e"`
	Theme     string `json:"theme,omitempty"`
	LastUsed  int64  `json:"last_used,omitempty"` // Unix timestamp
}

ConnectionProfile represents a saved connection profile

func RunEnhancedProfileSelection

func RunEnhancedProfileSelection(profiles []ConnectionProfile, icl *InteractiveConfigLoader) (*ConnectionProfile, error)

RunEnhancedProfileSelection runs the enhanced profile selection UI with management features

func RunEnhancedProfileSelectionWithNew

func RunEnhancedProfileSelectionWithNew(profiles []ConnectionProfile, icl *InteractiveConfigLoader) (*ConnectionProfile, bool, error)

RunEnhancedProfileSelectionWithNew runs the enhanced profile selection UI with "Create New" option

func RunProfileSelectionWithNew

func RunProfileSelectionWithNew(profiles []ConnectionProfile, icl *InteractiveConfigLoader) (*ConnectionProfile, bool, error)

RunProfileSelectionWithNew runs the profile selection UI with "Create New" option Deprecated: Use RunEnhancedProfileSelectionWithNew instead

type InteractiveConfigLoader

type InteractiveConfigLoader struct {
	ConfigPath   string
	ProfilesPath string
	// contains filtered or unexported fields
}

InteractiveConfigLoader handles interactive configuration

func NewInteractiveConfigLoader

func NewInteractiveConfigLoader() (*InteractiveConfigLoader, error)

func (*InteractiveConfigLoader) AutoConnect

func (icl *InteractiveConfigLoader) AutoConnect() (*Config, error)

AutoConnect automatically connects to the most recently used profile

func (*InteractiveConfigLoader) FormatSanitizedLaunchCommand

func (icl *InteractiveConfigLoader) FormatSanitizedLaunchCommand(cfg *Config) string

FormatSanitizedLaunchCommand creates a version safe for logging (without sensitive data)

func (*InteractiveConfigLoader) LoadOrPromptConfig

func (icl *InteractiveConfigLoader) LoadOrPromptConfig(overrides map[string]interface{}) (*Config, string, string, string, error)

LoadOrPromptConfig loads existing config or prompts for new configuration

func (*InteractiveConfigLoader) LoadProfiles

func (icl *InteractiveConfigLoader) LoadProfiles() (*Profiles, error)

func (*InteractiveConfigLoader) PromptSensitiveData

func (icl *InteractiveConfigLoader) PromptSensitiveData(isAdmin, useE2E bool) (adminKey, keystorePass string, err error)

PromptSensitiveData prompts for admin key and/or keystore passphrase

func (*InteractiveConfigLoader) QuickStartConnect

func (icl *InteractiveConfigLoader) QuickStartConnect() (*Config, error)

QuickStartConnect shows profiles with management features and connects to selected one

func (*InteractiveConfigLoader) SaveProfiles

func (icl *InteractiveConfigLoader) SaveProfiles(profiles *Profiles) error

type ProfileOperation

type ProfileOperation int

ProfileOperation represents different operations that can be performed

const (
	ProfileOpNone ProfileOperation = iota
	ProfileOpView
	ProfileOpRename
	ProfileOpDelete
)

type ProfileSelectionModel

type ProfileSelectionModel struct {
	// contains filtered or unexported fields
}

ProfileSelectionModel handles profile selection UI with management features

func NewEnhancedProfileSelectionModel

func NewEnhancedProfileSelectionModel(profiles []ConnectionProfile, showNewOption bool, icl *InteractiveConfigLoader) ProfileSelectionModel

func NewProfileSelectionModel

func NewProfileSelectionModel(profiles []ConnectionProfile, showNewOption bool) ProfileSelectionModel

func (ProfileSelectionModel) GetChoice

func (m ProfileSelectionModel) GetChoice() int

func (ProfileSelectionModel) GetSelectedProfile

func (m ProfileSelectionModel) GetSelectedProfile() *ConnectionProfile

GetSelectedProfile returns the actual selected profile object

func (ProfileSelectionModel) Init

func (m ProfileSelectionModel) Init() tea.Cmd

func (ProfileSelectionModel) IsCancelled

func (m ProfileSelectionModel) IsCancelled() bool

func (ProfileSelectionModel) IsCreateNew

func (m ProfileSelectionModel) IsCreateNew() bool

IsCreateNew returns true if user selected "Create New Profile"

func (ProfileSelectionModel) IsModified

func (m ProfileSelectionModel) IsModified() bool

func (ProfileSelectionModel) IsSelected

func (m ProfileSelectionModel) IsSelected() bool

func (ProfileSelectionModel) Update

func (m ProfileSelectionModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (ProfileSelectionModel) View

func (m ProfileSelectionModel) View() string

type Profiles

type Profiles struct {
	Default  string              `json:"default,omitempty"`
	Profiles []ConnectionProfile `json:"profiles"`
}

type SensitiveDataModel

type SensitiveDataModel struct {
	// contains filtered or unexported fields
}

SensitiveDataModel handles prompting for admin key and keystore passphrase

func NewSensitiveDataPrompt

func NewSensitiveDataPrompt(isAdmin, useE2E bool) SensitiveDataModel

func (SensitiveDataModel) GetAdminKey

func (m SensitiveDataModel) GetAdminKey() string

func (SensitiveDataModel) GetKeystorePassphrase

func (m SensitiveDataModel) GetKeystorePassphrase() string

func (SensitiveDataModel) Init

func (m SensitiveDataModel) Init() tea.Cmd

func (SensitiveDataModel) IsCancelled

func (m SensitiveDataModel) IsCancelled() bool

func (SensitiveDataModel) IsFinished

func (m SensitiveDataModel) IsFinished() bool

func (SensitiveDataModel) Update

func (m SensitiveDataModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (SensitiveDataModel) View

func (m SensitiveDataModel) View() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL