-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for reading configuration from home directory
- Loading branch information
Showing
15 changed files
with
222 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
struct AllConfiguration: Codable { | ||
var send: SendConfig? | ||
var mousePosition: MousePositionConfig? | ||
var transformer: TransformerConfig? | ||
|
||
init(send: SendConfig? = nil, mousePosition: MousePositionConfig? = nil, transformer: TransformerConfig? = nil) { | ||
self.send = send | ||
self.mousePosition = mousePosition | ||
self.transformer = transformer | ||
} | ||
|
||
func merge(with other: AllConfiguration?) -> AllConfiguration { | ||
return AllConfiguration( | ||
send: other?.send?.merge(with: self.send) ?? self.send, | ||
mousePosition: other?.mousePosition?.merge(with: self.mousePosition) ?? self.mousePosition, | ||
transformer: other?.transformer?.merge(with: self.transformer) ?? self.transformer | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
import Yams | ||
|
||
struct ConfigLoader { | ||
static func loadConfig() -> AllConfiguration { | ||
let defaultConfigFiles = [ | ||
NSString("~/.sendkeysrc.yml").expandingTildeInPath, NSString("~/.sendkeysrc.yaml").expandingTildeInPath, | ||
] | ||
|
||
for configFile in defaultConfigFiles { | ||
if FileManager.default.fileExists(atPath: configFile) { | ||
if let contents = FileManager.default.contents(atPath: configFile) { | ||
do { | ||
let decoder = YAMLDecoder() | ||
return try decoder.decode(AllConfiguration.self, from: contents) | ||
} catch { | ||
print("Unable to read \(configFile): \(error)") | ||
} | ||
} | ||
} | ||
} | ||
|
||
return AllConfiguration() | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Sources/SendKeysLib/Configuration/MousePositionConfig.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
struct MousePositionConfig: Codable { | ||
var watch: Bool? | ||
var output: OutputMode? | ||
var duration: Double? | ||
|
||
init(watch: Bool? = nil, output: OutputMode? = nil, duration: Double? = nil) { | ||
self.watch = watch | ||
self.output = output | ||
self.duration = duration | ||
} | ||
|
||
func merge(with other: MousePositionConfig?) -> MousePositionConfig { | ||
return MousePositionConfig( | ||
watch: other?.watch ?? self.watch, | ||
output: other?.output ?? self.output, | ||
duration: other?.duration ?? self.duration | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
struct SendConfig: Codable { | ||
var activate: Bool? | ||
var animationInterval: Double? | ||
var delay: Double? | ||
var initialDelay: Double? | ||
var keyboardLayout: KeyMappings.Layouts? | ||
var targeted: Bool? | ||
var terminateCommand: String? | ||
|
||
init( | ||
activate: Bool? = nil, animationInterval: Double? = nil, delay: Double? = nil, initialDelay: Double? = nil, | ||
keyboardLayout: KeyMappings.Layouts? = nil, targeted: Bool? = nil, terminateCommand: String? = nil | ||
) { | ||
self.activate = activate | ||
self.animationInterval = animationInterval | ||
self.delay = delay | ||
self.initialDelay = initialDelay | ||
self.keyboardLayout = keyboardLayout | ||
self.targeted = targeted | ||
self.terminateCommand = terminateCommand | ||
} | ||
|
||
func merge(with other: SendConfig?) -> SendConfig { | ||
return SendConfig( | ||
activate: other?.activate ?? self.activate, | ||
animationInterval: other?.animationInterval ?? self.animationInterval, | ||
delay: other?.delay ?? self.delay, | ||
initialDelay: other?.initialDelay ?? self.initialDelay, | ||
keyboardLayout: other?.keyboardLayout ?? self.keyboardLayout, | ||
targeted: other?.targeted ?? self.targeted, | ||
terminateCommand: other?.terminateCommand ?? self.terminateCommand | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
struct TransformerConfig: Codable { | ||
var indent: Bool? | ||
var autoClose: String? | ||
|
||
init(indent: Bool? = nil, autoClose: String? = nil) { | ||
self.indent = indent | ||
self.autoClose = autoClose | ||
} | ||
|
||
func merge(with other: TransformerConfig?) -> TransformerConfig { | ||
return TransformerConfig( | ||
indent: other?.indent ?? self.indent, | ||
autoClose: other?.autoClose ?? self.autoClose | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.