Skip to content

Commit

Permalink
Merge develop into feature/on_colors
Browse files Browse the repository at this point in the history
  • Loading branch information
toaster committed Jun 18, 2024
2 parents b994b85 + 759df6f commit b1d56de
Show file tree
Hide file tree
Showing 217 changed files with 1,007 additions and 941 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

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: 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
}
6 changes: 2 additions & 4 deletions canvas/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ func TestText_MinSize_NoMultiLine(t *testing.T) {
}

func TestText_Layout(t *testing.T) {
test.NewApp()
defer test.NewApp()
test.NewTempApp(t)

for name, tt := range map[string]struct {
text string
Expand Down Expand Up @@ -132,8 +131,7 @@ func TestText_Layout(t *testing.T) {
}

func TestText_CarriageReturn(t *testing.T) {
test.NewApp()
defer test.NewApp()
test.NewTempApp(t)

for name, tt := range map[string]struct {
text string
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne_demo/data/metadata_bundled.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cmd/fyne_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ func makeMenu(a fyne.App, w fyne.Window) *fyne.MainMenu {
w.Resize(fyne.NewSize(440, 520))
w.Show()
}
showAbout := func() {
w := a.NewWindow("About")
w.SetContent(widget.NewLabel("About Fyne Demo app..."))
w.Show()
}
aboutItem := fyne.NewMenuItem("About", showAbout)
settingsItem := fyne.NewMenuItem("Settings", openSettings)
settingsShortcut := &desktop.CustomShortcut{KeyName: fyne.KeyComma, Modifier: fyne.KeyModifierShortcutDefault}
settingsItem.Shortcut = settingsShortcut
Expand Down Expand Up @@ -170,6 +176,7 @@ func makeMenu(a fyne.App, w fyne.Window) *fyne.MainMenu {
if !device.IsMobile() && !device.IsBrowser() {
file.Items = append(file.Items, fyne.NewMenuItemSeparator(), settingsItem)
}
file.Items = append(file.Items, aboutItem)
main := fyne.NewMainMenu(
file,
fyne.NewMenu("Edit", cutItem, copyItem, pasteItem, fyne.NewMenuItemSeparator(), findItem),
Expand Down
7 changes: 5 additions & 2 deletions cmd/fyne_demo/tutorials/animation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ func makeAnimationCanvas() fyne.CanvasObject {
rect := canvas.NewRectangle(color.Black)
rect.Resize(fyne.NewSize(410, 140))

a := canvas.NewColorRGBAAnimation(theme.PrimaryColorNamed(theme.ColorBlue), theme.PrimaryColorNamed(theme.ColorGreen),
a := canvas.NewColorRGBAAnimation(
color.NRGBA{R: 0x29, G: 0x6f, B: 0xf6, A: 0xaa},
color.NRGBA{R: 0x8b, G: 0xc3, B: 0x4a, A: 0xaa},
time.Second*3, func(c color.Color) {
rect.FillColor = c
canvas.Refresh(rect)
})
},
)
a.RepeatCount = fyne.AnimationRepeatForever
a.AutoReverse = true
a.Start()
Expand Down
Loading

0 comments on commit b1d56de

Please sign in to comment.