-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.go
More file actions
44 lines (37 loc) · 880 Bytes
/
storage.go
File metadata and controls
44 lines (37 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"encoding/json"
"log"
"os"
"path/filepath"
)
func getHistoryFilePath() string {
homeDir, _ := os.UserHomeDir()
return filepath.Join(homeDir, ".clipboard-history.json")
}
func saveHistory() {
data, err := json.MarshalIndent(clipHistory, "", " ")
if err != nil {
log.Printf("Error marshaling history: %v", err)
return
}
err = os.WriteFile(getHistoryFilePath(), data, 0644)
if err != nil {
log.Printf("Error saving history: %v", err)
}
}
func loadHistory() {
filePath := getHistoryFilePath()
data, err := os.ReadFile(filePath)
if err != nil {
if !os.IsNotExist(err) {
log.Printf("Error reading history file: %v", err)
}
return
}
err = json.Unmarshal(data, clipHistory)
if err != nil {
log.Printf("Error unmarshaling history: %v", err)
}
log.Printf("Loaded %d clipboard items from history", len(clipHistory.Items))
}