Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to app editor Fysion if it is installed #265

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
7 changes: 7 additions & 0 deletions icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions internal/icon/fdo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,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
Expand All @@ -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
Expand Down Expand Up @@ -106,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
}
Expand Down Expand Up @@ -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=") {
Expand Down
10 changes: 10 additions & 0 deletions internal/icon/fdo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/icon/macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/icon/testdata/applications/com.fyne.app.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
Name=App2
Exec=app2
Icon=app2

[X-Fyne Source]
Repo=https://example.com/repo
Dir=cmd/dir
7 changes: 7 additions & 0 deletions internal/ui/bar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
85 changes: 85 additions & 0 deletions internal/ui/baricon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package ui

import (
"image/color"
"os"
"os/exec"
"os/user"
"path/filepath"

"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"

Expand Down Expand Up @@ -143,6 +149,13 @@ func (bi *barIcon) TappedSecondary(ev *fyne.PointEvent) {
}

items := []*fyne.MenuItem{addRemove}
editor := editorPath()
if app.Source() != nil && editor != "" {
items = append(items, fyne.NewMenuItem("Edit", func() {
editApp(app, editor)
}))
}

fynedesk.Instance().ShowMenuAt(fyne.NewMenu("", items...), ev.AbsolutePosition)
}

Expand All @@ -154,9 +167,81 @@ 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)

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")
}
2 changes: 1 addition & 1 deletion modules/launcher/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions modules/status/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions test/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down