Skip to content
New issue

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

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

Already on GitHub? # to your account

Add Interface name const to generated code #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MatthiasKunnen
Copy link

@MatthiasKunnen MatthiasKunnen commented Dec 4, 2024

Exports the name of the interface. This avoids the user having to know the exact interface name and can help protect against typos.

This allows for the following code:

func HandleRegistryGlobal(e client.RegistryGlobalEvent) {
	switch e.Interface {
	case idleNotify.IdleNotifierInterfaceName:
		m.notifier = idleNotify.NewIdleNotifier(m.context())
		err := m.registry.Bind(e.Name, e.Interface, e.Version, m.notifier)
		if err != nil {
			log.Fatalf("Unable to bind %s interface: %v", idleNotify.IdleNotifierInterfaceName, err)
		}
	case client.SeatInterfaceName:
		seat := client.NewSeat(m.context())
		err := m.registry.Bind(e.Name, e.Interface, e.Version, seat)
		if err != nil {
			log.Fatalf("unable to bind %s interface: %v", client.SeatInterfaceName, err)
		}
		m.seat = seat
	}
}

I did not include the generation changes in this PR because it would've required basing it on #8. As soon as that PR is merged and the URLs are updated, I can generate the code.

An example of the code it generates:

// IdleNotifierInterfaceName is the name of the interface as it appears in the [client.Registry].
// It can be used to match the [client.RegistryGlobalEvent.Interface] in the
// [Registry.SetGlobalHandler] and can be used in [Registry.Bind] if this applies.
const IdleNotifierInterfaceName = "ext_idle_notifier_v1"

Any and all feedback welcome

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant