Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new callback-based settings listener API #5431

Merged
merged 14 commits into from
Feb 2, 2025

Conversation

dweymouth
Copy link
Contributor

Description:

The existing Settings.AddChangeListener needs to be deprecated, since it is channel-based, and user code cannot block on channel receives from the main thread, and communicating to user code via a goroutine is against the new threading model.

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.
  • Any breaking changes have a deprecation path or have been discussed.

@andydotxyz
Copy link
Member

Not to sure how to resolve the conflict through web UI sorry @dweymouth

@dweymouth dweymouth marked this pull request as ready for review January 20, 2025 12:38
@coveralls
Copy link

coveralls commented Jan 20, 2025

Coverage Status

coverage: 62.638% (+3.5%) from 59.117%
when pulling 4f3ca6a on dweymouth:settings-callback
into e553897 on fyne-io:develop.

app/settings.go Outdated
@@ -170,7 +168,13 @@ func (s *settings) setupTheme() {
variant = theme.VariantDark
}

s.applyTheme(effectiveTheme, variant)
if async.IsMainGoroutine() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK that setupTheme is sometimes called from non-main?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the reasoning behind adding the IsMainGoroutine check. setupTheme is called from platform-specific code and I wasn't sure which of those would be on main, and which may be from a goroutine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should rely too much on async.IsMainGoroutine(). There is a reason that the Go developers don't expose the goroutine ID in a simple way as it allows people to more easily write bad code. Can we not use async.EnsureMain() for now until the migration is complete?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All OS specific code should come in on main. If it doesn't then other things will break.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then this should not do the ID check at all, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be my take. Unless there is some reason we know that this call can come from other places. In that situation it may be more desirable to fyne.Do it at the source.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Agreed :)

Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! I really like this new API and you are entirely correct that it is well worth it to replace the old one :)

app/settings.go Outdated Show resolved Hide resolved
app/settings.go Outdated
@@ -170,7 +168,13 @@ func (s *settings) setupTheme() {
variant = theme.VariantDark
}

s.applyTheme(effectiveTheme, variant)
if async.IsMainGoroutine() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should rely too much on async.IsMainGoroutine(). There is a reason that the Go developers don't expose the goroutine ID in a simple way as it allows people to more easily write bad code. Can we not use async.EnsureMain() for now until the migration is complete?

internal/driver/glfw/loop.go Outdated Show resolved Hide resolved
internal/driver/mobile/driver.go Outdated Show resolved Hide resolved
Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looking really good. Just a few small notes inline :)

test/app.go Outdated Show resolved Hide resolved
app/settings.go Outdated Show resolved Hide resolved
Copy link
Member

@Jacalz Jacalz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. Thanks

@dweymouth dweymouth merged commit 739f0e6 into fyne-io:develop Feb 2, 2025
11 checks passed
@dweymouth dweymouth deleted the settings-callback branch February 2, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants