SponsorkitNag
Decides when to show a "please support this project" message.
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 SponsorkitNagExample#
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#
| Member | Description |
|---|---|
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
predicateFunc<ContributionResult, bool>(ContributionResult): Your rule, given the current contribution result (served from the cache when fresh).forcebool: Bypass the terminal,CIandSPONSORKIT_NO_NAGchecks. Optional (defaultfalse).cancellationTokenCancellationToken: Cancels the contribution lookup. Optional (defaultdefault).
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.