Jelajahi Sumber

refactor(cmd): idk

ayn2op 5 bulan lalu
induk
melakukan
01cb4c043b
1 mengubah file dengan 9 tambahan dan 9 penghapusan
  1. 9 9
      cmd/application.go

+ 9 - 9
cmd/application.go

@@ -41,22 +41,22 @@ func newApplication(cfg *config.Config) *application {
 }
 
 func (a *application) run(token string) error {
+	var root tview.Primitive
 	if token == "" {
-		loginForm := login.NewForm(a.Application, a.cfg, func(token string) {
+		root = login.NewForm(a.Application, a.cfg, func(token string) {
 			if err := a.run(token); err != nil {
 				slog.Error("failed to run application", "err", err)
 			}
 		})
-
-		return a.SetRoot(loginForm, true).Run()
-	}
-
-	a.chatView = newChatView(a.Application, a.cfg)
-	if err := openState(token); err != nil {
-		return err
+	} else {
+		a.chatView = newChatView(a.Application, a.cfg)
+		root = a.chatView
+		if err := openState(token); err != nil {
+			return err
+		}
 	}
 
-	return a.SetRoot(a.chatView, true).Run()
+	return a.SetRoot(root, true).Run()
 }
 
 func (a *application) quit() {