|
| 1 | +# DarwinKit Development Notes |
| 2 | + |
| 3 | +## Useful Commands |
| 4 | + |
| 5 | +### Build & Test |
| 6 | +```bash |
| 7 | +# Build the entire project |
| 8 | +go build ./... |
| 9 | + |
| 10 | +# Run tests |
| 11 | +go test ./... |
| 12 | + |
| 13 | +# Run specific tests |
| 14 | +go test ./macos/appkit |
| 15 | +``` |
| 16 | + |
| 17 | +### Example Applications |
| 18 | +```bash |
| 19 | +# Run the screenshot example |
| 20 | +cd macos/_examples/screenshot && go run main.go |
| 21 | + |
| 22 | +# Run the webview example |
| 23 | +cd macos/_examples/webview && go run main.go |
| 24 | +``` |
| 25 | + |
| 26 | +## Framework Information |
| 27 | + |
| 28 | +### ScreenCaptureKit |
| 29 | +The ScreenCaptureKit implementation supports taking screenshots with robust TCC permission handling: |
| 30 | + |
| 31 | +```go |
| 32 | +// Basic screenshot |
| 33 | +manager := screencapturekit.SCScreenshotManager_SharedManager() |
| 34 | +manager.CaptureScreenshotWithCompletion(func(image appkit.Image, err screencapturekit.SCError) { |
| 35 | + // Process image or handle error |
| 36 | +}) |
| 37 | + |
| 38 | +// With retry for TCC permission issues |
| 39 | +manager.CaptureScreenshotWithRetry(3, time.Second, func(image appkit.Image, err screencapturekit.SCError, success bool) { |
| 40 | + // Handle result with automatic retry for permission issues |
| 41 | +}) |
| 42 | +``` |
| 43 | + |
| 44 | +When using ScreenCaptureKit, be aware that: |
| 45 | +1. Users must grant screen recording permission via System Preferences |
| 46 | +2. Permission issues are common and should be handled gracefully |
| 47 | +3. The application may need to be restarted after permission is granted |
| 48 | + |
| 49 | +### Naming Patterns |
| 50 | +- Class method calls: `ClassName_MethodName()` |
| 51 | +- Instance methods: `instance.MethodName()` |
| 52 | +- Create objects: `ClassName_New()` or similar constructor patterns |
| 53 | + |
| 54 | +## Code Style Preferences |
| 55 | + |
| 56 | +### Imports |
| 57 | +Order imports as follows: |
| 58 | +1. Standard library imports |
| 59 | +2. External library imports |
| 60 | +3. DarwinKit imports, with `objc` last |
| 61 | + |
| 62 | +```go |
| 63 | +import ( |
| 64 | + "fmt" |
| 65 | + "os" |
| 66 | + |
| 67 | + "github.com/progrium/darwinkit/macos/appkit" |
| 68 | + "github.com/progrium/darwinkit/macos/foundation" |
| 69 | + "github.com/progrium/darwinkit/objc" |
| 70 | +) |
| 71 | +``` |
| 72 | + |
| 73 | +### Error Handling |
| 74 | +For Objective-C errors: |
| 75 | +- Check `IsNil()` on error objects before using them |
| 76 | +- Use descriptive error messages when possible |
| 77 | +- Implement the `Error()` interface on custom error types |
| 78 | + |
| 79 | +## Memory Management |
| 80 | +Remember to handle memory appropriately: |
| 81 | +- Use `objc.CreateMallocBlock` for callbacks |
| 82 | +- Check for `nil` objects before accessing them |
| 83 | +- Be aware of ownership rules when working with Objective-C objects |
0 commit comments