ronantakizawa/codereview-bench huggingface dataset:
Repository: fyne-io/fyne
File: app/app_xdg.go (Go)

Code before:
//go:build !ci && !wasm && !test_web_driver && (linux || openbsd || freebsd || netbsd) && !android

package app

import (
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"sync/atomic"

	"github.com/godbus/dbus/v5"
	"github.com/rymdport/portal/notification"
	"github.com/rymdport/portal/openuri"
	portalSettings "github.com/rymdport/portal/settings"
	"github.com/rymdport/portal/settings/appearance"

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

var currentVariant = theme.VariantDark

func defaultVariant() fyne.ThemeVariant {
	return currentVariant
}

func (a *fyneApp) OpenURL(url *url.URL) error {
	if build.IsFlatpak {
		err := openuri.OpenURI("", url.String(), nil)
		if err != nil {
			fyne.LogError("Opening url in portal failed", err)
		}
		return err
	}

	cmd := exec.Command("xdg-open", url.String())
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Start()
}

// fetch color variant from dbus portal desktop settings.
func findFreedesktopColorScheme() fyne.ThemeVariant {
	colourScheme, err := appearance.GetColorScheme()
	if err != nil {
		return theme.VariantDark
	}

	switch colourScheme {
	case appearance.Light:

Review comment (bug):
Hmm. I think this might be introducing a race condition given that it is modified in a different goroutine? Might be worth using something like an `atomic.Pointer` or a lock?

Code after:
//go:build !ci && !wasm && !test_web_driver && (linux || openbsd || freebsd || netbsd) && !android

package app

import (
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"sync/atomic"

	"github.com/godbus/dbus/v5"
	"github.com/rymdport/portal/notification"
	"github.com/rymdport/portal/openuri"
	portalSettings "github.com/rymdport/portal/settings"
	"github.com/rymdport/portal/settings/appearance"

	"fyne.io/fyne/v2"
	"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)
		if err != nil {
			fyne.LogError("Opening url in portal failed", err)
		}
		return err
	}

	cmd := exec.Command("xdg-open", url.String())
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Start()
}

// fetch color variant from dbus portal desktop settings.
func findFreedesktopColorScheme() fyne.ThemeVariant {
	colourScheme, err := appearance.GetColorScheme()
	if err != nil {
		return theme.VariantDark
	}

	switch colourScheme {
	case appearance.Light:
Repository: fyne-io/fyne
File: app/app_xdg.go (Go)

Code before:
//go:build !ci && !wasm && !test_web_driver && (linux || openbsd || freebsd || netbsd) && !android

package app

import (
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"sync/atomic"

	"github.com/godbus/dbus/v5"
	"github.com/rymdport/portal/notification"
	"github.com/rymdport/portal/openuri"
	portalSettings "github.com/rymdport/portal/settings"
	"github.com/rymdport/portal/settings/appearance"

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

var currentVariant atomic.Value

func defaultVariant() fyne.ThemeVariant {
	val := currentVariant.Load()
	if val == nil {
		return theme.VariantDark
	}

	return val.(fyne.ThemeVariant)
}

func (a *fyneApp) OpenURL(url *url.URL) error {
	if build.IsFlatpak {
		err := openuri.OpenURI("", url.String(), nil)
		if err != nil {
			fyne.LogError("Opening url in portal failed", err)
		}
		return err
	}

	cmd := exec.Command("xdg-open", url.String())
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Start()
}

// fetch color variant from dbus portal desktop settings.

Review comment (suggestion):
Hmm. I actually have a better idea. Given that `fyne.ThemeVariant` is a uint, you can get cleaner and faster code by just using an `atomic.Uint64` and cast the value to a `fyne.ThemeVariant` where loading and storing.

Code after:
//go:build !ci && !wasm && !test_web_driver && (linux || openbsd || freebsd || netbsd) && !android

package app

import (
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"sync/atomic"

	"github.com/godbus/dbus/v5"
	"github.com/rymdport/portal/notification"
	"github.com/rymdport/portal/openuri"
	portalSettings "github.com/rymdport/portal/settings"
	"github.com/rymdport/portal/settings/appearance"

	"fyne.io/fyne/v2"
	"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)
		if err != nil {
			fyne.LogError("Opening url in portal failed", err)
		}
		return err
	}

	cmd := exec.Command("xdg-open", url.String())
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Start()
}

// fetch color variant from dbus portal desktop settings.
func findFreedesktopColorScheme() fyne.ThemeVariant {
	colourScheme, err := appearance.GetColorScheme()
	if err != nil {
		return theme.VariantDark
	}
Repository: fyne-io/fyne
File: app/app_xdg.go (Go)

Code before:
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"sync/atomic"

	"github.com/godbus/dbus/v5"
	"github.com/rymdport/portal/notification"
	"github.com/rymdport/portal/openuri"
	portalSettings "github.com/rymdport/portal/settings"
	"github.com/rymdport/portal/settings/appearance"

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

var currentVariant atomic.Value

func defaultVariant() fyne.ThemeVariant {
	val := currentVariant.Load()
	if val == nil {
		return theme.VariantDark
	}

	return val.(fyne.ThemeVariant)
}

func (a *fyneApp) OpenURL(url *url.URL) error {
	if build.IsFlatpak {
		err := openuri.OpenURI("", url.String(), nil)
		if err != nil {
			fyne.LogError("Opening url in portal failed", err)
		}
		return err
	}

	cmd := exec.Command("xdg-open", url.String())
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Start()
}

// fetch color variant from dbus portal desktop settings.
func findFreedesktopColorScheme() fyne.ThemeVariant {
	colourScheme, err := appearance.GetColorScheme()
	if err != nil {
		return theme.VariantDark
	}

	switch colourScheme {
	case appearance.Light:

Review comment (suggestion):
With the suggestion above, this would just be something like this (default/zero value is zero, aka `theme.VariantDark`):
```suggestion
	return fyne.ThemeVariant(currentVariant.Load())
```

Code after:
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"sync/atomic"

	"github.com/godbus/dbus/v5"
	"github.com/rymdport/portal/notification"
	"github.com/rymdport/portal/openuri"
	portalSettings "github.com/rymdport/portal/settings"
	"github.com/rymdport/portal/settings/appearance"

	"fyne.io/fyne/v2"
	"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)
		if err != nil {
			fyne.LogError("Opening url in portal failed", err)
		}
		return err
	}

	cmd := exec.Command("xdg-open", url.String())
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
	return cmd.Start()
}

// fetch color variant from dbus portal desktop settings.
func findFreedesktopColorScheme() fyne.ThemeVariant {
	colourScheme, err := appearance.GetColorScheme()
	if err != nil {
		return theme.VariantDark
	}

	switch colourScheme {
	case appearance.Light:
		return theme.VariantLight
	case appearance.Dark:
		return theme.VariantDark
	default:
		// Default to light theme to support Gnome's default see https://github.com/fyne-io/fyne/pull/3561
Repository: fyne-io/fyne
File: app/app_xdg.go (Go)

Code before:

// 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 { // don't use this on mobile tag
		desk.SetSystemTrayMenu(menu)
	}
}

// SetSystemTrayIcon sets a custom image for the system tray icon.
// You should have previously called `SetSystemTrayMenu` to initialise the menu icon.
func (a *fyneApp) SetSystemTrayIcon(icon fyne.Resource) {
	if desk, ok := a.Driver().(systrayDriver); ok { // don't use this on mobile tag
		desk.SetSystemTrayIcon(icon)
	}
}

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

func watchTheme() {
	go func() {
		// with portal this may not be immediate, so we update a cache instead
		currentVariant.Store(findFreedesktopColorScheme())

		portalSettings.OnSignalSettingChanged(func(changed portalSettings.Changed) {
			if changed.Namespace == "org.freedesktop.appearance" && changed.Key == "color-scheme" {
				currentVariant.Store(findFreedesktopColorScheme())
				fyne.CurrentApp().Settings().(*settings).setupTheme()
			}
		})
	}()
}


Review comment (suggestion):
Similar suggestion here:
```suggestion
		currentVariant.Store(uint64(findFreedesktopColorScheme()))
```

Code after:
		desk.SetSystemTrayMenu(menu)
	}
}

// SetSystemTrayIcon sets a custom image for the system tray icon.
// You should have previously called `SetSystemTrayMenu` to initialise the menu icon.
func (a *fyneApp) SetSystemTrayIcon(icon fyne.Resource) {
	if desk, ok := a.Driver().(systrayDriver); ok { // don't use this on mobile tag
		desk.SetSystemTrayIcon(icon)
	}
}

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

func watchTheme() {
	go func() {
		// with portal this may not be immediate, so we update a cache instead
		currentVariant.Store(uint64(findFreedesktopColorScheme()))

		portalSettings.OnSignalSettingChanged(func(changed portalSettings.Changed) {
			if changed.Namespace == "org.freedesktop.appearance" && changed.Key == "color-scheme" {
				currentVariant.Store(uint64(findFreedesktopColorScheme()))
				fyne.CurrentApp().Settings().(*settings).setupTheme()
			}
		})
	}()
}
Repository: fyne-io/fyne
File: layout/formlayout.go (Go)

Code before:
		objects[i].Resize(size)

		if i+1 < len(objects) {
			pos = fyne.NewPos(padding+labelWidth, y)
			size = fyne.NewSize(contentWidth, heights[row])
			if _, ok := objects[i+1].(*canvas.Text); ok {
				pos = pos.AddXY(innerPadding, innerPadding)
				size.Width -= innerPadding * 2
				size.Height = objects[i+1].MinSize().Height
			}

			objects[i+1].Move(pos)
			objects[i+1].Resize(size)
		}
		row++
	}
}

// MinSize finds the smallest size that satisfies all the child objects.
// For a FormLayout this is the width of the widest label and content items and the height is
// the sum of all column children combined with padding between each.
func (f *formLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
	labelWidth, contentWidth, heights := f.tableCellsSize(objects, 0)
	if len(heights) == 0 {
		return fyne.Size{}
	}

	padding := theme.Padding()
	minSize := fyne.Size{
		Width:  labelWidth + contentWidth + padding,
		Height: padding * float32(len(heights)-1),
	}

	for row := 0; row < len(heights); row++ {
		minSize.Height += heights[row]
	}
	return minSize
}

// NewFormLayout returns a new FormLayout instance
func NewFormLayout() fyne.Layout {
	return &formLayout{}
}


Review comment (performance):
Nit: `len(heights)` is invoked 3 times in this func. Compiler is probably smart enough to inline it but it wouldn't hurt to cache it in a variable

Code after:

		objects[i].Move(pos)
		objects[i].Resize(size)

		if i+1 < len(objects) {
			pos = fyne.NewPos(padding+labelWidth, y)
			size = fyne.NewSize(contentWidth, heights[row])
			if _, ok := objects[i+1].(*canvas.Text); ok {
				pos = pos.AddXY(innerPadding, innerPadding)
				size.Width -= innerPadding * 2
				size.Height = objects[i+1].MinSize().Height
			}

			objects[i+1].Move(pos)
			objects[i+1].Resize(size)
		}
		row++
	}
}

// MinSize finds the smallest size that satisfies all the child objects.
// For a FormLayout this is the width of the widest label and content items and the height is
// the sum of all column children combined with padding between each.
func (f *formLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
	labelWidth, contentWidth, heights := f.calculateTableSizes(objects, 0)
	if len(heights) == 0 {
		return fyne.Size{}
	}

	padding := theme.Padding()
	minSize := fyne.Size{
		Width:  labelWidth + contentWidth + padding,
		Height: padding * float32(len(heights)-1),
	}

	for _, height := range heights {
		minSize.Height += height
	}

	return minSize
}

// NewFormLayout returns a new FormLayout instance
func NewFormLayout() fyne.Layout {
	return &formLayout{}
}
Repository: fyne-io/fyne
File: internal/driver/glfw/window_x11.go (Go)

Code before:
//go:build !wayland && (linux || freebsd || openbsd || netbsd) && !wasm && !test_web_driver

package glfw

import (
	"strconv"

	"fyne.io/fyne/v2/driver"
)

// GetWindowHandle returns the window handle. Only implemented for X11 currently.
func (w *window) GetWindowHandle() string {
	xid := uint(w.viewport.GetX11Window())
	return "x11:" + strconv.FormatUint(uint64(xid), 16)
}

// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any) error) error {
	var err error
	done := make(chan struct{})
	runOnMain(func() {
		err = f(driver.X11WindowContext{
			WindowHandle: w.GetWindowHandle(),
		})
		close(done)
	})
	<-done
	return err
}


Review comment (suggestion):
I don't think this should be using the method above. I realise now that the "x11:" prefix is likely just how XDG Desktop Protocol wants the string formatted. See comment above about using the value of `GetX11Window()` as the type instead.

If you want to, you can remove `GetWindowhandle()` entirely and making the usage of it use this new functionality instead (by adding "x11:" as a prefix and formatting a base 16 string locally instead). I can also do that in a follow-up PR if you prefer.

Code after:
//go:build !wayland && (linux || freebsd || openbsd || netbsd) && !wasm && !test_web_driver

package glfw

import (
	"strconv"

	"fyne.io/fyne/v2/driver"
)

// GetWindowHandle returns the window handle. Only implemented for X11 currently.
func (w *window) GetWindowHandle() string {
	xid := uint(w.viewport.GetX11Window())
	return "x11:" + strconv.FormatUint(uint64(xid), 16)
}

// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any)) {
	var handle uintptr
	if v := w.view(); v != nil {
		handle = uintptr(v.GetX11Window())
	}
	runOnMain(func() {
		f(driver.X11WindowContext{
			WindowHandle: handle,
		})
	})
}
Repository: fyne-io/fyne
File: internal/driver/glfw/window_darwin.go (Go)

Code before:
//go:build darwin

package glfw

import (
	"fyne.io/fyne/v2/driver"
)

// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any) error) error {
	var err error
	done := make(chan struct{})
	runOnMain(func() {
		err = f(driver.MacWindowContext{
			NSWindow: uintptr(w.view().GetCocoaWindow()),
		})
		close(done)
	})
	<-done
	return err
}


Review comment (bug):
The call to `w.view()` can return nil. This might crash if called at the wrong time? Applies to most of the implementations.

Code after:
//go:build darwin

package glfw

import (
	"fyne.io/fyne/v2/driver"
)

// assert we are implementing driver.NativeWindow
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any)) {
	runOnMain(func() {
		var nsWindow uintptr
		if v := w.view(); v != nil {
			nsWindow = uintptr(v.GetCocoaWindow())
		}
		f(driver.MacWindowContext{
			NSWindow: nsWindow,
		})
	})
}
Repository: fyne-io/fyne
File: driver/native.go (Go)

Code before:

// WindowsWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a Microsoft Windows device.
//
// Since: 2.5
type WindowsWindowContext struct {
	// HWND is the window handle for the native window.
	HWND uintptr
}

// MacWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a macOS device.
//
// Since: 2.5
type MacWindowContext struct {
	// NSWindow is the window handle for the native window.
	NSWindow uintptr
}

// X11WindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a device with the X11 windowing system.
//
// Since: 2.5
type X11WindowContext struct {
	// WindowHandle is the window handle for the native X11 window.
	WindowHandle string
}

// WaylandWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a device with the Wayland windowing system.
//
// Since: 2.5
type WaylandWindowContext struct {
	// WaylandSurface is the handle to the native Wayland surface.
	WaylandSurface uintptr

	// EGLSurface is the handle to the native EGL surface.
	EGLSurface uintptr
}


Review comment (bug):
See comment further down about thing probably not making sense as a string. My string conversion for `.Windowhandle()` is likely a wrong assumption based on how XDG Desktop Portal wants it formatted.

Code after:

// WindowsWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a Microsoft Windows device.
//
// Since: 2.5
type WindowsWindowContext struct {
	// HWND is the window handle for the native window.
	HWND uintptr
}

// MacWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a macOS device.
//
// Since: 2.5
type MacWindowContext struct {
	// NSWindow is the window handle for the native window.
	NSWindow uintptr
}

// X11WindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a device with the X11 windowing system.
//
// Since: 2.5
type X11WindowContext struct {
	// WindowHandle is the window handle for the native X11 window.
	WindowHandle uintptr
}

// WaylandWindowContext is passed to the NativeWindow.RunNative callback
// when it is executed on a device with the Wayland windowing system.
//
// Since: 2.5
type WaylandWindowContext struct {
	// WaylandSurface is the handle to the native Wayland surface.
	WaylandSurface uintptr
}
Repository: fyne-io/fyne
File: test/theme_test.go (Go)

Code before:
package test

import (
	"fmt"
	"testing"

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

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

// Try to keep these in sync with the existing color names at theme/colors.go.
var knownColorNames = []fyne.ThemeColorName{
	theme.ColorNameBackground,
	theme.ColorNameButton,
	theme.ColorNameDisabledButton,
	theme.ColorNameDisabled,
	theme.ColorNameError,
	theme.ColorNameFocus,
	theme.ColorNameForeground,
	theme.ColorNameHeaderBackground,
	theme.ColorNameHover,
	theme.ColorNameHyperlink,
	theme.ColorNameInputBackground,
	theme.ColorNameInputBorder,
	theme.ColorNameMenuBackground,
	theme.ColorNameOnPrimary,
	theme.ColorNameOverlayBackground,
	theme.ColorNamePlaceHolder,
	theme.ColorNamePressed,
	theme.ColorNamePrimary,
	theme.ColorNameScrollBar,
	theme.ColorNameSelection,
	theme.ColorNameSeparator,
	theme.ColorNameShadow,
	theme.ColorNameSuccess,
	theme.ColorNameWarning,

Review comment (suggestion):
The file is called `color.go`. Also, lets add a comment there to update this list once new colours are added.
```suggestion
// Try to keep these in sync with the existing color names at theme/color.go.
```

Code after:
package test

import (
	"fmt"
	"testing"

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

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

// Try to keep these in sync with the existing color names at theme/color.go.
var knownColorNames = []fyne.ThemeColorName{
	theme.ColorNameBackground,
	theme.ColorNameButton,
	theme.ColorNameDisabledButton,
	theme.ColorNameDisabled,
	theme.ColorNameError,
	theme.ColorNameFocus,
	theme.ColorNameForeground,
	theme.ColorNameHeaderBackground,
	theme.ColorNameHover,
	theme.ColorNameHyperlink,
	theme.ColorNameInputBackground,
	theme.ColorNameInputBorder,
	theme.ColorNameMenuBackground,
	theme.ColorNameOnPrimary,
	theme.ColorNameOverlayBackground,
	theme.ColorNamePlaceHolder,
	theme.ColorNamePressed,
	theme.ColorNamePrimary,
	theme.ColorNameScrollBar,
	theme.ColorNameSelection,
	theme.ColorNameSeparator,
	theme.ColorNameShadow,
	theme.ColorNameSuccess,
	theme.ColorNameWarning,
Repository: fyne-io/fyne
File: internal/driver/glfw/driver_xdg.go (Go)

Code before:
var inhibitCookie uint32

func setDisableScreenBlank(disable bool) {
	conn, err := dbus.SessionBus() // shared connection, don't close
	if err != nil {
		fyne.LogError("Unable to connect to session D-Bus", err)
		return
	}

	if !disable {
		if inhibitCookie != 0 {
			obj := conn.Object("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver")
			call := obj.Call("org.freedesktop.ScreenSaver.UnInhibit", 0, inhibitCookie)
			if call.Err != nil {
				fyne.LogError("Failed to send message to bus", call.Err)
			}
			inhibitCookie = 0
		}
		return
	}

	if inhibitCookie != 0 {
		return
	}
	obj := conn.Object("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver")
	call := obj.Call("org.freedesktop.ScreenSaver.Inhibit", 0, fyne.CurrentApp().Metadata().Name,
		"App disabled screensaver")
	if call.Err == nil {
		inhibitCookie = call.Body[0].(uint32)
	} else {
		fyne.LogError("Failed to send message to bus", call.Err)
	}
}


Review comment (suggestion):
I think this should be the application ID and not the name? The docs over at https://specifications.freedesktop.org/idle-inhibit-spec/latest/re01.html say: "A unique identifier for the application, usually a reverse domain (such as 'org.freedesktop.example')."

Code after:
var inhibitCookie uint32

func setDisableScreenBlank(disable bool) {
	conn, err := dbus.SessionBus() // shared connection, don't close
	if err != nil {
		fyne.LogError("Unable to connect to session D-Bus", err)
		return
	}

	if !disable {
		if inhibitCookie != 0 {
			obj := conn.Object("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver")
			call := obj.Call("org.freedesktop.ScreenSaver.UnInhibit", 0, inhibitCookie)
			if call.Err != nil {
				fyne.LogError("Failed to send message to bus", call.Err)
			}
			inhibitCookie = 0
		}
		return
	}

	if inhibitCookie != 0 {
		return
	}
	obj := conn.Object("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver")
	call := obj.Call("org.freedesktop.ScreenSaver.Inhibit", 0, fyne.CurrentApp().Metadata().ID,
		"App disabled screensaver")
	if call.Err == nil {
		inhibitCookie = call.Body[0].(uint32)
	} else {
		fyne.LogError("Failed to send message to bus", call.Err)
	}
}