Skip to content

Commit

Permalink
input source command lines takes target source as extra arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed May 19, 2024
1 parent 5c4f85a commit 346394b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
13 changes: 7 additions & 6 deletions sources/InputSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import InputMethodKit

final class SquirrelInstaller {
enum InputMode: String, CaseIterable {
static let primary = Self.hant
static let primary = Self.hans
case hans = "im.rime.inputmethod.Squirrel.Hans"
case hant = "im.rime.inputmethod.Squirrel.Hant"
}
Expand Down Expand Up @@ -42,8 +42,8 @@ final class SquirrelInstaller {

func register() {
let enabledInputModes = enabledModes()
if enabledInputModes.count > 0 {
print("User already registered Squirrel method(s): \(enabledInputModes)")
if !enabledInputModes.isEmpty {
print("User already registered Squirrel method(s): \(enabledInputModes.map { $0.rawValue })")
// Already registered.
return
}
Expand All @@ -53,8 +53,8 @@ final class SquirrelInstaller {

func enable(modes: [InputMode] = [.primary]) {
let enabledInputModes = enabledModes()
if Set(modes).isSubset(of: enabledInputModes) {
print("User already enabled Squirrel method(s): \(enabledInputModes)")
if !enabledInputModes.isEmpty {
print("User already enabled Squirrel method(s): \(enabledInputModes.map { $0.rawValue })")
// keep user's manually enabled input modes.
return
}
Expand All @@ -69,7 +69,8 @@ final class SquirrelInstaller {
func select(mode: InputMode = .primary) {
let enabledInputModes = enabledModes()
if !enabledInputModes.contains(mode) {
enable(modes: [mode])
print("Target not enabled yet: \(mode.rawValue)")
return
}
for (mode, inputSource) in getInputSource(modes: [mode]) {
if let enabled = getBool(for: inputSource, key: kTISPropertyInputSourceIsEnabled),
Expand Down
20 changes: 19 additions & 1 deletion sources/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,31 @@ struct SquirrelApp {
installer.register()
return true
case "--enable-input-source":
if args.count > 2 {
let modes = args[2...].map { SquirrelInstaller.InputMode(rawValue: $0) }.compactMap { $0 }
if !modes.isEmpty {
installer.enable(modes: modes)
return true
}
}
installer.enable()
return true
case "--disable-input-source":
if args.count > 2 {
let modes = args[2...].map { SquirrelInstaller.InputMode(rawValue: $0) }.compactMap { $0 }
if !modes.isEmpty {
installer.disable(modes: modes)
return true
}
}
installer.disable()
return true
case "--select-input-source":
installer.select()
if args.count > 2, let mode = SquirrelInstaller.InputMode(rawValue: args[2]) {
installer.select(mode: mode)
} else {
installer.select()
}
return true
case "--build":
// Notification
Expand Down

0 comments on commit 346394b

Please sign in to comment.