-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
195 changed files
with
15,605 additions
and
1,227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// +build !ci | ||
|
||
// +build android | ||
|
||
package app | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_RootConfigDir(t *testing.T) { | ||
oldEnv := os.Getenv("FILESPATH") | ||
os.Setenv("FILESPATH", "/tmp") | ||
|
||
assert.Equal(t, "/tmp", rootConfigDir()) | ||
os.Setenv("FILESPATH", oldEnv) | ||
} | ||
|
||
func Test_StoragePath(t *testing.T) { | ||
oldEnv := os.Getenv("FILESPATH") | ||
os.Setenv("FILESPATH", "/tmp") | ||
defer os.Setenv("FILESPATH", oldEnv) | ||
|
||
p := &preferences{} | ||
expected := "/tmp/storage/preferences.json" | ||
assert.Equal(t, expected, p.storagePath()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// +build darwin | ||
// +build !ci | ||
|
||
// +build ios | ||
|
||
#import <UIKit/UIKit.h> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// +build !ci | ||
|
||
// +build !mobile,!android,!ios | ||
// +build !android,!ios | ||
|
||
package app | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// +build !ci | ||
|
||
// +build linux openbsd freebsd netbsd | ||
// +build !android,!mobile | ||
// +build !android | ||
|
||
package app | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// +build android | ||
|
||
package app | ||
|
||
import "path/filepath" | ||
|
||
// storagePath returns the location of the settings storage | ||
func (p *preferences) storagePath() string { | ||
// we have no global storage, use app global instead - rootConfigDir looks up in app_mobile_and.go | ||
return filepath.Join(rootConfigDir(), "storage", "preferences.json") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// +build ios | ||
|
||
package app | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"fyne.io/fyne" | ||
) | ||
|
||
/* | ||
#import <stdbool.h> | ||
#import <stdlib.h> | ||
#import <Foundation/Foundation.h> | ||
bool getPreferenceBool(const char* key, bool fallback); | ||
void setPreferenceBool(const char* key, bool value); | ||
float getPreferenceFloat(const char* key, float fallback); | ||
void setPreferenceFloat(const char* key, float value); | ||
int getPreferenceInt(const char* key, int fallback); | ||
void setPreferenceInt(const char* key, int value); | ||
const char* getPreferenceString(const char* key, const char* fallback); | ||
void setPreferenceString(const char* key, const char* value); | ||
void removePreferenceValue(const char* key); | ||
*/ | ||
import "C" | ||
|
||
type iOSPreferences struct { | ||
} | ||
|
||
// Declare conformity with Preferences interface | ||
var _ fyne.Preferences = (*iOSPreferences)(nil) | ||
|
||
func (p *iOSPreferences) Bool(key string) bool { | ||
return p.BoolWithFallback(key, false) | ||
} | ||
|
||
func (p *iOSPreferences) BoolWithFallback(key string, fallback bool) bool { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
|
||
return bool(C.getPreferenceBool(cKey, C.bool(fallback))) | ||
} | ||
|
||
func (p *iOSPreferences) SetBool(key string, value bool) { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
|
||
C.setPreferenceBool(cKey, C.bool(value)) | ||
} | ||
|
||
func (p *iOSPreferences) Float(key string) float64 { | ||
return p.FloatWithFallback(key, 0.0) | ||
} | ||
|
||
func (p *iOSPreferences) FloatWithFallback(key string, fallback float64) float64 { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
|
||
return float64(C.getPreferenceFloat(cKey, C.float(fallback))) | ||
} | ||
|
||
func (p *iOSPreferences) SetFloat(key string, value float64) { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
|
||
C.setPreferenceFloat(cKey, C.float(value)) | ||
} | ||
|
||
func (p *iOSPreferences) Int(key string) int { | ||
return p.IntWithFallback(key, 0) | ||
} | ||
|
||
func (p *iOSPreferences) IntWithFallback(key string, fallback int) int { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
|
||
return int(C.getPreferenceInt(cKey, C.int(fallback))) | ||
} | ||
|
||
func (p *iOSPreferences) SetInt(key string, value int) { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
|
||
C.setPreferenceInt(cKey, C.int(value)) | ||
} | ||
|
||
func (p *iOSPreferences) String(key string) string { | ||
return p.StringWithFallback(key, "") | ||
} | ||
|
||
func (p *iOSPreferences) StringWithFallback(key, fallback string) string { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
cFallback := C.CString(fallback) | ||
defer C.free(unsafe.Pointer(cFallback)) | ||
|
||
return C.GoString(C.getPreferenceString(cKey, cFallback)) | ||
} | ||
|
||
func (p *iOSPreferences) SetString(key string, value string) { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
cValue := C.CString(value) | ||
defer C.free(unsafe.Pointer(cValue)) | ||
|
||
C.setPreferenceString(cKey, cValue) | ||
} | ||
|
||
func (p *iOSPreferences) RemoveValue(key string) { | ||
cKey := C.CString(key) | ||
defer C.free(unsafe.Pointer(cKey)) | ||
|
||
C.removePreferenceValue(cKey) | ||
} | ||
|
||
func newPreferences() *iOSPreferences { | ||
return &iOSPreferences{} | ||
} | ||
|
||
func loadPreferences(_ string) *iOSPreferences { | ||
return newPreferences() // iOS stores the ID itself so load == new | ||
} |
Oops, something went wrong.