mirror of
https://github.com/swiftbar/SwiftBar.git
synced 2024-09-11 16:05:33 +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>
|
<swiftbar.schedule>01,16,31,46 * * * *</swiftbar.schedule>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can configure multiple schedules, using the sepparator `|`:
|
||||||
|
|
||||||
|
```
|
||||||
|
<swiftbar.schedule>1 * * * *|2 * * * *</swiftbar.schedule>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Other Parameters
|
#### Other Parameters
|
||||||
|
|
||||||
* `#<swiftbar.refreshOnOpen>true</swiftbar.refreshOnOpen>` - refreshes plugin on click, before presenting the menu
|
* `#<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)
|
Timer.TimerPublisher(interval: updateInterval, runLoop: .main, mode: .default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cronTimer: Timer?
|
||||||
|
|
||||||
var cancellable: Set<AnyCancellable> = []
|
var cancellable: Set<AnyCancellable> = []
|
||||||
|
|
||||||
let prefs = PreferencesStore.shared
|
let prefs = PreferencesStore.shared
|
||||||
@ -67,11 +69,16 @@ class ExecutablePlugin: Plugin {
|
|||||||
refresh()
|
refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this function called each time plugin updated(manual or scheduled)
|
||||||
func enableTimer() {
|
func enableTimer() {
|
||||||
// handle cron scheduled plugins
|
// handle cron scheduled plugins
|
||||||
if let nextDate = metadata?.nextDate {
|
if let nextDate = metadata?.nextDate {
|
||||||
let timer = Timer(fireAt: nextDate, interval: 0, target: self, selector: #selector(scheduledContentUpdate), userInfo: nil, repeats: false)
|
print("Time: \(nextDate)")
|
||||||
RunLoop.main.add(timer, forMode: .common)
|
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
|
return
|
||||||
}
|
}
|
||||||
guard cancellable.isEmpty else { return }
|
guard cancellable.isEmpty else { return }
|
||||||
|
@ -74,8 +74,8 @@ class PluginMetadata: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var nextDate: Date? {
|
var nextDate: Date? {
|
||||||
guard let cron = try? SwifCron(schedule) else { return nil }
|
// parse schedule string and return the minimum date
|
||||||
return try? cron.next()
|
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) {
|
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