SponsorkitNag

Decides when to show a "please support this project" message.

On this page

Decides when to show a "please support this project" message. Sponsorkit never shows anything itself and never signs in implicitly.

namespace Sponsorkit;

public sealed class SponsorkitNag

Example#

var nag = sk.Nag(new NagOptions("my-cli") { Every = 10, OrEvery = TimeSpan.FromDays(7) });
if (await nag.DueAsync(fc => fc.Active().Count == 0))
{
    Console.Error.WriteLine($"Enjoying my-cli? Support it: {sk.CheckoutUrl(new CheckoutUrlOptions { Frequency = Frequencies.Monthly })}");
    nag.Shown();
}

Methods#

MemberDescription
DueAsync(Func<ContributionResult, bool>, bool, CancellationToken)Counts this run (once per process per id, even when the predicate is false) and returns predicate(result) && (runs >= Every || timeSinceLastShown >= OrEvery).
Shown()Records that the nag was shown: resets the run counter and the OrEvery timer.

DueAsync(Func<ContributionResult, bool>, bool, CancellationToken)#

public Task<bool> DueAsync(Func<ContributionResult, bool> predicate, bool force = false, CancellationToken cancellationToken = default)

Counts this run (once per process per id, even when the predicate is false) and returns predicate(result) && (runs >= Every \|\| timeSinceLastShown >= OrEvery).

Parameters

  • predicate Func<ContributionResult, bool> (ContributionResult): Your rule, given the current contribution result (served from the cache when fresh).
  • force bool: Bypass the terminal, CI and SPONSORKIT_NO_NAG checks. Optional (default false).
  • cancellationToken CancellationToken: Cancels the contribution lookup. Optional (default default).

Returns Task<bool>: Whether to show the nag now.

Always false when SPONSORKIT_DISABLE is set. Unless force is true, also false when SPONSORKIT_NO_NAG or CI is set, or when stdout or stderr is not a terminal.

Shown()#

public void Shown()

Records that the nag was shown: resets the run counter and the OrEvery timer.