macos_sync.go

 1package config
 2
 3import (
 4	"fmt"
 5	"runtime"
 6
 7	"github.com/floatpane/matcha/clib/macos"
 8)
 9
10// SyncMacOSContacts fetches contacts from the macOS Contacts framework
11// and merges them into the local contacts cache.
12func SyncMacOSContacts() error {
13	if runtime.GOOS != "darwin" {
14		return nil
15	}
16
17	macContacts, err := macos.FetchContacts()
18	if err != nil {
19		return fmt.Errorf("failed to fetch macOS contacts: %w", err)
20	}
21
22	for _, mc := range macContacts {
23		for _, email := range mc.Emails {
24			// AddContact handles deduplication and name updates
25			if err := AddContact(mc.Name, email); err != nil {
26				// We continue even if one fails
27				continue
28			}
29		}
30	}
31
32	return nil
33}