refreshed/updated data on widgets

Hello, I have a small lightweight macOS application that includes a medium widget but the widget does not update with new data as often as I'd like. I understand that in apple's WidgetKit documentation they mention that apple controls when the widget updates due to battery life concerns, but I'd like to know if theres any way at all to control when the widget updates or when I think it makes sense to do so if I am not able to control how often it refreshes new data.

https://github.com/Alexx1105/MacStat-v2.1

Looking at your code:

// Generate a timeline consisting of five entries an hour apart, starting from the current date.
let currentDate = Date()
for hourOffset in 0 ..< 5 {
    let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
    let entry = SimpleEntry(date: entryDate, configuration: configuration)
    entries.append(entry)
}

You can easily change that to update more often. You're updating once every hour for five hours. Try every 5 minutes instead.

You can create a timeline for as any entries as you want, but bear in mind that too many entries in the timeline can cause your widget to go all weird. You should be safe with about 200 entries. I noticed weird behaviour when I accidentally had 2,000 entries in there.

It's up to the OS to decide whether or not to update your widget, and I think there's a limit of something like 70 updates a day (can't remember where I saw that number).

Also, if I were you, I'd separate the UI parts from the data parts, so move your widget views into their own files, and put the intent timeline stuff into the AppIntent.swift file. (And maybe change the "This is an example widget" stuff, and cut down on the whitespace.)

Thank you that is very helpful! Yeah I am using a lot of the default code that is included with WidgetKit and didn’t even bother to check that out. I’ll definitely get rid of the excess example widget default code aswell 👍

refreshed/updated data on widgets
 
 
Q