Add plugin refresh reason to ENV #404

Signed-off-by: Alex Mazanov <alexandr.mazanov@gmail.com>
This commit is contained in:
Alex Mazanov 2024-01-04 13:55:25 -05:00
parent 3e93034c49
commit 28ef89ff82
No known key found for this signature in database
GPG Key ID: FD35C3C7C1D34AB4
4 changed files with 7 additions and 1 deletions

View File

@ -176,6 +176,7 @@ When running a plugin, SwiftBar sets the following environment variables:
| `SWIFTBAR_PLUGIN_PATH` | The path to the running plugin |
| `SWIFTBAR_PLUGIN_CACHE_PATH` | The cache to data folder, individual per plugin |
| `SWIFTBAR_PLUGIN_DATA_PATH` | The path to data folder, individual per plugin |
| `SWIFTBAR_PLUGIN_REFRESH_REASON` | Plugin refresh reason\trigger |
| `SWIFTBAR_LAUNCH_TIME` | SwiftBar launch date and time, ISO8601 |
| `OS_APPEARANCE` | Current macOS appearance (`Light` or `Dark`) |
| `OS_VERSION_MAJOR` | The first part of the macOS version (e.g., `11` for macOS 11.0.1) |

View File

@ -702,6 +702,7 @@ extension MenubarItem {
func refreshAndShowMenu() {
os_log("Refreshing for refreshOnOpen plugin", log: Log.plugin, type: .info)
plugin?.lastRefreshReason = .MenuOpen
let content = plugin?.invoke()
_updateMenu(content: content)
barItem.menu = statusBarMenu

View File

@ -29,7 +29,7 @@ enum PluginState {
case Disabled
}
enum PluginRefreshReason {
enum PluginRefreshReason: String {
case FirstLaunch
case Schedule
case MenuAction
@ -40,6 +40,7 @@ enum PluginRefreshReason {
case DebugView
case NotificationAction
case PluginSettings
case MenuOpen
static func manualReasons() -> [Self] {
[
@ -51,6 +52,7 @@ enum PluginRefreshReason {
.NotificationAction,
.PluginSettings,
.DebugView,
.MenuOpen,
]
}
}
@ -148,6 +150,7 @@ extension Plugin {
Environment.Variables.osAppearance.rawValue: AppShared.isDarkTheme ? "Dark" : "Light",
Environment.Variables.swiftBarPluginCachePath.rawValue: cacheDirectoryPath,
Environment.Variables.swiftBarPluginDataPath.rawValue: dataDirectoryPath,
Environment.Variables.swiftBarPluginRefreshReason.rawValue: lastRefreshReason.rawValue,
]
metadata?.environment.forEach { k, v in
pluginEnv[k] = v

View File

@ -11,6 +11,7 @@ class Environment {
case swiftBarPluginPath = "SWIFTBAR_PLUGIN_PATH"
case swiftBarPluginCachePath = "SWIFTBAR_PLUGIN_CACHE_PATH"
case swiftBarPluginDataPath = "SWIFTBAR_PLUGIN_DATA_PATH"
case swiftBarPluginRefreshReason = "SWIFTBAR_PLUGIN_REFRESH_REASON"
case swiftBarLaunchTime = "SWIFTBAR_LAUNCH_TIME"
case osVersionMajor = "OS_VERSION_MAJOR"
case osVersionMinor = "OS_VERSION_MINOR"