Skip to content

Commit

Permalink
Also add a settings desktop icon
Browse files Browse the repository at this point in the history
This will launch the settings UI
  • Loading branch information
andydotxyz committed Jan 5, 2024
1 parent 913267f commit 66404e8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions desk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Desktop interface {

Desktop() int
SetDesktop(int)
ShowSettings()
}

var instance Desktop
Expand Down
4 changes: 4 additions & 0 deletions internal/ui/desk.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (l *desktop) SetDesktop(id int) {
}
}

func (l *desktop) ShowSettings() {
l.widgets.showSettings()
}

func (l *desktop) Layout(objects []fyne.CanvasObject, size fyne.Size) {
bg := objects[0].(*background)
bg.Resize(size)
Expand Down
22 changes: 15 additions & 7 deletions modules/fyles/fyles.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ func (f *fyles) Metadata() fynedesk.ModuleMetadata {
func (f *fyles) setDesktopDir(p *lib.Panel) {
home, _ := os.UserHomeDir()
u := storage.NewFileURI(filepath.Join(home, "Desktop"))
trash := newTrashURI(filepath.Join(home, ".local", "share", "Trash", "files"))
settings := newCustomURI("settings://", "Settings", theme.SettingsIcon())
trash := newCustomURI("file://"+filepath.Join(home, ".local", "share", "Trash", "files"), "Trash", theme.DeleteIcon())

list, err := storage.List(u)
list = append([]fyne.URI{trash}, list...)
list = append([]fyne.URI{settings, trash}, list...)
if err != nil {
fyne.LogError("Could not read Desktop dir", err)
} else {
Expand All @@ -72,6 +73,10 @@ func (f *fyles) setDesktopDir(p *lib.Panel) {
}

func (f *fyles) tapped(u fyne.URI) {
if u.Scheme() == "settings" {
fynedesk.Instance().ShowSettings()
return
}
p, err := execabs.LookPath("fyles")
if p != "" && err == nil {
if ok, _ := storage.CanList(u); ok {
Expand Down Expand Up @@ -105,17 +110,20 @@ func filterHidden() storage.FileFilter {

type trashURI struct {
fyne.URI

name string
icon fyne.Resource
}

func newTrashURI(s string) fyne.URI {
u := storage.NewFileURI(s)
return &trashURI{URI: u}
func newCustomURI(str, name string, icon fyne.Resource) fyne.URI {
u, _ := storage.ParseURI(str)
return &trashURI{URI: u, name: name, icon: icon}
}

func (t *trashURI) Name() string {
return "Trash"
return t.name
}

func (t *trashURI) Icon() fyne.Resource {
return theme.DeleteIcon()
return t.icon
}
2 changes: 2 additions & 0 deletions test/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (*Desktop) Desktop() int {
func (*Desktop) SetDesktop(int) {
}

func (*Desktop) ShowSettings() {}

Check failure on line 60 in test/desktop.go

View workflow job for this annotation

GitHub Actions / checks

exported method Desktop.ShowSettings should have comment or be unexported

// IconProvider returns the icon provider, by default it uses a simple in-memory implementation
func (td *Desktop) IconProvider() fynedesk.ApplicationProvider {
return td.icons
Expand Down

0 comments on commit 66404e8

Please sign in to comment.