[go: nahoru, domu]

Skip to content

Commit

Permalink
fix #62 fix #60 fix #55 fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
izhangzhihao committed Aug 27, 2021
1 parent 5726ef5 commit 3c0284d
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,23 @@ class RainbowFartTypedHandler(originalHandler: TypedActionHandler) : TypedAction
candidates.add(charTyped)
val str = candidates.joinToString("")
BuildInContributes.buildInContributesSeq
.firstOrNull { (keyword, _) ->
str.contains(keyword, true)
}?.let { (_, voices) ->
GlobalScope.launch(Dispatchers.Default) {
releaseFart(voices)
}
candidates.clear()
.firstOrNull { (keyword, _) ->
str.contains(keyword, true)
}?.let { (_, voices) ->
GlobalScope.launch(Dispatchers.Default) {
releaseFart(voices)
}
candidates.clear()
}
if (candidates.size > 20) {
candidates = candidates.subList(10, candidates.size - 1)
}
} finally {
// Ensure original handler is called no matter what errors are thrown, to prevent typing from being lost.
this.myOriginalHandler?.execute(editor, charTyped, dataContext)
try {
this.myOriginalHandler?.execute(editor, charTyped, dataContext)
} catch (e: Throwable) {
}
}
}

Expand All @@ -76,11 +79,11 @@ class RainbowFartTypedHandler(originalHandler: TypedActionHandler) : TypedAction

private fun playVoice(voices: List<String>) {
val mp3Stream =
if (RainbowFartSettings.instance.customVoicePackage != "") {
resolvePath(RainbowFartSettings.instance.customVoicePackage + File.separator + voices.random()).inputStream()
} else {
FartTypedHandler::class.java.getResourceAsStream("/build-in-voice-chinese/" + voices.random())
}
if (RainbowFartSettings.instance.customVoicePackage != "") {
resolvePath(RainbowFartSettings.instance.customVoicePackage + File.separator + voices.random()).inputStream()
} else {
FartTypedHandler::class.java.getResourceAsStream("/build-in-voice-chinese/" + voices.random())
}
val player = Player(mp3Stream)
player.play()
player.close()
Expand Down

0 comments on commit 3c0284d

Please sign in to comment.