fix build macos
This commit is contained in:
46
client/internal/winapi/wifi_darwin.go
Normal file
46
client/internal/winapi/wifi_darwin.go
Normal file
@@ -0,0 +1,46 @@
|
||||
//go:build darwin
|
||||
|
||||
package winapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetWifiConnection đọc SSID và BSSID từ ipconfig (macOS)
|
||||
func GetWifiConnection() WifiConnection {
|
||||
// Find Wi-Fi interface dynamically
|
||||
wifiInterface := "en0"
|
||||
cmdPort := exec.Command("networksetup", "-listallhardwareports")
|
||||
if outPort, err := cmdPort.Output(); err == nil {
|
||||
lines := strings.Split(string(outPort), "\n")
|
||||
for i := 0; i < len(lines)-1; i++ {
|
||||
if strings.Contains(lines[i], "Hardware Port: Wi-Fi") {
|
||||
next := strings.TrimSpace(lines[i+1])
|
||||
if strings.HasPrefix(next, "Device:") {
|
||||
wifiInterface = strings.TrimSpace(strings.TrimPrefix(next, "Device:"))
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cmd := exec.Command("ipconfig", "getsummary", wifiInterface)
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
if err := cmd.Run(); err != nil {
|
||||
return WifiConnection{}
|
||||
}
|
||||
|
||||
var conn WifiConnection
|
||||
for _, line := range strings.Split(out.String(), "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if strings.HasPrefix(trimmed, "SSID :") {
|
||||
conn.SSID = strings.TrimSpace(strings.TrimPrefix(trimmed, "SSID :"))
|
||||
} else if strings.HasPrefix(trimmed, "BSSID :") {
|
||||
conn.BSSID = normalizeMAC(strings.TrimSpace(strings.TrimPrefix(trimmed, "BSSID :")))
|
||||
}
|
||||
}
|
||||
return conn
|
||||
}
|
||||
8
client/internal/winapi/wifi_other.go
Normal file
8
client/internal/winapi/wifi_other.go
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build !windows && !darwin
|
||||
|
||||
package winapi
|
||||
|
||||
// GetWifiConnection returns an empty WifiConnection stub for other systems
|
||||
func GetWifiConnection() WifiConnection {
|
||||
return WifiConnection{}
|
||||
}
|
||||
40
client/internal/winapi/wifi_windows.go
Normal file
40
client/internal/winapi/wifi_windows.go
Normal file
@@ -0,0 +1,40 @@
|
||||
//go:build windows
|
||||
|
||||
package winapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// GetWifiConnection đọc SSID và BSSID từ netsh (Windows)
|
||||
func GetWifiConnection() WifiConnection {
|
||||
cmd := exec.Command("netsh", "wlan", "show", "interfaces")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
if err := cmd.Run(); err != nil {
|
||||
return WifiConnection{}
|
||||
}
|
||||
|
||||
var conn WifiConnection
|
||||
for _, line := range strings.Split(out.String(), "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
lower := strings.ToLower(trimmed)
|
||||
if strings.HasPrefix(lower, "ssid") && !strings.Contains(lower, "bssid") {
|
||||
if v := valueAfterColon(trimmed); v != "" {
|
||||
conn.SSID = v
|
||||
}
|
||||
}
|
||||
// Windows: "AP BSSID" (EN) hoặc dòng có chứa "bssid" (locale khác)
|
||||
if strings.Contains(lower, "bssid") {
|
||||
if v := valueAfterColon(trimmed); v != "" {
|
||||
conn.BSSID = normalizeMAC(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
return conn
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package winapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// WifiConnection — SSID + BSSID (MAC) của điểm phát đang kết nối
|
||||
@@ -18,36 +15,6 @@ func GetWifiSSID() string {
|
||||
return GetWifiConnection().SSID
|
||||
}
|
||||
|
||||
// GetWifiConnection đọc SSID và BSSID từ netsh (Windows)
|
||||
func GetWifiConnection() WifiConnection {
|
||||
cmd := exec.Command("netsh", "wlan", "show", "interfaces")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
||||
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
if err := cmd.Run(); err != nil {
|
||||
return WifiConnection{}
|
||||
}
|
||||
|
||||
var conn WifiConnection
|
||||
for _, line := range strings.Split(out.String(), "\n") {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
lower := strings.ToLower(trimmed)
|
||||
if strings.HasPrefix(lower, "ssid") && !strings.Contains(lower, "bssid") {
|
||||
if v := valueAfterColon(trimmed); v != "" {
|
||||
conn.SSID = v
|
||||
}
|
||||
}
|
||||
// Windows: "AP BSSID" (EN) hoặc dòng có chứa "bssid" (locale khác)
|
||||
if strings.Contains(lower, "bssid") {
|
||||
if v := valueAfterColon(trimmed); v != "" {
|
||||
conn.BSSID = normalizeMAC(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
||||
func valueAfterColon(line string) string {
|
||||
idx := strings.Index(line, ":")
|
||||
if idx < 0 {
|
||||
|
||||
30
client/internal/winapi/window_darwin.go
Normal file
30
client/internal/winapi/window_darwin.go
Normal file
@@ -0,0 +1,30 @@
|
||||
//go:build darwin
|
||||
|
||||
package winapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// ActivateAppWindow — đưa cửa sổ app lên trước
|
||||
func ActivateAppWindow(titleHint string) {
|
||||
pid := os.Getpid()
|
||||
script := fmt.Sprintf(`tell application "System Events" to set frontmost of first process whose unix id is %d to true`, pid)
|
||||
cmd := exec.Command("osascript", "-e", script)
|
||||
_ = cmd.Run()
|
||||
}
|
||||
|
||||
// PlayNotifySound — beep hệ thống macOS
|
||||
func PlayNotifySound() {
|
||||
cmd := exec.Command("osascript", "-e", "beep")
|
||||
_ = cmd.Run()
|
||||
}
|
||||
|
||||
// ShowWarningMessageBox hiển thị hộp thoại cảnh báo macOS bất đồng bộ
|
||||
func ShowWarningMessageBox(title, message string) {
|
||||
script := fmt.Sprintf(`display alert %q message %q`, title, message)
|
||||
cmd := exec.Command("osascript", "-e", script)
|
||||
_ = cmd.Start() // Run asynchronously
|
||||
}
|
||||
9
client/internal/winapi/window_other.go
Normal file
9
client/internal/winapi/window_other.go
Normal file
@@ -0,0 +1,9 @@
|
||||
//go:build !windows && !darwin
|
||||
|
||||
package winapi
|
||||
|
||||
func ActivateAppWindow(titleHint string) {}
|
||||
|
||||
func PlayNotifySound() {}
|
||||
|
||||
func ShowWarningMessageBox(title, message string) {}
|
||||
Reference in New Issue
Block a user