Skip to content

Commit

Permalink
Fix appimage file sourcing (wailsapp#3306)
Browse files Browse the repository at this point in the history
Add findGTKFiles to source webkit files for appimage generation

s
  • Loading branch information
atterpac authored Mar 17, 2024
1 parent e9a9420 commit ec2ce3f
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions v3/internal/commands/appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package commands

import (
_ "embed"
"errors"
"fmt"
"github.com/pterm/pterm"
"github.com/wailsapp/wails/v3/internal/s"
"os"
"path/filepath"
"strings"
"sync"

"github.com/pterm/pterm"
"github.com/wailsapp/wails/v3/internal/s"
)

//go:embed linuxdeploy-plugin-gtk.sh
Expand Down Expand Up @@ -110,9 +113,10 @@ func generateAppImage(options *GenerateAppImageOptions) error {
wg.Wait()

log(p, "Processing GTK files.")
files := s.FINDFILES("/usr/lib", "WebKitNetworkProcess", "WebKitWebProcess", "libwebkit2gtkinjectedbundle.so")
if len(files) != 3 {
return fmt.Errorf("unable to locate all WebKit libraries")
filesNeeded := []string{"WebKitWebProcess", "WebKitNetworkProcess", "libwebkit2gtkinjectedbundle.so"}
files, err := findGTKFiles(filesNeeded)
if err != nil {
return err
}
s.CD(appDir)
for _, file := range files {
Expand All @@ -130,7 +134,7 @@ func generateAppImage(options *GenerateAppImageOptions) error {
s.COPY(file, targetDir)
}
// Copy GTK Plugin
err := os.WriteFile(filepath.Join(options.BuildDir, "linuxdeploy-plugin-gtk.sh"), gtkPlugin, 0755)
err = os.WriteFile(filepath.Join(options.BuildDir, "linuxdeploy-plugin-gtk.sh"), gtkPlugin, 0755)
if err != nil {
return err
}
Expand Down Expand Up @@ -173,3 +177,48 @@ func generateAppImage(options *GenerateAppImageOptions) error {
log(p, "AppImage created: "+targetFile)
return nil
}

func findGTKFiles(files []string) ([]string, error) {
notFound := []string{}
found := []string{}
err := filepath.Walk("/usr/", func(path string, info os.FileInfo, err error) error {
if err != nil {
if os.IsPermission(err) {
return nil
}
return err
}

if info.IsDir() {
return nil
}

for _, fileName := range files {
if strings.HasSuffix(path, fileName) {
found = append(found, path)
break
}
}

return nil
})
if err != nil {
return nil, err
}
for _, fileName := range files {
fileFound := false
for _, foundPath := range found {
if strings.HasSuffix(foundPath, fileName) {
fileFound = true
break
}
}
if !fileFound {
notFound = append(notFound, fileName)
}
}
if len(notFound) > 0 {
return nil, errors.New("Unable to locate all required files: " + strings.Join(notFound, ", "))
}
return found, nil
}

0 comments on commit ec2ce3f

Please sign in to comment.