mirror of
https://github.com/swiftbar/SwiftBar.git
synced 2024-08-17 12:00:27 +03:00
Add support for multiple cron schedules
This commit is contained in:
parent
1cef69ab84
commit
152fef23dd
@ -212,6 +212,13 @@ A special tag can be used as an alternative to refresh interval defined in plugi
|
||||
<swiftbar.schedule>01,16,31,46 * * * *</swiftbar.schedule>
|
||||
```
|
||||
|
||||
You can configure multiple schedules, using the sepparator `|`:
|
||||
|
||||
```
|
||||
<swiftbar.schedule>1 * * * *|2 * * * *</swiftbar.schedule>
|
||||
```
|
||||
|
||||
|
||||
#### Other Parameters
|
||||
|
||||
* `#<swiftbar.refreshOnOpen>true</swiftbar.refreshOnOpen>` - refreshes plugin on click, before presenting the menu
|
||||
|
@ -30,6 +30,8 @@ class ExecutablePlugin: Plugin {
|
||||
Timer.TimerPublisher(interval: updateInterval, runLoop: .main, mode: .default)
|
||||
}
|
||||
|
||||
var cronTimer: Timer?
|
||||
|
||||
var cancellable: Set<AnyCancellable> = []
|
||||
|
||||
let prefs = PreferencesStore.shared
|
||||
@ -67,11 +69,16 @@ class ExecutablePlugin: Plugin {
|
||||
refresh()
|
||||
}
|
||||
|
||||
// this function called each time plugin updated(manual or scheduled)
|
||||
func enableTimer() {
|
||||
// handle cron scheduled plugins
|
||||
if let nextDate = metadata?.nextDate {
|
||||
let timer = Timer(fireAt: nextDate, interval: 0, target: self, selector: #selector(scheduledContentUpdate), userInfo: nil, repeats: false)
|
||||
RunLoop.main.add(timer, forMode: .common)
|
||||
print("Time: \(nextDate)")
|
||||
cronTimer?.invalidate()
|
||||
cronTimer = Timer(fireAt: nextDate, interval: 0, target: self, selector: #selector(scheduledContentUpdate), userInfo: nil, repeats: false)
|
||||
if let cronTimer {
|
||||
RunLoop.main.add(cronTimer, forMode: .common)
|
||||
}
|
||||
return
|
||||
}
|
||||
guard cancellable.isEmpty else { return }
|
||||
|
@ -74,8 +74,8 @@ class PluginMetadata: ObservableObject {
|
||||
}
|
||||
|
||||
var nextDate: Date? {
|
||||
guard let cron = try? SwifCron(schedule) else { return nil }
|
||||
return try? cron.next()
|
||||
// parse schedule string and return the minimum date
|
||||
schedule.components(separatedBy: "|").compactMap { try? SwifCron($0).next() }.reduce(Date.distantFuture, min)
|
||||
}
|
||||
|
||||
init(name: String = "", version: String = "", author: String = "", github: String = "", desc: String = "", previewImageURL: URL? = nil, dependencies: [String] = [], aboutURL: URL? = nil, dropTypes: [String] = [], schedule: String = "", type: PluginType = .Executable, hideAbout: Bool = false, hideRunInTerminal: Bool = false, hideLastUpdated: Bool = false, hideDisablePlugin: Bool = false, hideSwiftBar: Bool = false, environment: [String: String] = [:], runInBash: Bool = true, refreshOnOpen: Bool = false, useTrailingStreamSeparator: Bool = false) {
|
||||
|
Loading…
Reference in New Issue
Block a user