app_darwin.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. // #cgo CFLAGS: -x objective-c -Wno-deprecated-declarations
  3. // #cgo LDFLAGS: -framework Cocoa -framework LocalAuthentication
  4. // #include "app_darwin.h"
  5. import "C"
  6. import (
  7. "context"
  8. "fmt"
  9. "log/slog"
  10. "os"
  11. "path/filepath"
  12. "syscall"
  13. )
  14. func init() {
  15. home, err := os.UserHomeDir()
  16. if err != nil {
  17. panic(err)
  18. }
  19. ServerLogFile = filepath.Join(home, ".ollama", "logs", "server.log")
  20. }
  21. func run() {
  22. initLogging()
  23. slog.Info("ollama macOS app started")
  24. C.killOtherInstances()
  25. exe, err := os.Executable()
  26. if err != nil {
  27. panic(err)
  28. }
  29. resources := filepath.Join(filepath.Dir(exe), "..", "Resources")
  30. ctx, cancel := context.WithCancel(context.Background())
  31. var done chan int
  32. done, err = SpawnServer(ctx, filepath.Join(resources, "ollama"))
  33. if err != nil {
  34. slog.Error(fmt.Sprintf("Failed to spawn ollama server %s", err))
  35. done = make(chan int, 1)
  36. done <- 1
  37. }
  38. // Run the native app
  39. C.run()
  40. cancel()
  41. slog.Info("Waiting for ollama server to shutdown...")
  42. if done != nil {
  43. <-done
  44. }
  45. slog.Info("Ollama app exiting")
  46. }
  47. //export Quit
  48. func Quit() {
  49. syscall.Kill(os.Getpid(), syscall.SIGTERM)
  50. }