Skip to content

Commit

Permalink
chore: print more log
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Jun 29, 2024
1 parent 4743a8f commit 5343c25
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
7 changes: 7 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/bitxeno/atvloadly/internal/manager"
"github.com/bitxeno/atvloadly/internal/task"
"github.com/bitxeno/atvloadly/web"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -82,9 +83,15 @@ func action(c *cli.Context) error {
_ = task.ScheduleRefreshApps()
manager.StartDeviceManager()

printVersion()
port := conf.Server.Port
if c.Int("port") > 0 {
port = c.Int("port")
}
return web.Run(conf.Server.ListenAddr, port)
}

func printVersion() {
color.New(color.FgGreen).Print("Starting server version: ")
color.New(color.FgCyan).Printf("%s@%s@%v\n", app.Version.Version, app.Version.BuildDate, app.Mode)
}
24 changes: 12 additions & 12 deletions internal/manager/device_manager_avahi.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ func (dm *DeviceManager) Start() {
if err != nil {
log.Err(err).Msgf("GetHostName() failed: ")
}
log.Println("GetHostName()", host)
log.Tracef("GetHostName(): %s", host)

fqdn, err := server.GetHostNameFqdn()
if err != nil {
log.Err(err).Msgf("GetHostNameFqdn() failed: ")
}
log.Println("GetHostNameFqdn()", fqdn)
log.Tracef("GetHostNameFqdn(): %s", fqdn)

s, err := server.GetAlternativeHostName(host)
if err != nil {
log.Err(err).Msgf("GetAlternativeHostName() failed: ")
}
log.Println("GetAlternativeHostName()", s)
log.Tracef("GetAlternativeHostName(): %s", s)

i, err := server.GetAPIVersion()
if err != nil {
log.Err(err).Msgf("GetAPIVersion() failed: ")
}
log.Println("GetAPIVersion()", i)
log.Tracef("GetAPIVersion(): %s", i)

hn, err := server.ResolveHostName(avahi.InterfaceUnspec, avahi.ProtoUnspec, fqdn, avahi.ProtoUnspec, 0)
if err != nil {
log.Err(err).Msgf("ResolveHostName() failed: ")
}
log.Println("ResolveHostName:", hn)
log.Tracef("ResolveHostName: %s", hn)

sb, err := server.ServiceBrowserNew(avahi.InterfaceUnspec, avahi.ProtoUnspec, mdnsService, mdnsServiceDomain, 0)
if err != nil {
Expand All @@ -81,19 +81,19 @@ func (dm *DeviceManager) Start() {
for {
select {
case service = <-sb.AddChannel:
log.Println("ServiceBrowser ADD: ", service)
log.Tracef("ServiceBrowser ADD: %s", service)

service, err := server.ResolveService(service.Interface, service.Protocol, service.Name,
service.Type, service.Domain, avahi.ProtoUnspec, 0)
if err == nil {
log.Println(" RESOLVED >>", service.Address)
log.Tracef(" RESOLVED >> %s", service.Address)

macAddr := strings.Split(service.Name, "@")[0]
name := strings.TrimSuffix(service.Host, ".local")
// 检查是否已连接
lockdownDevices, err := loadLockdownDevices()
if err != nil {
log.Println(err)
log.Err(err).Msg("loadLockdownDevices error: ")
continue
}

Expand All @@ -112,14 +112,14 @@ func (dm *DeviceManager) Start() {
}
}
case service = <-sb.RemoveChannel:
log.Println("ServiceBrowser REMOVE: ", service)
log.Tracef("ServiceBrowser REMOVE: %s", service)
case service = <-sbPairable.AddChannel:
log.Println("ServiceBrowser ADD: ", service)
log.Tracef("ServiceBrowser ADD: %s", service)

service, err := server.ResolveService(service.Interface, service.Protocol, service.Name,
service.Type, service.Domain, avahi.ProtoUnspec, 0)
if err == nil {
log.Println(" RESOLVED >>", service.Address)
log.Tracef(" RESOLVED >> %s", service.Address)

// 添加可配对设备
macAddr := strings.Split(service.Name, "@")[0]
Expand All @@ -138,7 +138,7 @@ func (dm *DeviceManager) Start() {
}

case service = <-sbPairable.RemoveChannel:
log.Println("ServiceBrowser REMOVE: ", service)
log.Tracef("ServiceBrowser REMOVE: %s", service)
macAddr := strings.Split(service.Name, "@")[0]
udid := fmt.Sprintf("fff%sfff", macAddr)
dm.devices.Delete(udid)
Expand Down
6 changes: 3 additions & 3 deletions internal/manager/lockdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"os"

"github.com/bitxeno/atvloadly/internal/app"
"github.com/bitxeno/atvloadly/internal/log"
"github.com/bitxeno/atvloadly/internal/model"
"github.com/bitxeno/atvloadly/internal/utils"
"howett.net/plist"
)

func loadLockdownDevices() (map[string]model.LockdownDevice, error) {
log.Infof("Load lockdown from path: %s", app.Config.App.LockdownDir)
files, err := os.ReadDir(app.Config.App.LockdownDir)
if err != nil {
fmt.Println(err)
// return nil, err

log.Err(err).Msg("Read lockdown dir error: ")
devices := map[string]model.LockdownDevice{}
return devices, nil
}
Expand Down
1 change: 1 addition & 0 deletions internal/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,6 @@ func GetCurrentInstallingApps() []model.InstalledApp {
}

func ReloadTask() error {
log.Info("Reload task...")
return instance.RunSchedule()
}
1 change: 1 addition & 0 deletions internal/tty/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (t *TTY) SetENV(environ []string) {
}

func (t *TTY) Close() {
fmt.Println("tty close")
t.pl.Close()
}

Expand Down

0 comments on commit 5343c25

Please sign in to comment.