From fac201d246b424b1ec34a7a5b054801b23f356c0 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 9 Oct 2024 21:39:31 +0100 Subject: [PATCH 1/6] If fysion is installed and we are editing the app link to it --- internal/ui/baricon.go | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/internal/ui/baricon.go b/internal/ui/baricon.go index 94f8c852..3e9ed30e 100644 --- a/internal/ui/baricon.go +++ b/internal/ui/baricon.go @@ -2,6 +2,10 @@ package ui import ( "image/color" + "os" + "os/exec" + "os/user" + "path/filepath" "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" @@ -143,6 +147,22 @@ func (bi *barIcon) TappedSecondary(ev *fyne.PointEvent) { } items := []*fyne.MenuItem{addRemove} + root := sourceRoot() + editor := editorPath() + if root != "" && editor != "" { + srcDir := filepath.Join(root, app.Name()) + if exists(srcDir) { + items = append(items, fyne.NewMenuItem("Edit", func() { + cmd := exec.Command(editor, srcDir) + err := cmd.Start() + + if err != nil { + fyne.LogError("Failed to start Fysion", err) + } + })) + } + } + fynedesk.Instance().ShowMenuAt(fyne.NewMenu("", items...), ev.AbsolutePosition) } @@ -160,3 +180,26 @@ func newBarIcon(res fyne.Resource, appData fynedesk.AppData, winData *appWindow) return barIcon } + +func editorPath() string { + fysion, err := exec.LookPath("fysion") + if err == nil && fysion != "" { + return fysion + } + + return "" +} + +func exists(path string) bool { + _, err := os.Stat(path) + return err == nil +} + +func sourceRoot() string { + u, err := user.Current() + if err != nil { + return "" + } + + return filepath.Join(u.HomeDir, "FysionApps") +} From d9d2edeb83be343ce1f1613d947f7301cca2f94c Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 16 Oct 2024 17:55:27 +0100 Subject: [PATCH 2/6] Use the Fyne source extension for .desktop files Instead of checking for existing source checkout --- go.mod | 6 ++--- go.sum | 14 +++++------ icons.go | 7 ++++++ internal/icon/fdo.go | 22 +++++++++++++++++- internal/icon/fdo_test.go | 10 ++++++++ internal/icon/macos.go | 4 ++++ .../applications/com.fyne.app.desktop | 4 ++++ internal/ui/baricon.go | 23 ++++++++----------- test/icons.go | 4 ++++ 9 files changed, 70 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 33774a3d..e0d34b6e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module fyshos.com/fynedesk go 1.19 require ( - fyne.io/fyne/v2 v2.5.1 + fyne.io/fyne/v2 v2.5.3-0.20241016103742-4875e351f57a github.com/BurntSushi/xgb v0.0.0-20201008132610-5f9e7b3c49cd github.com/BurntSushi/xgbutil v0.0.0-20160919175755-f7c97cef3b4e github.com/FyshOS/backgrounds v0.0.0-20230616202904-0a8b6ebaa184 @@ -40,8 +40,8 @@ require ( github.com/fyne-io/terminal v0.0.0-20240728203942-56c3b98b9208 github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect - github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b // indirect - github.com/go-text/typesetting v0.1.0 // indirect + github.com/go-text/render v0.2.0 // indirect + github.com/go-text/typesetting v0.2.0 // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect github.com/pkg/errors v0.8.1 // indirect diff --git a/go.sum b/go.sum index 82debc7c..e4d76781 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -fyne.io/fyne/v2 v2.5.1 h1:jd2mhQz0ViosZjhgR5l2bdCbc5HFqkYnTzEXX8UOC7I= -fyne.io/fyne/v2 v2.5.1/go.mod h1:NdxEG8L7EVWo06/cYbXW11uA0X7UG8Q8j5CLebvTZi8= +fyne.io/fyne/v2 v2.5.3-0.20241016103742-4875e351f57a h1:0RawKdtWcDd623JcD2Hd9KB67eyxjziADSIm/uGekVg= +fyne.io/fyne/v2 v2.5.3-0.20241016103742-4875e351f57a/go.mod h1:26gqPDvtaxHeyct+C0BBjuGd2zwAJlPkUGSBrb+d7Ug= fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg= fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs= github.com/ActiveState/termtest/conpty v0.5.0 h1:JLUe6YDs4Jw4xNPCU+8VwTpniYOGeKzQg4SM2YHQNA8= @@ -116,11 +116,11 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b h1:daoFn+Aw8EIQZO9kYWwHL01FqwwpCl2nTeVEYbsgRHk= -github.com/go-text/render v0.1.1-0.20240418202334-dd62631dae9b/go.mod h1:jqEuNMenrmj6QRnkdpeaP0oKGFLDNhDkVKwGjsWWYU4= -github.com/go-text/typesetting v0.1.0 h1:vioSaLPYcHwPEPLT7gsjCGDCoYSbljxoHJzMnKwVvHw= -github.com/go-text/typesetting v0.1.0/go.mod h1:d22AnmeKq/on0HNv73UFriMKc4Ez6EqZAofLhAzpSzI= -github.com/go-text/typesetting-utils v0.0.0-20240329101916-eee87fb235a3 h1:levTnuLLUmpavLGbJYLJA7fQnKeS7P1eCdAlM+vReXk= +github.com/go-text/render v0.2.0 h1:LBYoTmp5jYiJ4NPqDc2pz17MLmA3wHw1dZSVGcOdeAc= +github.com/go-text/render v0.2.0/go.mod h1:CkiqfukRGKJA5vZZISkjSYrcdtgKQWRa2HIzvwNN5SU= +github.com/go-text/typesetting v0.2.0 h1:fbzsgbmk04KiWtE+c3ZD4W2nmCRzBqrqQOvYlwAOdho= +github.com/go-text/typesetting v0.2.0/go.mod h1:2+owI/sxa73XA581LAzVuEBZ3WEEV2pXeDswCH/3i1I= +github.com/go-text/typesetting-utils v0.0.0-20240317173224-1986cbe96c66 h1:GUrm65PQPlhFSKjLPGOZNPNxLCybjzjYBzjfoBGaDUY= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= diff --git a/icons.go b/icons.go index fda7481f..0e44d08b 100644 --- a/icons.go +++ b/icons.go @@ -10,6 +10,13 @@ type AppData interface { Categories() []string // Categories is a list of categories that the app fits in (platform specific) Hidden() bool // Hidden specifies whether instances of this app should be hidden Icon(theme string, size int) fyne.Resource // Icon returns an icon for the app in the requested theme and size + + Source() *AppSource // Source will return the location of the app source code from metadata, if known +} + +// AppSource represents the source code informtion of an application +type AppSource struct { + Repo, Dir string } // ApplicationProvider describes a type that can locate icons and applications for the current system diff --git a/internal/icon/fdo.go b/internal/icon/fdo.go index 66edeb49..9bbffd27 100644 --- a/internal/icon/fdo.go +++ b/internal/icon/fdo.go @@ -34,6 +34,8 @@ type fdoApplicationData struct { categories []string hide bool iconCache fyne.Resource + + source *fynedesk.AppSource } // Name returns the name associated with an fdo app @@ -73,6 +75,10 @@ func (data *fdoApplicationData) Icon(theme string, size int) fyne.Resource { return data.iconCache } +func (data *fdoApplicationData) Source() *fynedesk.AppSource { + return data.source +} + // extractArgs sanitises argument parameters from an Exec configuration func extractArgs(args []string) []string { var ret []string @@ -457,7 +463,21 @@ func newFdoIconData(desktopPath string) fynedesk.AppData { if strings.HasPrefix(line, "[") { currentSection = line } - if currentSection != "[Desktop Entry]" { + switch currentSection { + case "[X-Fyne Source]": + if fdoApp.source == nil { + fdoApp.source = &fynedesk.AppSource{} + } + if strings.HasPrefix(line, "Repo=") { + name := strings.SplitAfter(line, "=") + fdoApp.source.Repo = name[1] + } + if strings.HasPrefix(line, "Dir=") { + name := strings.SplitAfter(line, "=") + fdoApp.source.Dir = name[1] + } + case "[Desktop Entry]": // fall through to code below + default: continue } if strings.HasPrefix(line, "Name=") { diff --git a/internal/icon/fdo_test.go b/internal/icon/fdo_test.go index f785bd3f..163e3bda 100644 --- a/internal/icon/fdo_test.go +++ b/internal/icon/fdo_test.go @@ -102,6 +102,16 @@ func TestFdoIconHicolorFallbackScalable(t *testing.T) { assert.Equal(t, true, exists(data)) } +// applications/com.fyne.app.desktop +func TestFdoIconSource(t *testing.T) { + setTestEnv(t) + data := NewFDOIconProvider().(*fdoIconProvider).lookupApplication("app2") + + assert.NotNil(t, data.Source()) + assert.Equal(t, "https://example.com/repo", data.Source().Repo) + assert.Equal(t, "cmd/dir", data.Source().Dir) +} + // applications/app7.desktop and icons/default_theme/apps/16x16/app7.png func TestFdoLookupDefaultThemeDifferentSize(t *testing.T) { setTestEnv(t) diff --git a/internal/icon/macos.go b/internal/icon/macos.go index 9202910a..be946037 100644 --- a/internal/icon/macos.go +++ b/internal/icon/macos.go @@ -76,6 +76,10 @@ func (m *macOSAppBundle) Run([]string) error { return exec.Command("open", "-a", m.runPath).Start() } +func (m *macOSAppBundle) Source() *fynedesk.AppSource { + return nil +} + func loadAppBundle(name, path, category string) fynedesk.AppData { buf, err := os.Open(filepath.Join(path, "Contents", "Info.plist")) if err != nil { diff --git a/internal/icon/testdata/applications/com.fyne.app.desktop b/internal/icon/testdata/applications/com.fyne.app.desktop index 19aaef8f..28cb79f8 100644 --- a/internal/icon/testdata/applications/com.fyne.app.desktop +++ b/internal/icon/testdata/applications/com.fyne.app.desktop @@ -2,3 +2,7 @@ Name=App2 Exec=app2 Icon=app2 + +[X-Fyne Source] +Repo=https://example.com/repo +Dir=cmd/dir diff --git a/internal/ui/baricon.go b/internal/ui/baricon.go index 3e9ed30e..f8997915 100644 --- a/internal/ui/baricon.go +++ b/internal/ui/baricon.go @@ -147,20 +147,17 @@ func (bi *barIcon) TappedSecondary(ev *fyne.PointEvent) { } items := []*fyne.MenuItem{addRemove} - root := sourceRoot() editor := editorPath() - if root != "" && editor != "" { - srcDir := filepath.Join(root, app.Name()) - if exists(srcDir) { - items = append(items, fyne.NewMenuItem("Edit", func() { - cmd := exec.Command(editor, srcDir) - err := cmd.Start() - - if err != nil { - fyne.LogError("Failed to start Fysion", err) - } - })) - } + if app.Source() != nil && editor != "" { + srcDir := filepath.Join(sourceRoot(), app.Name()) + items = append(items, fyne.NewMenuItem("Edit", func() { + cmd := exec.Command(editor, srcDir) + err := cmd.Start() + + if err != nil { + fyne.LogError("Failed to start app editor: "+editor, err) + } + })) } fynedesk.Instance().ShowMenuAt(fyne.NewMenu("", items...), ev.AbsolutePosition) diff --git a/test/icons.go b/test/icons.go index 4f8deee7..9c59c8c6 100644 --- a/test/icons.go +++ b/test/icons.go @@ -44,6 +44,10 @@ func (tad *testAppData) Icon(theme string, size int) fyne.Resource { return wmTheme.IconifyIcon } +func (tad *testAppData) Source() *fynedesk.AppSource { + return nil +} + type testAppProvider struct { apps []fynedesk.AppData } From 9659333ca3861dbec63d890b694e8f0f44d67bfd Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 16 Oct 2024 17:55:40 +0100 Subject: [PATCH 3/6] Fix code warnings --- internal/icon/fdo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/icon/fdo.go b/internal/icon/fdo.go index 9bbffd27..4c4cfe15 100644 --- a/internal/icon/fdo.go +++ b/internal/icon/fdo.go @@ -57,7 +57,7 @@ func (data *fdoApplicationData) IconName() string { return data.iconName } -// IconPath returns the path of the icon that an fdo app wishes to use +// Icon returns the path of the icon that an fdo app wishes to use func (data *fdoApplicationData) Icon(theme string, size int) fyne.Resource { if data.iconCache != nil { return data.iconCache @@ -112,7 +112,7 @@ func (data *fdoApplicationData) Run(env []string) error { return cmd.Start() } -func (data fdoApplicationData) mainCategory() string { +func (data *fdoApplicationData) mainCategory() string { if len(data.Categories()) == 0 { return fallbackCategory } From e102db77997f95ea87645b9ae90c85e830af46cf Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 16 Oct 2024 20:04:34 +0100 Subject: [PATCH 4/6] Fix some missed usage of App interface --- internal/ui/bar_test.go | 7 +++++++ modules/status/network.go | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/internal/ui/bar_test.go b/internal/ui/bar_test.go index 5dfad73b..a334710c 100644 --- a/internal/ui/bar_test.go +++ b/internal/ui/bar_test.go @@ -4,6 +4,8 @@ import ( "image/color" "testing" + "fyshos.com/fynedesk" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/test" @@ -40,6 +42,11 @@ func (d *dummyIcon) Run([]string) error { return nil } +func (d *dummyIcon) Source() *fynedesk.AppSource { + // no-op + return nil +} + func testBar(icons []string) *bar { testBar := newBar(wmTest.NewDesktopWithWM(&embededWM{})) testBar.children = []fyne.CanvasObject{} // remove divider, then we add it again later diff --git a/modules/status/network.go b/modules/status/network.go index 7019fc06..51876a7b 100644 --- a/modules/status/network.go +++ b/modules/status/network.go @@ -184,3 +184,7 @@ func (n *networkApp) Hidden() bool { func (n *networkApp) Icon(theme string, size int) fyne.Resource { return wmtheme.WifiIcon } + +func (n *networkApp) Source() *fynedesk.AppSource { + return nil +} From 75f30e3790bfeb19ac2b06c3069508212781c661 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 16 Oct 2024 20:53:36 +0100 Subject: [PATCH 5/6] Actually download source and open editor --- internal/ui/baricon.go | 59 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/internal/ui/baricon.go b/internal/ui/baricon.go index f8997915..6d03b042 100644 --- a/internal/ui/baricon.go +++ b/internal/ui/baricon.go @@ -9,6 +9,8 @@ import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/container" + deskDriver "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -149,14 +151,8 @@ func (bi *barIcon) TappedSecondary(ev *fyne.PointEvent) { items := []*fyne.MenuItem{addRemove} editor := editorPath() if app.Source() != nil && editor != "" { - srcDir := filepath.Join(sourceRoot(), app.Name()) items = append(items, fyne.NewMenuItem("Edit", func() { - cmd := exec.Command(editor, srcDir) - err := cmd.Start() - - if err != nil { - fyne.LogError("Failed to start app editor: "+editor, err) - } + editApp(app, editor) })) } @@ -171,6 +167,55 @@ func (bi *barIcon) CreateRenderer() fyne.WidgetRenderer { return render } +func cloneRepo(src *fynedesk.AppSource, path string) error { + spin := widget.NewActivity() + prop := canvas.NewRectangle(color.Transparent) + prop.SetMinSize(fyne.NewSquareSize(56)) + + w := fyne.CurrentApp().Driver().(deskDriver.Driver).CreateSplashWindow() + w.SetContent( + container.NewBorder(nil, widget.NewLabel("Downloading..."), nil, nil, + container.NewStack(prop, spin))) + spin.Start() + w.Show() + + defer func() { + w.Hide() + spin.Stop() + }() + + cmd := exec.Command("git", "clone", src.Repo, path) + return cmd.Run() +} + +func editApp(app fynedesk.AppData, editor string) { + root := sourceRoot() + srcDir := filepath.Join(root, app.Name()) + + if !exists(srcDir) { + if !exists(root) { + err := os.MkdirAll(root, 0755) + if err != nil { + fyne.LogError("Failed to make source root", err) + return + } + } + + err := cloneRepo(app.Source(), srcDir) + if err != nil { + fyne.LogError("Error cloning the app source", err) + return + } + } + + cmd := exec.Command(editor, srcDir) + err := cmd.Start() + + if err != nil { + fyne.LogError("Failed to start app editor: "+editor, err) + } +} + func newBarIcon(res fyne.Resource, appData fynedesk.AppData, winData *appWindow) *barIcon { barIcon := &barIcon{resource: res, appData: appData, windowData: winData} barIcon.ExtendBaseWidget(barIcon) From 819181457ce8cfead81b88c636348f7af4182014 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Wed, 16 Oct 2024 20:57:27 +0100 Subject: [PATCH 6/6] Fix deprecation --- modules/launcher/calc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/launcher/calc.go b/modules/launcher/calc.go index 0c6d0c13..486c669f 100644 --- a/modules/launcher/calc.go +++ b/modules/launcher/calc.go @@ -84,5 +84,5 @@ func (i *calcItem) Title() string { } func (i *calcItem) Launch() { - fyne.CurrentApp().Driver().AllWindows()[0].Clipboard().SetContent(i.result) + fyne.CurrentApp().Clipboard().SetContent(i.result) }