summaryrefslogtreecommitdiff
path: root/pkg/backend/donate.go
blob: 98f9e6ba3767dfea3f21ada7a6c861e324484693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package backend

import (
	"time"
)

// runDonationReminder checks every six hours if we need to show the reminder,
// and trigger the launching of the dialog if needed.
func runDonationReminder() {
	go func() {
		for {
			time.Sleep(time.Hour * 6)
			if needsDonationReminder() {
				showDonate()
			}
		}
	}()
	// to test manually, uncomment this line.
	// time.AfterFunc(1*time.Minute, func() { showDonate() })
}

func needsDonationReminder() bool {
	return ctx.cfg.NeedsDonationReminder()
}

/* to be called from the gui, the visibility toggle will be updated on the next
   status change */
func donateSeen() {
	statusMutex.Lock()
	defer statusMutex.Unlock()
	ctx.DonateDialog = false
}

func donateAccepted() {
	statusMutex.Lock()
	defer statusMutex.Unlock()
	ctx.DonateDialog = false
	ctx.cfg.SetDonated()
	go trigger(OnStatusChanged)
}

func showDonate() {
	statusMutex.Lock()
	defer statusMutex.Unlock()
	ctx.DonateDialog = true
	ctx.cfg.SetLastReminded()
	go trigger(OnStatusChanged)
}