mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Merge commit 'a213e8bcd1d8e4e5c764978879d875d2d55dd400' as 'v2'
This commit is contained in:
54
v2/pkg/commands/build/desktop_linux.go
Normal file
54
v2/pkg/commands/build/desktop_linux.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// +build linux
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/xyproto/xpm"
|
||||
)
|
||||
|
||||
// compileIcon will compile the icon found at <projectdir>/icon.png into the application
|
||||
func (d *DesktopBuilder) compileIcon(assetDir string, iconFile string) error {
|
||||
|
||||
// Load icon into a databuffer
|
||||
targetFilename := "icon"
|
||||
targetFile := filepath.Join(assetDir, targetFilename+".c")
|
||||
|
||||
d.addFileToDelete(targetFile)
|
||||
|
||||
// Create a new XPM encoder
|
||||
enc := xpm.NewEncoder(targetFilename)
|
||||
|
||||
// Open the PNG file
|
||||
f, err := os.Open(iconFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := png.Decode(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.Close()
|
||||
|
||||
var buf strings.Builder
|
||||
|
||||
// Generate and output the XPM data
|
||||
err = enc.Encode(&buf, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Massage the output so we can extern reference it
|
||||
output := buf.String()
|
||||
output = strings.Replace(output, "static char", "const char", 1)
|
||||
|
||||
// save icon.c
|
||||
err = ioutil.WriteFile(targetFile, []byte(output), 0755)
|
||||
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user