app_desktop_darwin.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //go:build !ci && !ios && !js && !wasm && !test_web_driver
  2. // +build !ci,!ios,!js,!wasm,!test_web_driver
  3. package app
  4. /*
  5. #cgo CFLAGS: -x objective-c
  6. #cgo LDFLAGS: -framework Foundation
  7. #include <AppKit/AppKit.h>
  8. bool isBundled();
  9. bool isDarkMode();
  10. void watchTheme();
  11. */
  12. import "C"
  13. import (
  14. "net/url"
  15. "os"
  16. "path/filepath"
  17. "golang.org/x/sys/execabs"
  18. "fyne.io/fyne/v2"
  19. "fyne.io/fyne/v2/theme"
  20. )
  21. // SetSystemTrayMenu creates a system tray item and attaches the specified menu.
  22. // By default this will use the application icon.
  23. func (a *fyneApp) SetSystemTrayMenu(menu *fyne.Menu) {
  24. if desk, ok := a.Driver().(systrayDriver); ok {
  25. desk.SetSystemTrayMenu(menu)
  26. }
  27. }
  28. // SetSystemTrayIcon sets a custom image for the system tray icon.
  29. // You should have previously called `SetSystemTrayMenu` to initialise the menu icon.
  30. func (a *fyneApp) SetSystemTrayIcon(icon fyne.Resource) {
  31. a.Driver().(systrayDriver).SetSystemTrayIcon(icon)
  32. }
  33. func defaultVariant() fyne.ThemeVariant {
  34. if C.isDarkMode() {
  35. return theme.VariantDark
  36. }
  37. return theme.VariantLight
  38. }
  39. func rootConfigDir() string {
  40. homeDir, _ := os.UserHomeDir()
  41. desktopConfig := filepath.Join(filepath.Join(homeDir, "Library"), "Preferences")
  42. return filepath.Join(desktopConfig, "fyne")
  43. }
  44. func (a *fyneApp) OpenURL(url *url.URL) error {
  45. cmd := execabs.Command("open", url.String())
  46. cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
  47. return cmd.Run()
  48. }
  49. //export themeChanged
  50. func themeChanged() {
  51. fyne.CurrentApp().Settings().(*settings).setupTheme()
  52. }
  53. func watchTheme() {
  54. C.watchTheme()
  55. }