Skip to content

Commit

Permalink
Actually download source and open editor
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Oct 16, 2024
1 parent e102db7 commit 75f30e3
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions internal/ui/baricon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}))
}

Expand All @@ -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)
Expand Down

0 comments on commit 75f30e3

Please sign in to comment.