Fixing swiftbar.environment not available #214

This commit is contained in:
Alex Mazanov 2021-07-31 11:35:30 -04:00
parent d965521b82
commit e5403402aa
3 changed files with 14 additions and 7 deletions

View File

@ -211,7 +211,7 @@ A special tag can be used as an alternative to refresh interval defined in plugi
* `<swiftbar.runInBash>false</swiftbar.runInBash>` - doesn't wrap plugins in Bash when running * `<swiftbar.runInBash>false</swiftbar.runInBash>` - doesn't wrap plugins in Bash when running
* `<swiftbar.type>streamable</swiftbar.type>` - mark plugin as Streamable * `<swiftbar.type>streamable</swiftbar.type>` - mark plugin as Streamable
* `<swiftbar.environment>['var1':'default value', 'var2':'default value', ... ]</swiftbar.environment>` - this variables will be passed in plugin's environment, in later release SwiftBar will provide a UI to change values for these variables. * `<swiftbar.environment>[var1:default value, var2:default value, ... ]</swiftbar.environment>` - this variables will be passed in plugin's environment, in later release SwiftBar will provide a UI to change values for these variables.
#### Metadata for Binary Plugins #### Metadata for Binary Plugins

View File

@ -100,11 +100,15 @@ extension Plugin {
} }
var env: [String: String] { var env: [String: String] {
[ var pluginEnv = [
EnvironmentVariables.swiftBarPluginPath.rawValue: file, EnvironmentVariables.swiftBarPluginPath.rawValue: file,
EnvironmentVariables.osAppearance.rawValue: AppShared.isDarkTheme ? "Dark" : "Light", EnvironmentVariables.osAppearance.rawValue: AppShared.isDarkTheme ? "Dark" : "Light",
EnvironmentVariables.swiftBarPluginCachePath.rawValue: cacheDirectoryPath, EnvironmentVariables.swiftBarPluginCachePath.rawValue: cacheDirectoryPath,
EnvironmentVariables.swiftBarPluginDataPath.rawValue: dataDirectoryPath, EnvironmentVariables.swiftBarPluginDataPath.rawValue: dataDirectoryPath,
] ]
metadata?.environment.forEach { k, v in
pluginEnv[k] = v
}
return pluginEnv
} }
} }

View File

@ -122,11 +122,14 @@ class PluginMetadata: ObservableObject {
} }
var environment: [String: String] = [:] var environment: [String: String] = [:]
if !getTagValue(tag: .environment).isEmpty { if !getTagValue(tag: .environment).isEmpty {
getTagValue(tag: .environment).split(separator: ",").forEach { str in getTagValue(tag: .environment)
let pair = str.split(separator: ":").map { $0.trimmingCharacters(in: .whitespaces) } .dropFirst()
guard pair.count == 2 else { return } .dropLast()
environment[pair[0]] = pair[1] .split(separator: ",").forEach { str in
} let pair = str.split(separator: ":").map { $0.trimmingCharacters(in: .whitespaces) }
guard pair.count == 2 else { return }
environment[pair[0]] = pair[1]
}
} }
return PluginMetadata(name: getTagValue(tag: .title), return PluginMetadata(name: getTagValue(tag: .title),