Skip to content

Commit b89d4b0

Browse files
committed
feat: show hostname or IP when running
1 parent c52085d commit b89d4b0

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

FyneApp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Website = "https://fujinet.online"
55
Name = "TNFS Server Manager"
66
ID = "org.fujinet.tnfs-ui"
77
Version = "0.0.1"
8-
Build = 12
8+
Build = 18

internal/config/config.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"fmt"
5+
"net"
56
"os"
67
"os/exec"
78
"path/filepath"
@@ -17,6 +18,7 @@ const (
1718
type Config struct {
1819
ExePath string
1920
TnfsRootPath string
21+
Hostname string
2022
}
2123

2224
func (c *Config) UpdateRootPath(newPath string) {
@@ -27,15 +29,37 @@ func (c *Config) UpdateRootPath(newPath string) {
2729
}
2830

2931
func LoadConfig() (*Config, error) {
30-
rootPath := loadDefaultRootPath()
3132
exePath, err := locateTnfsdExecutable()
3233
if err != nil {
3334
return &Config{}, err
3435
}
35-
cfg := &Config{ExePath: exePath, TnfsRootPath: rootPath}
36+
cfg := &Config{
37+
ExePath: exePath,
38+
TnfsRootPath: loadDefaultRootPath(),
39+
Hostname: getHostnameOrIP(),
40+
}
3641
return cfg, nil
3742
}
3843

44+
func getHostnameOrIP() string {
45+
host, err := os.Hostname()
46+
if err == nil && host != "" {
47+
return host
48+
}
49+
addrs, err := net.InterfaceAddrs()
50+
if err != nil {
51+
return ""
52+
}
53+
for _, addr := range addrs {
54+
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
55+
if ipnet.IP.To4() != nil {
56+
return ipnet.IP.String()
57+
}
58+
}
59+
}
60+
return ""
61+
}
62+
3963
func locateTnfsdExecutable() (string, error) {
4064
dir := "."
4165
exeName := "tnfsd"

internal/ui/tab_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func makeServerTab(ui *UI, server *tnfs.Server) *fyne.Container {
7474

7575
startButton.Disable()
7676
case tnfs.STARTED:
77-
msg = "Running"
77+
msg = "Running on " + ui.cfg.Hostname
7878
icon = theme.NewColoredResource(theme.MediaRecordIcon(), theme.ColorNameSuccess)
7979

8080
startButton.Hide()

0 commit comments

Comments
 (0)