fix: save history

This commit is contained in:
2026-02-05 01:14:44 +08:00
parent 3588c49d7d
commit 4b7a4eb36d
6 changed files with 51 additions and 13 deletions

View File

@@ -77,6 +77,7 @@ func Load() *Config {
}
v.SetDefault("host_name", defaultHostName)
v.SetDefault("id", uuid.New().String())
v.SetDefault("save_history", true)
v.SetConfigFile(configFile)
v.SetConfigType("json")
@@ -182,3 +183,16 @@ func (c *Config) GetSaveHistory() bool {
func (c *Config) GetVersion() string {
return Version
}
func (c *Config) SetWindowState(state WindowState) {
c.mu.Lock()
defer c.mu.Unlock()
c.WindowState = state
c.v.Set("window_state", state)
}
func (c *Config) GetWindowState() WindowState {
c.mu.RLock()
defer c.mu.RUnlock()
return c.WindowState
}

View File

@@ -15,7 +15,7 @@ func (s *Service) SaveHistory() {
if err != nil {
return
}
file, err := os.OpenFile(historyPath, os.O_CREATE|os.O_RDWR, os.FileMode(0644))
file, err := os.OpenFile(historyPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
return
}

View File

@@ -65,7 +65,7 @@ func (s *Service) Start() {
}
func (s *Service) GetTransferList() []*Transfer {
var requests []*Transfer
var requests []*Transfer = make([]*Transfer, 0)
s.transferList.Range(func(key, value any) bool {
requests = append(requests, value.(*Transfer))
return true