NewApp creates the root TUI application model.
(port int, secretKey string, hook *LogHook)
| 58 | |
| 59 | // NewApp creates the root TUI application model. |
| 60 | func NewApp(port int, secretKey string, hook *LogHook) App { |
| 61 | standalone := hook != nil |
| 62 | authRequired := !standalone |
| 63 | ti := textinput.New() |
| 64 | ti.CharLimit = 512 |
| 65 | ti.EchoMode = textinput.EchoPassword |
| 66 | ti.EchoCharacter = '*' |
| 67 | ti.SetValue(strings.TrimSpace(secretKey)) |
| 68 | ti.Focus() |
| 69 | |
| 70 | client := NewClient(port, secretKey) |
| 71 | app := App{ |
| 72 | activeTab: tabDashboard, |
| 73 | standalone: standalone, |
| 74 | logsEnabled: true, |
| 75 | authenticated: !authRequired, |
| 76 | authInput: ti, |
| 77 | dashboard: newDashboardModel(client), |
| 78 | config: newConfigTabModel(client), |
| 79 | auth: newAuthTabModel(client), |
| 80 | keys: newKeysTabModel(client), |
| 81 | oauth: newOAuthTabModel(client), |
| 82 | logs: newLogsTabModel(client, hook), |
| 83 | client: client, |
| 84 | initialized: [6]bool{ |
| 85 | tabDashboard: true, |
| 86 | tabLogs: true, |
| 87 | }, |
| 88 | } |
| 89 | |
| 90 | app.refreshTabs() |
| 91 | if authRequired { |
| 92 | app.initialized = [6]bool{} |
| 93 | } |
| 94 | app.setAuthInputPrompt() |
| 95 | return app |
| 96 | } |
| 97 | |
| 98 | func (a App) Init() tea.Cmd { |
| 99 | if !a.authenticated { |
no test coverage detected