app_desktop_darwin.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. "fyne.io/fyne/v2"
  18. "fyne.io/fyne/v2/theme"
  19. )
  20. // SetSystemTrayMenu creates a system tray item and attaches the specified menu.
  21. // By default this will use the application icon.
  22. func (a *fyneApp) SetSystemTrayMenu(menu *fyne.Menu) {
  23. if desk, ok := a.Driver().(systrayDriver); ok {
  24. desk.SetSystemTrayMenu(menu)
  25. }
  26. }
  27. // SetSystemTrayIcon sets a custom image for the system tray icon.
  28. // You should have previously called `SetSystemTrayMenu` to initialise the menu icon.
  29. func (a *fyneApp) SetSystemTrayIcon(icon fyne.Resource) {
  30. a.Driver().(systrayDriver).SetSystemTrayIcon(icon)
  31. }
  32. func defaultVariant() fyne.ThemeVariant {
  33. if C.isDarkMode() {
  34. return theme.VariantDark
  35. }
  36. return theme.VariantLight
  37. }
  38. func rootConfigDir() string {
  39. homeDir, _ := os.UserHomeDir()
  40. desktopConfig := filepath.Join(filepath.Join(homeDir, "Library"), "Preferences")
  41. return filepath.Join(desktopConfig, "fyne")
  42. }
  43. func (a *fyneApp) OpenURL(url *url.URL) error {
  44. cmd := a.exec("open", url.String())
  45. cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
  46. return cmd.Run()
  47. }
  48. //export themeChanged
  49. func themeChanged() {
  50. fyne.CurrentApp().Settings().(*settings).setupTheme()
  51. }
  52. func watchTheme() {
  53. C.watchTheme()
  54. }