Skip to content

Commit

Permalink
Remove the now not needed Resource.CachePath
Browse files Browse the repository at this point in the history
The was only used by the EFL driver.
It could be re-added if there is a real use-case.
  • Loading branch information
andydotxyz committed Feb 20, 2019
1 parent 96c23a3 commit ec587be
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 79 deletions.
13 changes: 0 additions & 13 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package fyne
type Resource interface {
Name() string
Content() []byte
CachePath() string
}

// StaticResource is a bundled resource compiled into the application.
Expand All @@ -30,18 +29,6 @@ func (r *StaticResource) Content() []byte {
return r.StaticContent
}

// CachePath will return the cached location of a resource.
// If the resource has not previously been written to a cache this operation
// will block until the data is available at the returned location.
func (r *StaticResource) CachePath() string {
path := cachePath(r.StaticName)
if !pathExists(path) {
toFile(r)
}

return path
}

// NewStaticResource returns a new static resource object with the specified
// name and content. Creating a new static resource in memory results in
// sharable binary data that may be serialised to the location returned by
Expand Down
13 changes: 0 additions & 13 deletions resource_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fyne

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -15,15 +14,3 @@ func TestNewResource(t *testing.T) {
assert.Equal(t, name, res.Name())
assert.Equal(t, content, res.Content())
}

func TestResourceFile(t *testing.T) {
content := []byte{1, 2, 3, 4}

res := NewStaticResource("file.dat", content)
path := res.CachePath()

assert.True(t, path != "")
assert.True(t, pathExists(path))

os.Remove(path)
}
15 changes: 0 additions & 15 deletions serialise.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,8 @@ package fyne
import (
"bytes"
"fmt"
"io/ioutil"
)

func fromFile(name string) Resource {
data, err := ioutil.ReadFile(cachePath(name))

if err != nil {
return nil
}

return NewStaticResource(name, data)
}

func toFile(res *StaticResource) {
ioutil.WriteFile(cachePath(res.StaticName), res.StaticContent, 0644)
}

// GoString converts a Resource object to Go code.
// This is useful if serialising to a Go file for compilation into a binary.
func (r *StaticResource) GoString() string {
Expand Down
20 changes: 0 additions & 20 deletions serialise_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fyne

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -14,25 +13,6 @@ var imgGo = `&fyne.StaticResource{
StaticContent: []byte{
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 1, 0, 0, 0, 1, 8, 2, 0, 0, 0, 144, 119, 83, 222, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1, 0, 154, 156, 24, 0, 0, 0, 7, 116, 73, 77, 69, 7, 226, 6, 5, 15, 49, 19, 102, 121, 20, 234, 0, 0, 0, 29, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 0, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 100, 46, 101, 7, 0, 0, 0, 12, 73, 68, 65, 84, 8, 215, 99, 248, 207, 192, 0, 0, 3, 1, 1, 0, 24, 221, 141, 176, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130}}`

func TestToFromFile(t *testing.T) {
path := cachePath(imgName)

res := NewStaticResource(imgName, imgBytes)
toFile(res)
assert.True(t, path != "")
if !pathExists(path) {
t.Errorf("%s was not written", imgName)
return
}

res2 := fromFile(imgName)
assert.True(t, res2 != nil)
assert.Equal(t, imgName, res2.Name())
assert.Equal(t, imgBytes, res2.Content())

os.Remove(path)
}

func TestToGo(t *testing.T) {
res := NewStaticResource(imgName, imgBytes)

Expand Down
9 changes: 0 additions & 9 deletions theme/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ func (res *ThemedResource) Content() []byte {
return res.dark.Content()
}

// CachePath returns the cachepath of the correct resource for the current theme setting
func (res *ThemedResource) CachePath() string {
if isThemeLight() {
return res.light.CachePath()
}

return res.dark.CachePath()
}

// NewThemedResource creates a resource that adapts to the current theme setting.
// It is currently a simple pairing of a dark and light variant of the same resource.
func NewThemedResource(dark, light fyne.Resource) *ThemedResource {
Expand Down
9 changes: 0 additions & 9 deletions theme/icons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,3 @@ func TestIconThemeChangeContent(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(LightTheme())
assert.NotEqual(t, content, cancel.Content())
}

func TestIconThemeChangePath(t *testing.T) {
fyne.CurrentApp().Settings().SetTheme(DarkTheme())
checked := CheckButtonIcon()
path := checked.CachePath()

fyne.CurrentApp().Settings().SetTheme(LightTheme())
assert.NotEqual(t, path, checked.CachePath())
}

0 comments on commit ec587be

Please sign in to comment.