Skip to content

Commit

Permalink
refactor: separate LanguageCheckStrategy another file
Browse files Browse the repository at this point in the history
  • Loading branch information
lauvsong committed Feb 3, 2024
1 parent 33ece34 commit f5ad7a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.lauvsong.langcursor.core

import com.github.lauvsong.langcursor.utils.WindowsLanguageUtil
import com.jcraft.jsch.agentproxy.connector.PageantConnector
import java.awt.im.InputContext
import java.util.*

fun interface LanguageCheckStrategy {
fun isEnglishInput(): Boolean
}

val defaultLanguageCheckStrategy = LanguageCheckStrategy {
val locale = InputContext.getInstance().locale
val language = locale.language
val country = locale.country

language == Locale.ENGLISH.language
|| country == Locale.US.country
|| country == Locale.UK.country
}

val windowsLanguageCheckStrategy = LanguageCheckStrategy {
PageantConnector.User32.INSTANCE.GetForegroundWindow()
?.let { hwnd ->
WindowsLanguageUtil.INSTANCE.isEnglish(hwnd.pointer)
} ?: false
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.github.lauvsong.langcursor.services

import com.github.lauvsong.langcursor.utils.LanguageUtil
import com.jcraft.jsch.agentproxy.connector.PageantConnector.User32
import com.github.lauvsong.langcursor.core.LanguageCheckStrategy
import com.github.lauvsong.langcursor.core.defaultLanguageCheckStrategy
import com.github.lauvsong.langcursor.core.windowsLanguageCheckStrategy
import org.apache.commons.lang3.SystemUtils
import java.awt.im.InputContext
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -46,25 +45,4 @@ object LanguageCheckService {
} else {
defaultLanguageCheckStrategy
}
}

fun interface LanguageCheckStrategy {
fun isEnglishInput(): Boolean
}

val defaultLanguageCheckStrategy = LanguageCheckStrategy {
val locale = InputContext.getInstance().locale
val language = locale.language
val country = locale.country

language == Locale.ENGLISH.language
|| country == Locale.US.country
|| country == Locale.UK.country
}

val windowsLanguageCheckStrategy = LanguageCheckStrategy {
User32.INSTANCE.GetForegroundWindow()
?.let { hwnd ->
LanguageUtil.INSTANCE.isEnglish(hwnd.pointer)
} ?: false
}

0 comments on commit f5ad7a4

Please sign in to comment.