Use temp directory for walk resource manager (#129)

* Use temp directory for walk resource manager

* Use appdir for temp dir

Co-authored-by: Ox Cart <ox.to.a.cart@gmail.com>
This commit is contained in:
maxb
2020-03-13 14:19:18 -07:00
committed by GitHub
co-authored by Ox Cart
parent 0de639be68
commit 6a2da1056d
3 changed files with 26 additions and 3 deletions
+3
View File
@@ -3,9 +3,12 @@ module github.com/getlantern/systray
go 1.12
require (
github.com/getlantern/appdir v0.0.0-20180320102544-7c0f9d241ea7
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7
github.com/getlantern/uuid v1.2.0
github.com/lxn/walk v0.0.0-20191113135339-bf589de20b3c
github.com/lxn/win v0.0.0-20191106123917-121afc750dd3 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
golang.org/x/sys v0.0.0-20190919044723-0c1ff786ef13 // indirect
gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect
)
+6
View File
@@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getlantern/appdir v0.0.0-20180320102544-7c0f9d241ea7 h1:4b2ht7EWptzPz/e6shqGZn3p5dXh4E3VETyKMTTPfGo=
github.com/getlantern/appdir v0.0.0-20180320102544-7c0f9d241ea7/go.mod h1:3vR6+jQdWfWojZ77w+htCqEF5MO/Y2twJOpAvFuM9po=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4=
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 h1:6uJ+sZ/e03gkbqZ0kUG6mfKoqDb4XMAzMIwlajq19So=
@@ -12,12 +14,16 @@ github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0F
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA=
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA=
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
github.com/getlantern/uuid v1.2.0 h1:pGrGaCV7XEaG6lvjWkwf8Y92BjB/9yFmkKsNFpRQ7rc=
github.com/getlantern/uuid v1.2.0/go.mod h1:uX10hOzZUUDR+oYNSIks+RcozOEiwTNC/K2rw9SUi1k=
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/lxn/walk v0.0.0-20191113135339-bf589de20b3c h1:4pJw1uBKndwiBBJpcbqP1Bf90YfqTJUsHG9DVoAfIQ8=
github.com/lxn/walk v0.0.0-20191113135339-bf589de20b3c/go.mod h1:E23UucZGqpuUANJooIbHWCufXvOcT6E7Stq81gU+CSQ=
github.com/lxn/win v0.0.0-20191106123917-121afc750dd3 h1:DvGEvKK/Qnhph/EgdBN9zXA7pEosgJ0k57ojII51JAo=
github.com/lxn/win v0.0.0-20191106123917-121afc750dd3/go.mod h1:ouWl4wViUNh8tPSIwxTVMuS014WakR1hqvBc2I0bMoA=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+17 -3
View File
@@ -6,10 +6,12 @@ import (
"crypto/md5"
"fmt"
"io/ioutil"
"path/filepath"
"os"
"path/filepath"
"sync/atomic"
"github.com/getlantern/appdir"
"github.com/getlantern/uuid"
"github.com/lxn/walk"
)
@@ -26,6 +28,18 @@ var (
)
func nativeLoop(title string, width int, height int) {
if randomPath, uuidErr := uuid.NewRandom(); uuidErr != nil {
fail("Unable to generate guid for creating temp dir (this should never happen): %v", uuidErr)
} else {
tmpDir := filepath.Join(appdir.General("systray"), randomPath.String())
if dirErr := os.MkdirAll(tmpDir, 0755); dirErr != nil {
fail("Error creating temp dir: %s", dirErr)
} else {
walk.Resources.SetRootDirPath(tmpDir)
defer os.RemoveAll(tmpDir)
}
}
var err error
mainWindow, err = walk.NewMainWindow()
if err != nil {
@@ -78,7 +92,7 @@ func quit() {
// for other platforms.
func SetIcon(iconBytes []byte) {
md5 := md5.Sum(iconBytes)
filename := fmt.Sprintf("systray.%x.ico", md5)
filename := fmt.Sprintf("%x.ico", md5)
iconpath := filepath.Join(walk.Resources.RootDirPath(), filename)
// First, try to find a previously loaded icon in walk cache
icon, err := walk.Resources.Icon(filename)
@@ -172,7 +186,7 @@ func addOrUpdateMenuItem(item *MenuItem) {
// iconBytes should be the content of .ico/.jpg/.png
func (item *MenuItem) SetIcon(iconBytes []byte) {
md5 := md5.Sum(iconBytes)
filename := fmt.Sprintf("systray.%x.ico", md5)
filename := fmt.Sprintf("%x.ico", md5)
iconpath := filepath.Join(walk.Resources.RootDirPath(), filename)
// First, try to find a previously loaded icon in walk cache
icon, err := walk.Resources.Image(filename)