Skip to content

Commit

Permalink
rework systray icon loading (embed)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexadhy committed Sep 10, 2021
1 parent da35b3f commit 604d280
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 69 deletions.
5 changes: 2 additions & 3 deletions cmd/apps/skychat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ skychat app for skywire visor
package main

import (
"embed"
"encoding/json"
"flag"
"fmt"
"io/fs"
"net"
"net/http"
"os"
"sync"
"time"

"embed"
"io/fs"

"github.com/skycoin/dmsg/buildinfo"
"github.com/skycoin/dmsg/cipher"

Expand Down
1 change: 1 addition & 0 deletions cmd/skywire-visor/commands/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package commands

import (
"context"

"github.com/getlantern/systray"
"github.com/skycoin/skycoin/src/util/logging"

Expand Down
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
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-redis/redis v6.15.8+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
Expand Down Expand Up @@ -184,12 +185,7 @@ github.com/klauspost/reedsolomon v1.9.9/go.mod h1:O7yFFHiQwDR6b2t63KPUpccPtNdp5A
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
<<<<<<< HEAD
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
=======
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
>>>>>>> upstream/develop
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand Down Expand Up @@ -402,8 +398,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 Expand Up @@ -474,11 +468,8 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
<<<<<<< HEAD
golang.org/x/sys v0.0.0-20210217105451-b926d437f341/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
=======
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
>>>>>>> upstream/develop
golang.org/x/sys v0.0.0-20210217105451-b926d437f341/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139 h1:C+AwYEtBp/VQwoLntUmQ/yx3MS9vmZaKNdw5eOpoQe8=
Expand Down
12 changes: 7 additions & 5 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//+build systray
//go:build systray
// +build systray

package gui

import (
"context"
"embed"
"fmt"
"io"
"io/ioutil"
Expand All @@ -25,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 @@ -71,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
35 changes: 5 additions & 30 deletions internal/gui/gui_darwin.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
//+build darwin,systray
//go:build darwin && systray
// +build darwin,systray

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"
iconName = "icons/icon.tiff"
deinstallerPath = "/Applications/Skywire.app/Contents/deinstaller"
appPath = "/Applications/Skywire.app"
appPath = "/Applications/Skywire.app"
)

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)
_, err := os.Stat(deinstallerPath)
return err == nil
}
9 changes: 3 additions & 6 deletions internal/gui/gui_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build linux,systray
//go:build linux && systray
// +build linux,systray

package gui

Expand All @@ -8,14 +9,10 @@ import (

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

func preReadIcon() error {
return nil
}

func checkIsPackage() bool {
_, err := os.Stat(deinstallerPath)
return err == nil
Expand Down
33 changes: 33 additions & 0 deletions internal/gui/gui_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build systray
// +build systray

package gui

import (
"testing"

"github.com/skycoin/dmsg/cipher"
"github.com/stretchr/testify/require"

"github.com/skycoin/skywire/pkg/visor/visorconfig"
)

func TestGetAvailPublicVPNServers(t *testing.T) {
pk, sk := cipher.GenerateKeyPair()
common := &visorconfig.Common{
Version: "v1.1.0",
SK: sk,
PK: pk,
}
config := visorconfig.MakeBaseConfig(common)
servers := GetAvailPublicVPNServers(config)
require.NotEqual(t, nil, servers)
require.NotEqual(t, []string{}, servers)
t.Logf("Servers: %v", servers)
}

func TestReadEmbeddedIcon(t *testing.T) {
b, err := ReadSysTrayIcon()
require.NoError(t, err)
require.NotEqual(t, 0, len(b))
}
3 changes: 2 additions & 1 deletion internal/gui/gui_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build !windows,systray
//go:build !windows && systray
// +build !windows,systray

package gui

Expand Down
19 changes: 9 additions & 10 deletions internal/gui/gui_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//+build windows,systray
//go:build windows && systray
// +build windows,systray

package gui

Expand All @@ -9,20 +10,18 @@ import (
"github.com/skycoin/skywire/pkg/util/osutil"
)

// TODO (darkrengarius): change path
const iconPath = "%LOCALDATA\\skywire\\icon.png"
var 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: 1 addition & 2 deletions pkg/visor/hypervisorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package hypervisorconfig
import (
"encoding/hex"
"encoding/json"
"io/fs"
"log"
"net/http"
"os"
"path/filepath"
"time"

"io/fs"

"github.com/skycoin/dmsg/cipher"

"github.com/skycoin/skywire/pkg/skyenv"
Expand Down

0 comments on commit 604d280

Please sign in to comment.