/
package-darwin.go
68 lines (57 loc) · 1.71 KB
/
package-darwin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package commands
import (
"image"
"os"
"path/filepath"
"strings"
"fyne.io/fyne/v2/cmd/fyne/internal/templates"
"fyne.io/fyne/v2/cmd/fyne/internal/util"
"github.com/jackmordaunt/icns"
"github.com/pkg/errors"
)
type darwinData struct {
Name, ExeName string
AppID string
Version string
Build int
Category string
}
func (p *packager) packageDarwin() error {
appDir := util.EnsureSubDir(p.dir, p.name+".app")
exeName := filepath.Base(p.exe)
contentsDir := util.EnsureSubDir(appDir, "Contents")
info := filepath.Join(contentsDir, "Info.plist")
infoFile, _ := os.Create(info)
tplData := darwinData{Name: p.name, ExeName: exeName, AppID: p.appID, Version: p.appVersion, Build: p.appBuild,
Category: strings.ToLower(p.category)}
err := templates.InfoPlistDarwin.Execute(infoFile, tplData)
if err != nil {
return errors.Wrap(err, "Failed to write plist template")
}
macOSDir := util.EnsureSubDir(contentsDir, "MacOS")
binName := filepath.Join(macOSDir, exeName)
err = util.CopyExeFile(p.exe, binName)
if err != nil {
return errors.Wrap(err, "Failed to copy exe file")
}
resDir := util.EnsureSubDir(contentsDir, "Resources")
icnsPath := filepath.Join(resDir, "icon.icns")
img, err := os.Open(p.icon)
if err != nil {
return errors.Wrapf(err, "Failed to open source image \"%s\"", p.icon)
}
defer img.Close()
srcImg, _, err := image.Decode(img)
if err != nil {
return errors.Wrapf(err, "Failed to decode source image")
}
dest, err := os.Create(icnsPath)
if err != nil {
return errors.Wrap(err, "Failed to open destination file")
}
defer dest.Close()
if err := icns.Encode(dest, srcImg); err != nil {
return errors.Wrap(err, "Failed to encode icns")
}
return nil
}