Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into temp-test-app
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jun 17, 2024
2 parents 48034e0 + 237167e commit 39089be
Show file tree
Hide file tree
Showing 423 changed files with 3,433 additions and 2,349 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ Jacob Alzén <[email protected]>
Charles A. Daniels <[email protected]>
Pablo Fuentes <[email protected]>
Changkun Ou <[email protected]>
Cedric Bail
Drew Weymouth

2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (a *fyneApp) NewWindow(title string) fyne.Window {
}

func (a *fyneApp) Run() {
go a.lifecycle.RunEventQueue()
a.driver.Run()
}

Expand Down Expand Up @@ -138,6 +139,7 @@ func newAppWithDriver(d fyne.Driver, id string) fyne.App {
fyne.SetCurrentApp(newApp)

newApp.prefs = newApp.newDefaultPreferences()
newApp.lifecycle.InitEventQueue()
newApp.lifecycle.SetOnStoppedHookExecuted(func() {
if prefs, ok := newApp.prefs.(*preferences); ok {
prefs.forceImmediateSave()
Expand Down
27 changes: 9 additions & 18 deletions app/app_desktop_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package app
#include <AppKit/AppKit.h>
bool isBundled();
bool isDarkMode();
void watchTheme();
*/
import "C"
Expand All @@ -20,15 +19,12 @@ import (
"path/filepath"

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

// SetSystemTrayMenu creates a system tray item and attaches the specified menu.
// By default this will use the application icon.
func (a *fyneApp) SetSystemTrayMenu(menu *fyne.Menu) {
if desk, ok := a.Driver().(systrayDriver); ok {
desk.SetSystemTrayMenu(menu)
}
func (a *fyneApp) OpenURL(url *url.URL) error {
cmd := exec.Command("open", url.String())
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
return cmd.Run()
}

// SetSystemTrayIcon sets a custom image for the system tray icon.
Expand All @@ -37,11 +33,12 @@ func (a *fyneApp) SetSystemTrayIcon(icon fyne.Resource) {
a.Driver().(systrayDriver).SetSystemTrayIcon(icon)
}

func defaultVariant() fyne.ThemeVariant {
if C.isDarkMode() {
return theme.VariantDark
// SetSystemTrayMenu creates a system tray item and attaches the specified menu.
// By default this will use the application icon.
func (a *fyneApp) SetSystemTrayMenu(menu *fyne.Menu) {
if desk, ok := a.Driver().(systrayDriver); ok {
desk.SetSystemTrayMenu(menu)
}
return theme.VariantLight
}

func rootConfigDir() string {
Expand All @@ -51,12 +48,6 @@ func rootConfigDir() string {
return filepath.Join(desktopConfig, "fyne")
}

func (a *fyneApp) OpenURL(url *url.URL) error {
cmd := exec.Command("open", url.String())
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
return cmd.Run()
}

//export themeChanged
func themeChanged() {
fyne.CurrentApp().Settings().(*settings).setupTheme()
Expand Down
5 changes: 0 additions & 5 deletions app/app_desktop_darwin.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

#import <Foundation/Foundation.h>

bool isDarkMode() {
NSString *style = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
return [@"Dark" isEqualToString:style];
}

void watchTheme() {
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"AppleInterfaceThemeChangedNotification" object:nil queue:nil
usingBlock:^(NSNotification *note) {
Expand Down
5 changes: 2 additions & 3 deletions app/app_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ package app

import (
"fyne.io/fyne/v2"
internalapp "fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/driver/mobile"
)

var systemTheme fyne.ThemeVariant

// NewWithID returns a new app instance using the appropriate runtime driver.
// The ID string should be globally unique to this app.
func NewWithID(id string) fyne.App {
d := mobile.NewGoMobileDriver()
a := newAppWithDriver(d, id)
d.(mobile.ConfiguredDriver).SetOnConfigurationChanged(func(c *mobile.Configuration) {
systemTheme = c.SystemTheme
internalapp.SystemTheme = c.SystemTheme

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

func defaultVariant() fyne.ThemeVariant {
return systemTheme
}

func rootConfigDir() string {
filesDir := os.Getenv("FILESDIR")
if filesDir == "" {
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 @@ -17,8 +17,6 @@ import (
"net/url"
"path/filepath"
"unsafe"

"fyne.io/fyne/v2"
)

func rootConfigDir() string {
Expand All @@ -33,7 +31,3 @@ func (a *fyneApp) OpenURL(url *url.URL) error {

return nil
}

func defaultVariant() fyne.ThemeVariant {
return systemTheme
}
7 changes: 1 addition & 6 deletions app/app_other.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ci || (!linux && !darwin && !windows && !freebsd && !openbsd && !netbsd && !wasm && !test_web_driver)
//go:build ci || (mobile && !android && !ios) || (!linux && !darwin && !windows && !freebsd && !openbsd && !netbsd && !wasm && !test_web_driver)

package app

Expand All @@ -9,13 +9,8 @@ import (
"path/filepath"

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

func defaultVariant() fyne.ThemeVariant {
return theme.VariantDark
}

func rootConfigDir() string {
return filepath.Join(os.TempDir(), "fyne-test")
}
Expand Down
12 changes: 0 additions & 12 deletions app/app_theme_web.go

This file was deleted.

25 changes: 0 additions & 25 deletions app/app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import (
"strings"
"syscall"

"golang.org/x/sys/windows/registry"

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

const notificationTemplate = `$title = "%s"
Expand All @@ -31,28 +28,6 @@ $xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("%s").Show($toast);`

func isDark() bool {
k, err := registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize`, registry.QUERY_VALUE)
if err != nil { // older version of Windows will not have this key
return false
}
defer k.Close()

useLight, _, err := k.GetIntegerValue("AppsUseLightTheme")
if err != nil { // older version of Windows will not have this value
return false
}

return useLight == 0
}

func defaultVariant() fyne.ThemeVariant {
if isDark() {
return theme.VariantDark
}
return theme.VariantLight
}

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

Expand Down
13 changes: 4 additions & 9 deletions app/app_xdg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !ci && !wasm && !test_web_driver && (linux || openbsd || freebsd || netbsd) && !android
//go:build !ci && !wasm && !test_web_driver && !android && !ios && !mobile && (linux || openbsd || freebsd || netbsd)

package app

Expand All @@ -16,16 +16,11 @@ import (
"github.com/rymdport/portal/settings/appearance"

"fyne.io/fyne/v2"
internalapp "fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/theme"
)

var currentVariant atomic.Uint64

func defaultVariant() fyne.ThemeVariant {
return fyne.ThemeVariant(currentVariant.Load())
}

func (a *fyneApp) OpenURL(url *url.URL) error {
if build.IsFlatpak {
err := openuri.OpenURI("", url.String(), nil)
Expand Down Expand Up @@ -123,11 +118,11 @@ func rootConfigDir() string {
func watchTheme() {
go func() {
// with portal this may not be immediate, so we update a cache instead
currentVariant.Store(uint64(findFreedesktopColorScheme()))
internalapp.CurrentVariant.Store(uint64(findFreedesktopColorScheme()))

portalSettings.OnSignalSettingChanged(func(changed portalSettings.Changed) {
if changed.Namespace == "org.freedesktop.appearance" && changed.Key == "color-scheme" {
currentVariant.Store(uint64(findFreedesktopColorScheme()))
internalapp.CurrentVariant.Store(uint64(findFreedesktopColorScheme()))
fyne.CurrentApp().Settings().(*settings).setupTheme()
}
})
Expand Down
3 changes: 1 addition & 2 deletions app/preferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ func TestPreferences_Save_OverwriteFast(t *testing.T) {
val["key"] = "value"
})

path := filepath.Join(os.TempDir(), "fynePrefs2.json")
defer os.Remove(path)
path := filepath.Join(t.TempDir(), "fynePrefs2.json")
p.saveToFile(path)

p.WriteValues(func(val map[string]any) {
Expand Down
3 changes: 2 additions & 1 deletion app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

"fyne.io/fyne/v2"
internalapp "fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/build"
"fyne.io/fyne/v2/theme"
)
Expand Down Expand Up @@ -152,7 +153,7 @@ func (s *settings) setupTheme() {
name = env
}

variant := defaultVariant()
variant := internalapp.DefaultVariant()
effectiveTheme := s.theme
if !s.themeSpecified {
effectiveTheme = s.loadSystemTheme()
Expand Down
7 changes: 4 additions & 3 deletions app/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"fyne.io/fyne/v2"
internalapp "fyne.io/fyne/v2/internal/app"
"fyne.io/fyne/v2/internal/build"
internalTest "fyne.io/fyne/v2/internal/test"
"fyne.io/fyne/v2/test"
Expand Down Expand Up @@ -43,7 +44,7 @@ func TestSettingsLoad(t *testing.T) {
func TestOverrideTheme(t *testing.T) {
set := &settings{}
set.setupTheme()
assert.Equal(t, defaultVariant(), set.ThemeVariant())
assert.Equal(t, internalapp.DefaultVariant(), set.ThemeVariant())

set.schema.ThemeName = "light"
set.setupTheme()
Expand All @@ -57,7 +58,7 @@ func TestOverrideTheme(t *testing.T) {

set = &settings{}
set.setupTheme()
assert.Equal(t, defaultVariant(), set.ThemeVariant())
assert.Equal(t, internalapp.DefaultVariant(), set.ThemeVariant())

err := os.Setenv("FYNE_THEME", "light")
if err != nil {
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestCustomTheme(t *testing.T) {

set.setupTheme()
assert.True(t, set.Theme() == ctheme)
assert.Equal(t, defaultVariant(), set.ThemeVariant())
assert.Equal(t, internalapp.DefaultVariant(), set.ThemeVariant())

err := set.loadFromFile(filepath.Join("testdata", "light-theme.json"))
if err != nil {
Expand Down
14 changes: 11 additions & 3 deletions canvas/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,15 @@ func (i *Image) updateReader() (io.ReadCloser, error) {
i.isSVG = false
if i.Resource != nil {
i.isSVG = svg.IsResourceSVG(i.Resource)
return io.NopCloser(bytes.NewReader(i.Resource.Content())), nil
content := i.Resource.Content()
if res, ok := i.Resource.(fyne.ThemedResource); i.isSVG && ok {
th := cache.WidgetTheme(i)
if th != nil {
col := th.Color(res.ThemeColorName(), fyne.CurrentApp().Settings().ThemeVariant())
content = svg.Colorize(content, col)
}
}
return io.NopCloser(bytes.NewReader(content)), nil
} else if i.File != "" {
var err error

Expand Down Expand Up @@ -347,7 +355,7 @@ func (i *Image) renderSVG(width, height float32) (image.Image, error) {
screenWidth, screenHeight = c.PixelCoordinateForPosition(fyne.Position{X: width, Y: height})
}

tex := cache.GetSvg(i.name(), screenWidth, screenHeight)
tex := cache.GetSvg(i.name(), i, screenWidth, screenHeight)
if tex != nil {
return tex, nil
}
Expand All @@ -357,6 +365,6 @@ func (i *Image) renderSVG(width, height float32) (image.Image, error) {
if err != nil {
return nil, err
}
cache.SetSvg(i.name(), tex, screenWidth, screenHeight)
cache.SetSvg(i.name(), i, tex, screenWidth, screenHeight)
return tex, nil
}
8 changes: 3 additions & 5 deletions canvas/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
"testing"

"fyne.io/fyne/v2/canvas"
intRepo "fyne.io/fyne/v2/internal/repository"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/storage/repository"
_ "fyne.io/fyne/v2/test"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -43,6 +42,7 @@ func TestNewImageFromReader(t *testing.T) {
path := filepath.Join(filepath.Dir(pwd), "theme", "icons", "fyne.png")
read, err := os.Open(path)
assert.Nil(t, err)
defer read.Close()

img := canvas.NewImageFromReader(read, "fyne.png")
assert.NotNil(t, img)
Expand Down Expand Up @@ -77,9 +77,6 @@ func TestNewImageFromURI_File(t *testing.T) {
}

func TestNewImageFromURI_HTTP(t *testing.T) {
h := intRepo.NewHTTPRepository()
repository.Register("http", h)

pwd, _ := os.Getwd()
path := filepath.Join(filepath.Dir(pwd), "theme", "icons", "fyne.png")
f, _ := os.ReadFile(path)
Expand All @@ -95,6 +92,7 @@ func TestNewImageFromURI_HTTP(t *testing.T) {
}))
defer ts.Close()

// http is mounted in Fyne test handlers by default
url, _ := storage.ParseURI(ts.URL)
img := canvas.NewImageFromURI(url)
assert.NotNil(t, img)
Expand Down
Loading

0 comments on commit 39089be

Please sign in to comment.