Skip to content

Commit

Permalink
added invalid token notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Official-Husko committed Dec 9, 2023
1 parent 4675c30 commit bfb2289
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
//go:embed icon.ico
var content embed.FS

var DEBUG = 0

// Config represents the configuration structure
type Config struct {
XFToken string `json:"_xfToken"`
Expand All @@ -32,7 +34,7 @@ type Data struct {
}

// Define a constant for the version
const version = "1.0.0" // Replace with your actual version
const version = "1.1.0" // Replace with your actual version

// main is the entry point function for the program.
//
Expand Down Expand Up @@ -159,7 +161,13 @@ func onExit() {
// The function does not return anything.
func runBackgroundProcess(config Config) {
// set up a ticker to trigger the function periodically
ticker := time.NewTicker(5 * time.Minute)
var ticker *time.Ticker
if DEBUG == 1 {
ticker = time.NewTicker(5 * time.Second)
log.Println("Debugging detected: using shorter ticker duration")
} else {
ticker = time.NewTicker(5 * time.Minute)
}
defer ticker.Stop() // stop the ticker when the function ends

for range ticker.C { // iterate over the ticker channel
Expand Down Expand Up @@ -190,6 +198,16 @@ func runBackgroundProcess(config Config) {
continue
}

// Check if "visitor" field and "total_unread" field are present
if data.Visitor.TotalUnread == "" {
log.Println("Error: 'total_unread' field is missing in the response JSON")

// Send a notification with "invalid" as title and body
title := "Outdated Session?"
body := "The server returned no data. Please update your Token and Cookie."
sendNotification(title, body)
}

totalUnread, err := data.Visitor.TotalUnread.Int64()
if err != nil {
log.Println("Error converting TotalUnread to int64:", err)
Expand Down

0 comments on commit bfb2289

Please sign in to comment.