тест подключения к впн (vibe-kanban 618b1de6)
Функционал подключения уже реализован. В главном окне кнопка для подключения остается неактивной даже при импортированном и выбранном конфиге. Нужно сделать так чтобы кнопка становилась активной при выборе конфига. Также проверь - реализована ли логика подключения при нажатии на кнопку.
This commit is contained in:
BIN
hamy-vpn-client-test.exe
Normal file
BIN
hamy-vpn-client-test.exe
Normal file
Binary file not shown.
67
main.go
67
main.go
@@ -38,6 +38,7 @@ var (
|
|||||||
currentProcess *exec.Cmd
|
currentProcess *exec.Cmd
|
||||||
configs []Config // Store all configurations
|
configs []Config // Store all configurations
|
||||||
activeConfig int // Index of the active config (-1 if none)
|
activeConfig int // Index of the active config (-1 if none)
|
||||||
|
configFilePath string = "configs.json" // Path to save/load configs
|
||||||
)
|
)
|
||||||
|
|
||||||
// checkSingBox checks if sing-box.exe exists in the bin folder
|
// checkSingBox checks if sing-box.exe exists in the bin folder
|
||||||
@@ -49,6 +50,40 @@ func checkSingBox() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loadConfigs loads configurations from file at startup
|
||||||
|
func loadConfigs() error {
|
||||||
|
data, err := os.ReadFile(configFilePath)
|
||||||
|
if err != nil {
|
||||||
|
// If file doesn't exist, it's not an error - just start with empty configs
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &configs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// saveConfigs saves configurations to file
|
||||||
|
func saveConfigs() error {
|
||||||
|
data, err := json.MarshalIndent(configs, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(configFilePath, data, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// isValidVLESS checks if the given URL is a valid VLESS URL
|
// isValidVLESS checks if the given URL is a valid VLESS URL
|
||||||
func isValidVLESS(vlessURL string) bool {
|
func isValidVLESS(vlessURL string) bool {
|
||||||
// Basic validation for VLESS URL format
|
// Basic validation for VLESS URL format
|
||||||
@@ -74,6 +109,9 @@ func isValidVLESS(vlessURL string) bool {
|
|||||||
// addConfig adds a new configuration to the list
|
// addConfig adds a new configuration to the list
|
||||||
func addConfig(title, url string) {
|
func addConfig(title, url string) {
|
||||||
configs = append(configs, Config{Title: title, URL: url})
|
configs = append(configs, Config{Title: title, URL: url})
|
||||||
|
|
||||||
|
// Save configurations to file
|
||||||
|
saveConfigs()
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateConfig updates an existing configuration
|
// updateConfig updates an existing configuration
|
||||||
@@ -81,6 +119,9 @@ func updateConfig(index int, title, url string) {
|
|||||||
if index >= 0 && index < len(configs) {
|
if index >= 0 && index < len(configs) {
|
||||||
configs[index].Title = title
|
configs[index].Title = title
|
||||||
configs[index].URL = url
|
configs[index].URL = url
|
||||||
|
|
||||||
|
// Save configurations to file
|
||||||
|
saveConfigs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +135,9 @@ func removeConfig(index int) {
|
|||||||
if activeConfig >= len(configs) {
|
if activeConfig >= len(configs) {
|
||||||
activeConfig = -1
|
activeConfig = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save configurations to file
|
||||||
|
saveConfigs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,6 +535,9 @@ func main() {
|
|||||||
// Set the window size to 200x300 as requested
|
// Set the window size to 200x300 as requested
|
||||||
myWindow.Resize(fyne.NewSize(200, 300))
|
myWindow.Resize(fyne.NewSize(200, 300))
|
||||||
|
|
||||||
|
// Load configurations from file at startup
|
||||||
|
loadConfigs()
|
||||||
|
|
||||||
// Initialize active config to -1 (no config selected)
|
// Initialize active config to -1 (no config selected)
|
||||||
activeConfig = -1
|
activeConfig = -1
|
||||||
|
|
||||||
@@ -599,10 +646,12 @@ func main() {
|
|||||||
statusLabel.Refresh()
|
statusLabel.Refresh()
|
||||||
})
|
})
|
||||||
connectButton.Importance = widget.HighImportance
|
connectButton.Importance = widget.HighImportance
|
||||||
|
|
||||||
|
// Initially disable the button if no configs are available
|
||||||
if len(configs) == 0 {
|
if len(configs) == 0 {
|
||||||
connectButton.Disable() // Disable initially until a config is selected
|
connectButton.Disable()
|
||||||
} else {
|
} else {
|
||||||
connectButton.Enable() // Enable if we have configs
|
connectButton.Enable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configurations button - opens a separate window
|
// Configurations button - opens a separate window
|
||||||
@@ -632,6 +681,11 @@ func main() {
|
|||||||
// Refresh the list
|
// Refresh the list
|
||||||
refreshList()
|
refreshList()
|
||||||
importEntry.SetText("")
|
importEntry.SetText("")
|
||||||
|
|
||||||
|
// Enable connect button if we have configs
|
||||||
|
if len(configs) > 0 {
|
||||||
|
connectButton.Enable()
|
||||||
|
}
|
||||||
} else if url != "" {
|
} else if url != "" {
|
||||||
dialog.ShowError(errors.New("Невалидная ссылка"), configWindow)
|
dialog.ShowError(errors.New("Невалидная ссылка"), configWindow)
|
||||||
}
|
}
|
||||||
@@ -688,6 +742,11 @@ func main() {
|
|||||||
|
|
||||||
// Refresh the list
|
// Refresh the list
|
||||||
refreshList()
|
refreshList()
|
||||||
|
|
||||||
|
// Disable connect button if no configs remain or current config was deleted
|
||||||
|
if len(configs) == 0 || activeConfig == -1 {
|
||||||
|
connectButton.Disable()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
configWindow)
|
configWindow)
|
||||||
@@ -698,6 +757,10 @@ func main() {
|
|||||||
newListContainer.OnSelected = func(id widget.ListItemID) {
|
newListContainer.OnSelected = func(id widget.ListItemID) {
|
||||||
activeConfig = id
|
activeConfig = id
|
||||||
dialog.ShowInformation("Config Selected", fmt.Sprintf("Active config: %s", configs[id].Title), configWindow)
|
dialog.ShowInformation("Config Selected", fmt.Sprintf("Active config: %s", configs[id].Title), configWindow)
|
||||||
|
|
||||||
|
// Enable the connect button since a config is selected
|
||||||
|
connectButton.Enable()
|
||||||
|
|
||||||
configWindow.Close()
|
configWindow.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user