mirror of
https://github.com/anotherhadi/usbguard-tui.git
synced 2026-10-05 18:28:24 +02:00
@@ -21,6 +21,11 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := guard.ListDevices(); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
p := tea.NewProgram(newApp())
|
p := tea.NewProgram(newApp())
|
||||||
if _, err := p.Run(); err != nil {
|
if _, err := p.Run(); err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
-11
@@ -50,7 +50,6 @@ type Model struct {
|
|||||||
rulesManaged bool
|
rulesManaged bool
|
||||||
rulesWritable bool
|
rulesWritable bool
|
||||||
pendingRules []pendingRule
|
pendingRules []pendingRule
|
||||||
fatalShown bool
|
|
||||||
|
|
||||||
ModalOpen bool
|
ModalOpen bool
|
||||||
}
|
}
|
||||||
@@ -172,16 +171,6 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
|
|
||||||
case actionMsg:
|
case actionMsg:
|
||||||
if msg.err != nil {
|
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, errorToast(msg.err)
|
||||||
}
|
}
|
||||||
return m, fetchDevices
|
return m, fetchDevices
|
||||||
|
|||||||
@@ -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"))
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user