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

Conversation

andydotxyz
Copy link
Member

@andydotxyz andydotxyz commented May 26, 2022

Re-encode non-png packaging images

Fixes #2412

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Updated the vendor folder (using go mod vendor).
  • Check for binary size increases when importing new modules.

@coveralls
Copy link

coveralls commented May 26, 2022

Coverage Status

Coverage decreased (-0.06%) to 61.333% when pulling f88c300 on andydotxyz:fix/2412 into d94d0c5 on fyne-io:develop.

}

tmpPath := filepath.Join(os.TempDir(), "fyne-ico-tmp.png")
out, err := os.Create(tmpPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to remove the file once it is not necessary anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good idea.
I don't think we have a hook for the processed completing at this time.
Can you think of a clean way to do that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doPackage use defer p.removeBuild(files). Maybe make doPackage and validate return a []string of files that need to be cleaned and set a defer in the caller to those function?

Copy link
Member

@Jacalz Jacalz May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a folder in the temp directory using https://pkg.go.dev/io/ioutil#TempDir and save everything there when we create temporary files. We then simply make sure to remove the whole folder before exiting the command (we could probably even hook up the interup signal https://www.tutorialspoint.com/how-to-handle-signals-in-golang so that it removes it before exiting using ctrl+c).

@Bluebugs
Copy link
Contributor

Just a bit of concern with this new dependencies regarding its license: biessek/golang-ico#3

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few possible improvements.

Comment on lines 439 to 440
tmpPath := filepath.Join(os.TempDir(), "fyne-ico-tmp.png")
out, err := os.Create(tmpPath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using ioutil.TempFile() instead?

Suggested change
tmpPath := filepath.Join(os.TempDir(), "fyne-ico-tmp.png")
out, err := os.Create(tmpPath)
out, err := ioutil.TempFile("", "fyne-ico-tmp.png")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used that originally, but it's not in Go 1.14

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that? It seems to exist in Go 1.14 if you look at this: https://pkg.go.dev/io/ioutil@go1.14#TempFile. The os.CreateTemp stuff was added in Go 1.16 but this does the same thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch, I must have got the two confused sorry.

}

tmpPath := filepath.Join(os.TempDir(), "fyne-ico-tmp.png")
out, err := os.Create(tmpPath)
Copy link
Member

@Jacalz Jacalz May 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could create a folder in the temp directory using https://pkg.go.dev/io/ioutil#TempDir and save everything there when we create temporary files. We then simply make sure to remove the whole folder before exiting the command (we could probably even hook up the interup signal https://www.tutorialspoint.com/how-to-handle-signals-in-golang so that it removes it before exiting using ctrl+c).


err = png.Encode(out, srcImg)
if err != nil {
return "", fmt.Errorf("failed to encode icon: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable out isn't closed if we get an error here.

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good. Just one comment on a potentially incorrect defer. I also think it might be good to get this updated once fyne-io/image#1 lands.

cmd/fyne/internal/commands/package.go Show resolved Hide resolved
@Jacalz
Copy link
Member

Jacalz commented Jun 1, 2022

FYI, there are also conflicts with the base branch that need to be resolved.

@andydotxyz
Copy link
Member Author

FYI, there are also conflicts with the base branch that need to be resolved.

Thanks, fixed

@Jacalz Jacalz self-requested a review June 2, 2022 05:32
Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm. Thanks 👍

@andydotxyz andydotxyz merged commit 41496dc into fyne-io:develop Jun 2, 2022
@andydotxyz andydotxyz deleted the fix/2412 branch June 2, 2022 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants