diff --git a/app.go b/cmd/usbguard-tui/app.go similarity index 100% rename from app.go rename to cmd/usbguard-tui/app.go diff --git a/main.go b/cmd/usbguard-tui/main.go similarity index 84% rename from main.go rename to cmd/usbguard-tui/main.go index e28b7b2..f15f5ab 100644 --- a/main.go +++ b/cmd/usbguard-tui/main.go @@ -21,6 +21,11 @@ func main() { os.Exit(1) } + if _, err := guard.ListDevices(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + p := tea.NewProgram(newApp()) if _, err := p.Run(); err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/ui/model.go b/ui/model.go index 8e8ac0a..f9810ea 100644 --- a/ui/model.go +++ b/ui/model.go @@ -50,7 +50,6 @@ type Model struct { rulesManaged bool rulesWritable bool pendingRules []pendingRule - fatalShown bool ModalOpen bool } @@ -172,16 +171,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { case actionMsg: if msg.err != nil { - - if msg.err == guard.ErrPermission { - - if m.fatalShown { - return m, nil - } - m.fatalShown = true - return m, modal.Show("Permission Error", newPermissionModal(), - modal.WithModalStyle(permissionModalStyle())) - } return m, errorToast(msg.err) } return m, fetchDevices diff --git a/ui/permissionmodal.go b/ui/permissionmodal.go deleted file mode 100644 index ed97a74..0000000 --- a/ui/permissionmodal.go +++ /dev/null @@ -1,44 +0,0 @@ -package ui - -import ( - "strings" - - tea "charm.land/bubbletea/v2" - "charm.land/lipgloss/v2" - "github.com/anotherhadi/ilovetui/app" - "github.com/anotherhadi/ilovetui/modal" - "github.com/anotherhadi/ilovetui/style" -) - -type permissionModal struct{} - -func newPermissionModal() tea.Model { return permissionModal{} } - -func permissionModalStyle() modal.Styles { - s := modal.DefaultStyles() - s.Title = s.Title.Foreground(style.S.Error) - s.Border = s.Border.BorderForeground(style.S.Error) - return s -} - -func (permissionModal) Init() tea.Cmd { return nil } - -func (m permissionModal) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch msg.(type) { - case tea.KeyPressMsg, tea.MouseClickMsg: - return m, app.Quit() - } - return m, nil -} - -func (permissionModal) View() tea.View { - textStyle := lipgloss.NewStyle().Foreground(style.S.Text) - hintStyle := lipgloss.NewStyle().Foreground(style.S.Muted) - - parts := []string{ - textStyle.Render("Can't reach the usbguard daemon (permission denied)."), - textStyle.Render("Join the usbguard group, or use sudo."), - hintStyle.Render("press any key to quit"), - } - return tea.NewView(strings.Join(parts, "\n")) -}