cask "radio-silence" do
  version "3.0"
  sha256 "fbd864e3a2d17dbfe17ab29b97f6a7c38eea20cd2dbde1b28c5b67db1e7d33ad"

  url "https://radiosilenceapp.com/downloads/Radio_Silence_#{version}.pkg"
  name "Radio Silence"
  desc "Network monitor and firewall"
  homepage "https://radiosilenceapp.com/"

  livecheck do
    url "https://radiosilenceapp.com/update"
    strategy :page_match
    regex(%r{href=.*?/Radio_Silence_(\d+(?:\.\d+)*)\.pkg}i)
  end

  pkg "Radio_Silence_#{version}.pkg"

  # We intentionally unload the kext twice as a workaround
  # See https://github.com/Homebrew/homebrew-cask/pull/1802#issuecomment-34171151

  uninstall early_script: {
    executable:   "/sbin/kextunload",
    args:         ["-b", "com.radiosilenceapp.nke.filter"],
    must_succeed: false,
  },
            quit:         "com.radiosilenceapp.client",
            kext:         "com.radiosilenceapp.nke.filter",
            pkgutil:      "com.radiosilenceapp.*",
            launchctl:    [
              "com.radiosilenceapp.trial",
              "com.radiosilenceapp.agent",
              "com.radiosilenceapp.nke",
            ]

  zap trash: "~/Library/Application Support/Radio Silence"
end
