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

Support reading .ico icon files if passed to packaging #3008

Merged
merged 10 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/package-windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"runtime"

"fyne.io/fyne/v2/cmd/fyne/internal/templates"
ico "github.com/Kodeworks/golang-image-ico"
"github.com/fyne-io/image/ico"
"github.com/josephspurrier/goversioninfo"
"golang.org/x/sys/execabs"
)
Expand Down
48 changes: 46 additions & 2 deletions cmd/fyne/internal/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import (
"errors"
"flag"
"fmt"
"image"
_ "image/jpeg" // import image encodings
_ "image/png" // import image encodings
"image/png" // import image encodings
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
"strings"

_ "github.com/fyne-io/image/ico" // import image encodings
"github.com/urfave/cli/v2"
"golang.org/x/mod/modfile"
"golang.org/x/mod/module"
Expand Down Expand Up @@ -120,6 +122,7 @@ type Packager struct {
install, release bool
certificate, profile string // optional flags for releasing
tags, category string
tempDir string
}

// AddFlags adds the flags for interacting with the package command.
Expand Down Expand Up @@ -255,6 +258,7 @@ func (p *Packager) doPackage(runner runner) error {
if p.AppBuild <= 0 {
p.AppBuild = defaultAppBuild
}
defer os.RemoveAll(p.tempDir)

if !util.Exists(p.exe) && !util.IsMobile(p.os) {
files, err := p.buildPackage(runner)
Expand Down Expand Up @@ -302,7 +306,14 @@ func (p *Packager) removeBuild(files []string) {
}
}

func (p *Packager) validate() error {
func (p *Packager) validate() (err error) {
p.tempDir, err = ioutil.TempDir("", "fyne-package-*")
defer func() {
if err != nil {
_ = os.RemoveAll(p.tempDir)
}
}()
Jacalz marked this conversation as resolved.
Show resolved Hide resolved

if p.os == "" {
p.os = targetOS()
}
Expand Down Expand Up @@ -347,6 +358,13 @@ func (p *Packager) validate() error {
if !util.Exists(p.icon) {
return errors.New("Missing application icon at \"" + p.icon + "\"")
}
if strings.ToLower(filepath.Ext(p.icon)) != ".png" {
tmp, err := p.normaliseIcon(p.icon)
if err != nil {
return err
}
p.icon = tmp
}

p.AppID, err = validateAppID(p.AppID, p.os, p.Name, p.release)
if err != nil {
Expand Down Expand Up @@ -412,6 +430,32 @@ func mergeMetadata(p *appData, data *metadata.FyneApp) {
}
}

// normaliseIcon takes a non-png image file and converts it to PNG for use in packaging.
// Successful conversion will return a path to the new file.
// Any errors that occur will be returned with an empty string for new path.
func (p *Packager) normaliseIcon(path string) (string, error) {
// convert icon
img, err := os.Open(path)
if err != nil {
return "", fmt.Errorf("failed to open source image: %w", err)
}
defer img.Close()
srcImg, _, err := image.Decode(img)
if err != nil {
return "", fmt.Errorf("failed to decode source image: %w", err)
}

out, err := ioutil.TempFile(p.tempDir, "fyne-ico-*.png")
if err != nil {
return "", fmt.Errorf("failed to open image output file: %w", err)
}
tmpPath := out.Name()
defer out.Close()

err = png.Encode(out, srcImg)
return tmpPath, err
}

func validateAppID(appID, os, name string, release bool) (string, error) {
// old darwin compatibility
if os == "darwin" {
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go 1.14
require (
fyne.io/systray v1.9.1-0.20220523202515-bb6f1d955cff
github.com/BurntSushi/toml v1.1.0
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3
github.com/fsnotify/fsnotify v1.5.4
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504
github.com/fyne-io/image v0.0.0-20220601192234-cf0c0847e24d
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec
github.com/go-ole/go-ole v1.2.6
Expand All @@ -23,10 +23,10 @@ require (
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.1
github.com/urfave/cli/v2 v2.4.0
github.com/yuin/goldmark v1.4.0
golang.org/x/image v0.0.0-20200430140353-33d19683fad8
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
golang.org/x/mobile v0.0.0-20211207041440-4e6c2922fdee
golang.org/x/mod v0.4.2
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad
Expand Down
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9 h1:1ltqoej5GtaWF8jaiA49HwsZD459jqm9YFz9ZtMFpQA=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.10.2 h1:Zxm8V5eI1hW4gGaYsJQUhxpjkENuG91ki8B4zCrvEsw=
github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down Expand Up @@ -86,6 +84,8 @@ github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe h1:A/wiwvQ0CAjPkuJyt
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe/go.mod h1:d4clgH0/GrRwWjRzJJQXxT/h1TyuNSfF/X64zb/3Ggg=
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 h1:+31CdF/okdokeFNoy9L/2PccG3JFidQT3ev64/r4pYU=
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504/go.mod h1:gLRWYfYnMA9TONeppRSikMdXlHQ97xVsPojddUv3b/E=
github.com/fyne-io/image v0.0.0-20220601192234-cf0c0847e24d h1:01kvTqDlj2pZAWS0v9r/ZNOoVdp8LuKbsam9fxDJf48=
github.com/fyne-io/image v0.0.0-20220601192234-cf0c0847e24d/go.mod h1:jcskXEXXX7/RUeErPdRBPSUeaEVTfAhpcSysNRR2DHA=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
Expand Down Expand Up @@ -202,6 +202,8 @@ github.com/josephspurrier/goversioninfo v1.4.0/go.mod h1:JWzv5rKQr+MmW+LvM412ToT
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e h1:LvL4XsI70QxOGHed6yhQtAU34Kx3Qq2wwBzGFKY8zKk=
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
Expand Down Expand Up @@ -273,8 +275,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/urfave/cli/v2 v2.4.0 h1:m2pxjjDFgDxSPtO8WSdbndj17Wu2y8vOT86wE/tjr+I=
github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg=
Expand Down Expand Up @@ -319,8 +322,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"runtime"
"sync"

ico "github.com/Kodeworks/golang-image-ico"
"github.com/fyne-io/image/ico"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/internal/animation"
Expand Down
24 changes: 0 additions & 24 deletions vendor/github.com/Kodeworks/golang-image-ico/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/github.com/Kodeworks/golang-image-ico/README.md

This file was deleted.

Binary file not shown.
Binary file removed vendor/github.com/Kodeworks/golang-image-ico/new.ico
Binary file not shown.
29 changes: 29 additions & 0 deletions vendor/github.com/fyne-io/image/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.