mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
commit
8513ed0fa3
@ -83,7 +83,7 @@ class SupportedTypesHolder {
|
|||||||
return (item: .weather(interval: interval ?? 1800.00, units: units ?? "metric", api_key: api_key ?? "32c4256d09a4c52b38aecddba7a078f6", icon_type: icon_type ?? "text"), action: action, parameters: [:])
|
return (item: .weather(interval: interval ?? 1800.00, units: units ?? "metric", api_key: api_key ?? "32c4256d09a4c52b38aecddba7a078f6", icon_type: icon_type ?? "text"), action: action, parameters: [:])
|
||||||
},
|
},
|
||||||
"currency": { decoder in
|
"currency": { decoder in
|
||||||
enum CodingKeys: String, CodingKey { case refreshInterval; case from; case to; case action }
|
enum CodingKeys: String, CodingKey { case refreshInterval; case from; case to }
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval)
|
||||||
let from = try container.decodeIfPresent(String.self, forKey: .from)
|
let from = try container.decodeIfPresent(String.self, forKey: .from)
|
||||||
@ -167,6 +167,7 @@ enum ItemType: Decodable {
|
|||||||
case icon_type
|
case icon_type
|
||||||
case formatTemplate
|
case formatTemplate
|
||||||
case image
|
case image
|
||||||
|
case url
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ItemTypeRaw: String, Decodable {
|
enum ItemTypeRaw: String, Decodable {
|
||||||
@ -223,6 +224,7 @@ enum ActionType: Decodable {
|
|||||||
case appleSctipt(source: SourceProtocol)
|
case appleSctipt(source: SourceProtocol)
|
||||||
case shellScript(executable: String, parameters: [String])
|
case shellScript(executable: String, parameters: [String])
|
||||||
case custom(closure: ()->())
|
case custom(closure: ()->())
|
||||||
|
case openUrl(url: String)
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case action
|
case action
|
||||||
@ -230,6 +232,7 @@ enum ActionType: Decodable {
|
|||||||
case actionAppleScript
|
case actionAppleScript
|
||||||
case executablePath
|
case executablePath
|
||||||
case shellArguments
|
case shellArguments
|
||||||
|
case url
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum ActionTypeRaw: String, Decodable {
|
private enum ActionTypeRaw: String, Decodable {
|
||||||
@ -237,6 +240,7 @@ enum ActionType: Decodable {
|
|||||||
case keyPress
|
case keyPress
|
||||||
case appleScript
|
case appleScript
|
||||||
case shellScript
|
case shellScript
|
||||||
|
case openUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
@ -256,6 +260,9 @@ enum ActionType: Decodable {
|
|||||||
let executable = try container.decode(String.self, forKey: .executablePath)
|
let executable = try container.decode(String.self, forKey: .executablePath)
|
||||||
let parameters = try container.decodeIfPresent([String].self, forKey: .shellArguments) ?? []
|
let parameters = try container.decodeIfPresent([String].self, forKey: .shellArguments) ?? []
|
||||||
self = .shellScript(executable: executable, parameters: parameters)
|
self = .shellScript(executable: executable, parameters: parameters)
|
||||||
|
case .some(.openUrl):
|
||||||
|
let url = try container.decode(String.self, forKey: .url)
|
||||||
|
self = .openUrl(url: url)
|
||||||
case .none:
|
case .none:
|
||||||
self = .none
|
self = .none
|
||||||
}
|
}
|
||||||
@ -287,6 +294,8 @@ func ==(lhs: ActionType, rhs: ActionType) -> Bool {
|
|||||||
return a == b
|
return a == b
|
||||||
case let (.shellScript(a, b), .shellScript(c, d)):
|
case let (.shellScript(a, b), .shellScript(c, d)):
|
||||||
return a == c && b == d
|
return a == c && b == d
|
||||||
|
case let (.openUrl(a), .openUrl(b)):
|
||||||
|
return a == b
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -222,6 +222,14 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
task.arguments = parameters
|
task.arguments = parameters
|
||||||
task.launch()
|
task.launch()
|
||||||
}
|
}
|
||||||
|
case .openUrl(url: let url):
|
||||||
|
return {
|
||||||
|
if let url = URL(string: url), NSWorkspace.shared.open(url) {
|
||||||
|
// print("URL was successfully opened")
|
||||||
|
} else {
|
||||||
|
print("error", url)
|
||||||
|
}
|
||||||
|
}
|
||||||
case .custom(closure: let closure):
|
case .custom(closure: let closure):
|
||||||
return closure
|
return closure
|
||||||
case .none:
|
case .none:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user