-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
133 lines (109 loc) · 3 KB
/
utils.go
File metadata and controls
133 lines (109 loc) · 3 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"net"
"os"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
func (a *App) findPossibleIPAddresses() {
interfaces, err := net.Interfaces()
if err != nil {
a.AlertDialog("Error finding IP addresses", err.Error())
return
}
possibleAddresses := make([]string, 0)
// Iterate through the interfaces to find the first non-loopback address
for _, iface := range interfaces {
// Skip loopback interfaces (127.0.0.1, etc.)
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := iface.Addrs()
if err != nil {
LogError("Failed to get addresses for interface %s: %s", iface.Name, err.Error())
continue
}
// Iterate over the addresses and look for an IPv4 address
for _, addr := range addrs {
// Check if the address is an IPv4 address
if ipNet, ok := addr.(*net.IPNet); ok && ipNet.IP.To4() != nil {
possibleAddresses = append(possibleAddresses, ipNet.IP.String())
}
}
}
a.sacnConfig.PossibleIpAddresses = possibleAddresses
LogInfo("Found %d IP address(es): %v", len(possibleAddresses), possibleAddresses)
if len(possibleAddresses) == 0 {
a.AlertDialog("No IP addresses found", "This should not happen. Make sure you have a network interface active.")
return
}
a.sacnConfig.IpAddress = possibleAddresses[0]
LogInfo("Selected IP address: %s", possibleAddresses[0])
}
func (a *App) LoadFile() string {
file, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Load Följe Configuration",
Filters: []runtime.FileFilter{
{
DisplayName: "Följe Configurations (*.fconf)",
Pattern: "*.fconf",
},
}})
if err != nil {
runtime.LogError(a.ctx, err.Error())
return ""
}
// User cancelled the dialog
if file == "" {
return ""
}
data, err := os.ReadFile(file)
if err != nil {
runtime.LogError(a.ctx, err.Error())
return "{}"
}
LogInfo("Loaded config from file: %s", file)
// Save the config path to preferences
a.updateLastConfigPath(file)
return string(data)
}
func (a *App) LoadFileFromPath(path string) string {
if path == "" {
return "{}"
}
data, err := os.ReadFile(path)
if err != nil {
runtime.LogError(a.ctx, err.Error())
return "{}"
}
LogInfo("Loaded config from path: %s", path)
return string(data)
}
func (a *App) SaveFile(content string) bool {
file, err := runtime.SaveFileDialog(a.ctx, runtime.SaveDialogOptions{
Title: "Save Följe Configuration",
Filters: []runtime.FileFilter{
{
DisplayName: "Följe Configurations (*.fconf)",
Pattern: "*.fconf",
},
},
DefaultFilename: "conf.fconf",
})
if err != nil {
LogError("Failed to open save dialog: %s", err.Error())
return false
}
// User cancelled the dialog
if file == "" {
return false
}
err = os.WriteFile(file, []byte(content), 0644)
if err != nil {
LogError("Failed to write config file %s: %s", file, err.Error())
return false
}
LogInfo("Saved config to file: %s", file)
// Save the config path to preferences
a.updateLastConfigPath(file)
return true
}