"log"
"os"
"os/signal"
+ "runtime"
"syscall"
)
-
func main() {
_, cancelRoot := context.WithCancel(context.Background())
cancelRoot()
}()
- client := hotline.NewClient("", logger)
+ cfgPath := defaultConfigPath()
+
+ client := hotline.NewClient(cfgPath, logger)
client.DebugBuf = db
client.UI.Start()
"warn": zap.WarnLevel,
"error": zap.ErrorLevel,
}
+
+func defaultConfigPath() (cfgPath string) {
+ os := runtime.GOOS
+ switch os {
+ case "windows":
+ cfgPath = "mobius-client-config.yaml"
+ case "darwin":
+ cfgPath = "/usr/local/etc/mobius-client-config.yaml"
+ case "linux":
+ cfgPath = "/usr/local/etc/mobius-client-config.yaml"
+ default:
+ fmt.Printf("unsupported OS")
+ }
+
+ return cfgPath
+}
"time"
)
-const clientConfigPath = "/usr/local/etc/mobius-client-config.yaml"
const (
trackerListPage = "trackerList"
)
}
type Client struct {
+ cfgPath string
DebugBuf *DebugBuffer
Connection net.Conn
Login *[]byte
// TODO: handle err
}
// TODO: handle err
- _ = ioutil.WriteFile(clientConfigPath, out, 0666)
+ err = ioutil.WriteFile(ui.HLClient.cfgPath, out, 0666)
+ if err != nil {
+ println(ui.HLClient.cfgPath)
+ panic(err)
+ }
ui.Pages.RemovePage("settings")
})
settingsForm.SetBorder(true)
}
}
-func NewClient(username string, logger *zap.SugaredLogger) *Client {
+func NewClient(cfgPath string, logger *zap.SugaredLogger) *Client {
c := &Client{
+ cfgPath: cfgPath,
Logger: logger,
activeTasks: make(map[uint32]*Transaction),
Handlers: clientHandlers,
}
c.UI = NewUI(c)
- prefs, err := readConfig(clientConfigPath)
+ prefs, err := readConfig(cfgPath)
if err != nil {
- return c
+ fmt.Printf("unable to read config file")
+ logger.Fatal("unable to read config file", "path", cfgPath)
}
c.pref = prefs