Skip to content

Commit

Permalink
Merge pull request #5231 from andydotxyz/fix/systemthemefallback
Browse files Browse the repository at this point in the history
Defer to system theme when a custom theme delegates to DefaultTheme
  • Loading branch information
andydotxyz authored Dec 1, 2024
2 parents e8be3f6 + c64f5b2 commit 5987ac4
Show file tree
Hide file tree
Showing 29 changed files with 172 additions and 73 deletions.
8 changes: 0 additions & 8 deletions app/app_desktop_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"net/url"
"os"
"os/exec"
"path/filepath"

"fyne.io/fyne/v2"
)
Expand All @@ -41,13 +40,6 @@ func (a *fyneApp) SetSystemTrayMenu(menu *fyne.Menu) {
}
}

func rootConfigDir() string {
homeDir, _ := os.UserHomeDir()

desktopConfig := filepath.Join(filepath.Join(homeDir, "Library"), "Preferences")
return filepath.Join(desktopConfig, "fyne")
}

//export themeChanged
func themeChanged() {
fyne.CurrentApp().Settings().(*settings).setupTheme()
Expand Down
4 changes: 0 additions & 4 deletions app/app_goxjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func (a *fyneApp) SendNotification(n *fyne.Notification) {
}
}

func rootConfigDir() string {
return "/data/"
}

var themeChanged = js.FuncOf(func(this js.Value, args []js.Value) interface{} {
if len(args) > 0 && args[0].Type() == js.TypeObject {
fyne.CurrentApp().Settings().(*settings).setupTheme()
Expand Down
13 changes: 0 additions & 13 deletions app/app_mobile_and.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ void sendNotification(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char
*/
import "C"
import (
"log"
"net/url"
"os"
"path/filepath"
"unsafe"

"fyne.io/fyne/v2"
Expand Down Expand Up @@ -44,13 +41,3 @@ func (a *fyneApp) SendNotification(n *fyne.Notification) {
return nil
})
}

func rootConfigDir() string {
filesDir := os.Getenv("FILESDIR")
if filesDir == "" {
log.Println("FILESDIR env was not set by android native code")
return "/data/data" // probably won't work, but we can't make a better guess
}

return filepath.Join(filesDir, "fyne")
}
4 changes: 3 additions & 1 deletion app/app_mobile_and_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import (
"os"
"testing"

"fyne.io/fyne/v2/internal/app"

"github.com/stretchr/testify/assert"
)

func Test_RootConfigDir(t *testing.T) {
oldEnv := os.Getenv("FILESPATH")
os.Setenv("FILESPATH", "/tmp")

assert.Equal(t, "/tmp", rootConfigDir())
assert.Equal(t, "/tmp", app.RootConfigDir())
os.Setenv("FILESPATH", oldEnv)
}

Expand Down
6 changes: 0 additions & 6 deletions app/app_mobile_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ void sendNotification(char *title, char *content);
import "C"
import (
"net/url"
"path/filepath"
"unsafe"
)

func rootConfigDir() string {
root := C.documentsPath()
return filepath.Join(C.GoString(root), "fyne")
}

func (a *fyneApp) OpenURL(url *url.URL) error {
urlStr := C.CString(url.String())
C.openURL(urlStr)
Expand Down
6 changes: 0 additions & 6 deletions app/app_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ package app
import (
"errors"
"net/url"
"os"
"path/filepath"

"fyne.io/fyne/v2"
)

func rootConfigDir() string {
return filepath.Join(os.TempDir(), "fyne-test")
}

func (a *fyneApp) OpenURL(_ *url.URL) error {
return errors.New("Unable to open url for unknown operating system")
}
Expand Down
7 changes: 0 additions & 7 deletions app/app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ $xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("%s").Show($toast);`

func rootConfigDir() string {
homeDir, _ := os.UserHomeDir()

desktopConfig := filepath.Join(filepath.Join(homeDir, "AppData"), "Roaming")
return filepath.Join(desktopConfig, "fyne")
}

func (a *fyneApp) OpenURL(url *url.URL) error {
cmd := exec.Command("rundll32", "url.dll,FileProtocolHandler", url.String())
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
Expand Down
6 changes: 0 additions & 6 deletions app/app_xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/url"
"os"
"os/exec"
"path/filepath"
"sync/atomic"

"github.com/godbus/dbus/v5"
Expand Down Expand Up @@ -114,11 +113,6 @@ func (a *fyneApp) SetSystemTrayIcon(icon fyne.Resource) {
}
}

func rootConfigDir() string {
desktopConfig, _ := os.UserConfigDir()
return filepath.Join(desktopConfig, "fyne")
}

func watchTheme(s *settings) {
go func() {
// Theme lookup hangs on some desktops. Update theme variant cache from within goroutine.
Expand Down
8 changes: 6 additions & 2 deletions app/preferences_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

package app

import "path/filepath"
import (
"path/filepath"

"fyne.io/fyne/v2/internal/app"
)

// storagePath returns the location of the settings storage
func (p *preferences) storagePath() string {
Expand All @@ -12,7 +16,7 @@ func (p *preferences) storagePath() string {

// storageRoot returns the location of the app storage
func (a *fyneApp) storageRoot() string {
return rootConfigDir() // we are in a sandbox, so no app ID added to this path
return app.RootConfigDir() // we are in a sandbox, so no app ID added to this path
}

func (p *preferences) watch() {
Expand Down
4 changes: 3 additions & 1 deletion app/preferences_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package app

import (
"path/filepath"

"fyne.io/fyne/v2/internal/app"
)
import "C"

Expand All @@ -15,7 +17,7 @@ func (p *preferences) storagePath() string {

// storageRoot returns the location of the app storage
func (a *fyneApp) storageRoot() string {
return rootConfigDir() // we are in a sandbox, so no app ID added to this path
return app.RootConfigDir() // we are in a sandbox, so no app ID added to this path
}

func (p *preferences) watch() {
Expand Down
8 changes: 6 additions & 2 deletions app/preferences_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

package app

import "path/filepath"
import (
"path/filepath"

"fyne.io/fyne/v2/internal/app"
)

// storagePath returns the location of the settings storage
func (p *preferences) storagePath() string {
Expand All @@ -11,7 +15,7 @@ func (p *preferences) storagePath() string {

// storageRoot returns the location of the app storage
func (a *fyneApp) storageRoot() string {
return filepath.Join(rootConfigDir(), a.UniqueID())
return filepath.Join(app.RootConfigDir(), a.UniqueID())
}

func (p *preferences) watch() {
Expand Down
8 changes: 6 additions & 2 deletions app/preferences_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

package app

import "path/filepath"
import (
"path/filepath"

"fyne.io/fyne/v2/internal/app"
)

// storagePath returns the location of the settings storage
func (p *preferences) storagePath() string {
Expand All @@ -11,7 +15,7 @@ func (p *preferences) storagePath() string {

// storageRoot returns the location of the app storage
func (a *fyneApp) storageRoot() string {
return filepath.Join(rootConfigDir(), a.UniqueID())
return filepath.Join(app.RootConfigDir(), a.UniqueID())
}

func (p *preferences) watch() {
Expand Down
8 changes: 4 additions & 4 deletions app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

"fyne.io/fyne/v2"
internalapp "fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/theme"
)
Expand All @@ -25,7 +25,7 @@ type SettingsSchema struct {

// StoragePath returns the location of the settings storage
func (sc *SettingsSchema) StoragePath() string {
return filepath.Join(rootConfigDir(), "settings.json")
return filepath.Join(app.RootConfigDir(), "settings.json")
}

// Declare conformity with Settings interface
Expand Down Expand Up @@ -134,7 +134,7 @@ func (s *settings) fileChanged() {
}

func (s *settings) loadSystemTheme() fyne.Theme {
path := filepath.Join(rootConfigDir(), "theme.json")
path := filepath.Join(app.RootConfigDir(), "theme.json")
data, err := fyne.LoadResourceFromPath(path)
if err != nil {
if !os.IsNotExist(err) {
Expand All @@ -158,7 +158,7 @@ func (s *settings) setupTheme() {
name = env
}

variant := internalapp.DefaultVariant()
variant := app.DefaultVariant()
effectiveTheme := s.theme
if !s.themeSpecified {
effectiveTheme = s.loadSystemTheme()
Expand Down
5 changes: 5 additions & 0 deletions internal/app/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package app

func RootConfigDir() string {
return rootConfigDir()
}
15 changes: 15 additions & 0 deletions internal/app/config_desktop_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !ci && !ios && !wasm && !test_web_driver && !mobile

package app

import (
"os"
"path/filepath"
)

func rootConfigDir() string {
homeDir, _ := os.UserHomeDir()

desktopConfig := filepath.Join(filepath.Join(homeDir, "Library"), "Preferences")
return filepath.Join(desktopConfig, "fyne")
}
7 changes: 7 additions & 0 deletions internal/app/config_goxjs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !ci && (!android || !ios || !mobile) && (wasm || test_web_driver)

package app

func rootConfigDir() string {
return "/data/"
}
19 changes: 19 additions & 0 deletions internal/app/config_mobile_and.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !ci && android

package app

import (
"log"
"os"
"path/filepath"
)

func rootConfigDir() string {
filesDir := os.Getenv("FILESDIR")
if filesDir == "" {
log.Println("FILESDIR env was not set by android native code")
return "/data/data" // probably won't work, but we can't make a better guess
}

return filepath.Join(filesDir, "fyne")
}
12 changes: 12 additions & 0 deletions internal/app/config_mobile_ios.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !ci && ios && !mobile

package app

import (
"path/filepath"
)

func rootConfigDir() string {
root := C.documentsPath()
return filepath.Join(C.GoString(root), "fyne")
}
12 changes: 12 additions & 0 deletions internal/app/config_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build ci || (mobile && !android && !ios) || (!linux && !darwin && !windows && !freebsd && !openbsd && !netbsd && !wasm && !test_web_driver)

package app

import (
"os"
"path/filepath"
)

func rootConfigDir() string {
return filepath.Join(os.TempDir(), "fyne-test")
}
15 changes: 15 additions & 0 deletions internal/app/config_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build !ci && !android && !ios && !wasm && !test_web_driver

package app

import (
"os"
"path/filepath"
)

func rootConfigDir() string {
homeDir, _ := os.UserHomeDir()

desktopConfig := filepath.Join(filepath.Join(homeDir, "AppData"), "Roaming")
return filepath.Join(desktopConfig, "fyne")
}
13 changes: 13 additions & 0 deletions internal/app/config_xdg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !ci && !wasm && !test_web_driver && !android && !ios && !mobile && (linux || openbsd || freebsd || netbsd)

package app

import (
"os"
"path/filepath"
)

func rootConfigDir() string {
desktopConfig, _ := os.UserConfigDir()
return filepath.Join(desktopConfig, "fyne")
}
2 changes: 1 addition & 1 deletion internal/app/theme_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool isDarkMode();
import "C"
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/internal/theme"
)

// DefaultVariant returns the systems default fyne.ThemeVariant.
Expand Down
2 changes: 1 addition & 1 deletion internal/app/theme_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package app

import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/internal/theme"
)

// DefaultVariant returns the systems default fyne.ThemeVariant.
Expand Down
2 changes: 1 addition & 1 deletion internal/app/theme_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"syscall/js"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/internal/theme"
)

// DefaultVariant returns the systems default fyne.ThemeVariant.
Expand Down
Loading

0 comments on commit 5987ac4

Please sign in to comment.