Skip to content

Commit

Permalink
ui,preferences: allow to disable favicon downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
lucor committed May 3, 2024
1 parent 55cbfa0 commit 394ce2c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Details:
- ui: update icon to use tabler.io icon
- ui: improve validation
- ui: improve audit view
- ui: improve favicon download
- ui: improve favicon downloader
- ui: improve note field display
- ui,preferences: allow to disable favicon downloader
- all: add application state
- all: update to store time in UTC
- browser: initial implementation of native messaging protocol to support browser extensions
Expand Down
14 changes: 12 additions & 2 deletions internal/paw/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package paw

func newDefaultPreferences() *Preferences {
return &Preferences{
FaviconDownloader: FaviconDownloaderPreferences{
Disabled: false,
},
Password: PasswordPreferences{
Passphrase: PassphrasePasswordPreferences{
DefaultLength: PassphrasePasswordDefaultLength,
Expand Down Expand Up @@ -34,8 +37,15 @@ func newDefaultPreferences() *Preferences {
}

type Preferences struct {
Password PasswordPreferences `json:"password,omitempty"`
TOTP TOTPPreferences `json:"totp,omitempty"`
FaviconDownloader FaviconDownloaderPreferences `json:"favicon_downloader,omitempty"`
Password PasswordPreferences `json:"password,omitempty"`
TOTP TOTPPreferences `json:"totp,omitempty"`
}

// FaviconDownloaderPreferences represents the preferences for the favicon downloader.
// FaviconDownloader tool is opt-out, hence the default value is false.
type FaviconDownloaderPreferences struct {
Disabled bool `json:"disabled,omitempty"` // Disabled is true if the favicon downloader is disabled.
}

type PasswordPreferences struct {
Expand Down
18 changes: 13 additions & 5 deletions internal/ui/item_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewLoginWidget(item *paw.Login, preferences *paw.Preferences) FyneItemWidge
return &loginItemWidget{
item: item,
preferences: preferences,
urlEntry: newURLEntryWithData(context.TODO(), item.URL),
urlEntry: newURLEntryWithData(context.TODO(), item.URL, preferences.FaviconDownloader),
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func (iw *loginItemWidget) Edit(ctx context.Context, key *paw.Key, w fyne.Window
titleEntry.Validator = requiredValidator("The title cannot be emtpy")
titleEntry.PlaceHolder = "Untitled login"

urlEntry := newURLEntryWithData(ctx, iw.item.URL)
urlEntry := newURLEntryWithData(ctx, iw.item.URL, preferences.FaviconDownloader)
urlEntry.TitleEntry = titleEntry
urlEntry.FaviconListener = func(favicon *paw.Favicon) {
iw.item.Metadata.Favicon = favicon
Expand Down Expand Up @@ -199,13 +199,15 @@ type urlEntry struct {
FaviconListener func(*paw.Favicon)
ctx context.Context
loginURL *paw.LoginURL // keep track of the initial value before editing
preferences paw.FaviconDownloaderPreferences
validationError error
}

func newURLEntryWithData(ctx context.Context, loginURL *paw.LoginURL) *urlEntry {
func newURLEntryWithData(ctx context.Context, loginURL *paw.LoginURL, preferences paw.FaviconDownloaderPreferences) *urlEntry {
e := &urlEntry{
ctx: ctx,
loginURL: loginURL,
ctx: ctx,
loginURL: loginURL,
preferences: preferences,
}
e.ExtendBaseWidget(e)
e.SetText(e.loginURL.String())
Expand Down Expand Up @@ -250,6 +252,12 @@ func (e *urlEntry) FocusLost() {
return
}

if e.preferences.Disabled {
// Favicons are disabled, skipping download
e.FaviconListener(nil)
return
}

go func() {
var fav *paw.Favicon

Expand Down
17 changes: 16 additions & 1 deletion internal/ui/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
func (a *app) makePreferencesView() fyne.CanvasObject {
content := container.NewVScroll(
container.NewVBox(
a.makeFaviconDownloaderPreferencesCard(),
a.makePasswordPreferencesCard(),
a.makeTOTPPreferencesCard(),
),
Expand All @@ -36,6 +37,20 @@ func (a *app) storePreferences() {
}
}

func (a *app) makeFaviconDownloaderPreferencesCard() fyne.CanvasObject {
checkbox := widget.NewCheck("Disabled", func(disabled bool) {
a.state.Preferences.FaviconDownloader.Disabled = disabled
a.storePreferences()
})
checkbox.Checked = a.state.Preferences.FaviconDownloader.Disabled

return widget.NewCard(
"Favicon Downloader",
"",
checkbox,
)
}

func (a *app) makePasswordPreferencesCard() fyne.CanvasObject {
passphraseCard := widget.NewCard(
"Passphrase",
Expand Down Expand Up @@ -89,7 +104,7 @@ func (a *app) makeTOTPPreferencesCard() fyne.CanvasObject {
form.Add(container.NewBorder(nil, nil, nil, intervalEntry, intervalSlider))

return widget.NewCard(
"TOTP",
"Two Factor Authentication (TOTP)",
"",
form,
)
Expand Down

0 comments on commit 394ce2c

Please sign in to comment.