|
@@ -1,18 +1,15 @@
|
|
|
package cmd
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "log/slog"
|
|
|
|
|
-
|
|
|
|
|
"github.com/ayn2op/discordo/internal/config"
|
|
"github.com/ayn2op/discordo/internal/config"
|
|
|
"github.com/ayn2op/discordo/internal/logger"
|
|
"github.com/ayn2op/discordo/internal/logger"
|
|
|
- "github.com/rivo/tview"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
|
discordState *State
|
|
discordState *State
|
|
|
|
|
|
|
|
cfg *config.Config
|
|
cfg *config.Config
|
|
|
- app = tview.NewApplication()
|
|
|
|
|
|
|
+ app *Application
|
|
|
mainFlex *MainFlex
|
|
mainFlex *MainFlex
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -27,34 +24,9 @@ func Run(token string) error {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // app must be initialized after configuration is loaded
|
|
|
|
|
+ app = newApplication()
|
|
|
// mainFlex must be initialized before opening a new state.
|
|
// mainFlex must be initialized before opening a new state.
|
|
|
mainFlex = newMainFlex()
|
|
mainFlex = newMainFlex()
|
|
|
- if token == "" {
|
|
|
|
|
- lf := NewLoginForm(func(token string, err error) {
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- app.Stop()
|
|
|
|
|
- slog.Error("failed to login", "err", err)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if err := openState(token); err != nil {
|
|
|
|
|
- app.Stop()
|
|
|
|
|
- slog.Error("failed to open state", "err", err)
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- app.SetRoot(mainFlex, true)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- app.SetRoot(lf, true)
|
|
|
|
|
- } else {
|
|
|
|
|
- if err := openState(token); err != nil {
|
|
|
|
|
- return err
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- app.SetRoot(mainFlex, true)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- app.EnableMouse(cfg.Mouse)
|
|
|
|
|
- return app.Run()
|
|
|
|
|
|
|
+ return app.Run(token)
|
|
|
}
|
|
}
|