Skip to content

Commit

Permalink
refresh URL Scheme pass parameters as ENV variables to plugin #369
Browse files Browse the repository at this point in the history
  • Loading branch information
melonamin committed Apr 22, 2023
1 parent 6e5d16b commit ce8b27f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions SwiftBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
case "refreshplugin":
if let plugin = getPluginFromURL(url: url) {
pluginManager.menuBarItems[plugin.id]?.dimOnManualRefresh()
if let params = url.queryParameters {
plugin.refreshEnv = params.filter { $0.key != "name" }
}
plugin.refresh(reason: .URLScheme)
return
}
Expand Down
1 change: 1 addition & 0 deletions SwiftBar/Plugin/EphemeralPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class EphemeralPlugin: Plugin {
let type: PluginType = .Ephemeral
let name: String = "Ephemeral"
let file: String = "none"
var refreshEnv: [String: String] = [:]

var updateInterval: Double = 60 * 60 * 24 * 100 {
didSet {
Expand Down
1 change: 1 addition & 0 deletions SwiftBar/Plugin/ExecutablePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ExecutablePlugin: Plugin {
let type: PluginType = .Executable
let name: String
let file: String
var refreshEnv: [String: String] = [:]

var updateInterval: Double = 60 * 60 * 24 * 100 // defaults to "never", for NOT timed scripts
var metadata: PluginMetadata?
Expand Down
6 changes: 6 additions & 0 deletions SwiftBar/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protocol Plugin: AnyObject {
var content: String? { get set }
var error: Error? { get set }
var debugInfo: PluginDebugInfo { get set }
var refreshEnv: [String: String] { get set }
func refresh(reason: PluginRefreshReason)
func enable()
func disable()
Expand Down Expand Up @@ -151,6 +152,11 @@ extension Plugin {
metadata?.environment.forEach { k, v in
pluginEnv[k] = v
}

refreshEnv.forEach { k, v in
pluginEnv[k] = v
}
refreshEnv.removeAll()
return pluginEnv
}
}
1 change: 1 addition & 0 deletions SwiftBar/Plugin/ShortcutPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ShortcutPlugin: Plugin, Identifiable, ObservableObject {
var shortcut: String
var repeatString: String
var cronString: String
var refreshEnv: [String: String] = [:]
@Published var enabled: Bool = true
var operation: RunPluginOperation<ShortcutPlugin>?

Expand Down
1 change: 1 addition & 0 deletions SwiftBar/Plugin/StreamablePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class StreamablePlugin: Plugin {
let type: PluginType = .Streamable
let name: String
let file: String
var refreshEnv: [String: String] = [:]

var metadata: PluginMetadata?
var lastUpdated: Date?
Expand Down

0 comments on commit ce8b27f

Please sign in to comment.