//go:build darwin

package main

import (
	"os"
	"os/exec"
	"strings"
)

func needsFullDiskAccess() bool {
	f, err := os.Open("/Library/Application Support/com.apple.TCC/TCC.db")
	if err == nil {
		f.Close()
	}
	return os.IsPermission(err)
}

func openFullDiskAccessSettings() {
	exec.Command("open", "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles").Start()
}

func promptFullDiskAccess() {
	out, err := exec.Command("osascript", "-e",
		`display dialog "Restray needs Full Disk Access to be able to back up all your files." buttons {"Skip", "Open Settings"} default button "Open Settings" with title "Restray" with icon caution`).Output()
	if err == nil && strings.Contains(string(out), "Open Settings") {
		openFullDiskAccessSettings()
	}
}
