Skip to content

Commit

Permalink
Refactor for cleaner use of constants #274
Browse files Browse the repository at this point in the history
  • Loading branch information
melonamin committed Feb 4, 2022
1 parent b35957d commit 7c517e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions SwiftBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
func userNotificationCenter(_: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let payload = response.notification.request.content.userInfo

guard let pluginID = payload[SystemNotificationName.pluginID.rawValue] as? String,
guard let pluginID = payload[SystemNotificationName.pluginID] as? String,
let plugin = pluginManager.plugins.first(where: { $0.id == pluginID }),
plugin.enabled else { return }

if let urlString = payload[SystemNotificationName.url.rawValue] as? String,
if let urlString = payload[SystemNotificationName.url] as? String,
let url = URL(string: urlString)
{
NSWorkspace.shared.open(url)
}

if let commandString = payload[SystemNotificationName.command.rawValue] as? String,
if let commandString = payload[SystemNotificationName.command] as? String,
let json = commandString.data(using: .utf8), let params = MenuLineParameters(json: json),
let bash = params.bash
{
Expand Down
6 changes: 3 additions & 3 deletions SwiftBar/Plugin/PluginManger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,16 @@ extension PluginManager {
content.sound = silent ? nil : .default
content.threadIdentifier = pluginID

content.userInfo[SystemNotificationName.pluginID.rawValue] = pluginID
content.userInfo[SystemNotificationName.pluginID] = pluginID

if let urlString = href,
let url = URL(string: urlString), url.host != nil, url.scheme != nil
{
content.userInfo[SystemNotificationName.url.rawValue] = urlString
content.userInfo[SystemNotificationName.url] = urlString
}

if let commandParams = commandParams {
content.userInfo[SystemNotificationName.command.rawValue] = commandParams
content.userInfo[SystemNotificationName.command] = commandParams
}

let uuidString = UUID().uuidString
Expand Down
8 changes: 4 additions & 4 deletions SwiftBar/Utility/SystemNotificationName.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

enum SystemNotificationName: String {
case url
case command
case pluginID
struct SystemNotificationName {
public static let url = "url"
public static let command = "command"
public static let pluginID = "pluginID"
}

0 comments on commit 7c517e0

Please sign in to comment.