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

Improve systray icon loading #882

Merged
merged 3 commits into from
Oct 2, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ require (
github.com/xtaci/lossyconn v0.0.0-20200209145036-adba10fffc37 // indirect
go.etcd.io/bbolt v1.3.5
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/tools v0.1.2 // indirect
golang.zx2c4.com/wireguard v0.0.20200320
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
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=
Expand Down
9 changes: 5 additions & 4 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package gui

import (
"context"
"embed"
"fmt"
"io"
"io/ioutil"
Expand All @@ -26,6 +27,9 @@ import (

// TODO @alexadhy : Show VPN status, list all vpn servers, quick dial

//go:embed icons/*
var iconFS embed.FS

var log = logging.NewMasterLogger()

var (
Expand Down Expand Up @@ -72,10 +76,7 @@ func OnGUIQuit() {

// ReadSysTrayIcon reads system tray icon.
func ReadSysTrayIcon() ([]byte, error) {
if err := preReadIcon(); err != nil {
return nil, err
}
contents, err := ioutil.ReadFile(iconPath)
contents, err := iconFS.ReadFile(iconName)
if err != nil {
return nil, fmt.Errorf("failed to read icon: %w", err)
}
Expand Down
28 changes: 1 addition & 27 deletions internal/gui/gui_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,15 @@
package gui

import (
"image/png"
"os"

"golang.org/x/image/tiff"
)

const (
pngIconPath = "/Applications/Skywire.app/Contents/Resources/icon.png"
iconPath = "/Applications/Skywire.app/Contents/Resources/tray_icon.tiff"
deinstallerPath = "/Applications/Skywire.app/Contents/deinstaller"
appPath = "/Applications/Skywire.app"
iconName = "icons/icon.tiff"
)

func preReadIcon() error {
imgFile, err := os.Open(pngIconPath)
if err != nil {
return err
}
img, err := png.Decode(imgFile)
if err != nil {
return err
}

tiffFile, err := os.Create(iconPath)
if err != nil {
return err
}

if err = tiff.Encode(tiffFile, img, nil); err != nil {
return err
}

return tiffFile.Close()
}

func checkIsPackage() bool {
_, err := os.Stat(appPath)
return err == nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gui/gui_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// TODO (darkrengarius): change path
const (
iconPath = "/opt/skywire/icon.png"
iconName = "icons/icon.png"
deinstallerPath = "/opt/skywire/deinstaller"
)

Expand Down
15 changes: 7 additions & 8 deletions internal/gui/gui_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ import (
)

// TODO (darkrengarius): change path
const iconPath = "%LOCALDATA\\skywire\\icon.png"
const iconName = "icons/icon.ico"

func deinstallerPath() string {
return filepath.Join(localDataPath, "skywire", "deinstaller.ps1")
func localDataPath() string {
return os.Getenv("LOCALDATA")
}

func platformExecUninstall() error {
localDataPath := os.Getenv("LOCALDATA")
return osutil.Run("pwsh", "-c", deinstallerPath)
func deinstallerPath() string {
return filepath.Join(localDataPath(), "skywire", "deinstaller.ps1")
}

func preReadIcon() error {
return nil
func platformExecUninstall() error {
return osutil.Run("pwsh", "-c", deinstallerPath())
}

func checkIsPackage() bool {
Expand Down
Binary file added internal/gui/icons/icon.ico
Binary file not shown.
Binary file added internal/gui/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added internal/gui/icons/icon.tiff
Binary file not shown.
3 changes: 0 additions & 3 deletions vendor/golang.org/x/image/AUTHORS

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/golang.org/x/image/CONTRIBUTORS

This file was deleted.

27 changes: 0 additions & 27 deletions vendor/golang.org/x/image/LICENSE

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/golang.org/x/image/PATENTS

This file was deleted.

Loading