Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
修复"选择词库"相关的bug(#104,#105)。
Browse files Browse the repository at this point in the history
  • Loading branch information
tangshimin committed Jan 18, 2023
1 parent 702907d commit 0851e64
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/main/kotlin/data/Vocabulary.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,20 @@ data class ExternalCaption(

fun loadMutableVocabulary(path: String): MutableVocabulary {
val file = getResourcesFile(path)
return if (file.exists()) {
// 如果当前词库被删除,重启之后又没有选择新的词库,再次重启时才会调用,
// 主要是为了避免再次重启是出现”找不到词库"对话框
return if(path.isEmpty()){
val vocabulary = Vocabulary(
name = "",
type = VocabularyType.DOCUMENT,
language = "",
size = 0,
relateVideoPath = "",
subtitlesTrackId = 0,
wordList = mutableListOf()
)
MutableVocabulary(vocabulary)
}else if (file.exists()) {

try {
val vocabulary = Json.decodeFromString<Vocabulary>(file.readText())
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/state/WordState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,16 @@ private fun loadWordState(): WordState {
try {
val decodeFormat = Json { ignoreUnknownKeys = true }
val dataWordState = decodeFormat.decodeFromString<DataWordState>(typingWordSettings.readText())
WordState(dataWordState)
val wordState = WordState(dataWordState)
// 主要是为了避免再次重启是出现”找不到词库"对话框
if(wordState.vocabulary.name.isEmpty() &&
wordState.vocabulary.relateVideoPath.isEmpty() &&
wordState.vocabulary.wordList.isEmpty()){
wordState.vocabularyName = ""
wordState.vocabularyPath = ""
wordState.saveTypingWordState()
}
wordState
} catch (exception: Exception) {
FlatLightLaf.setup()
JOptionPane.showMessageDialog(null, "设置信息解析错误,将使用默认设置。\n地址:$typingWordSettings")
Expand Down
13 changes: 8 additions & 5 deletions src/main/kotlin/ui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fun App() {
}
when (appState.global.type) {
TypingType.WORD -> {
title = computeTitle(wordState)
title = computeTitle(wordState.vocabularyName,wordState.vocabulary.wordList.isNotEmpty())

// 显示器缩放
val density = LocalDensity.current.density
Expand Down Expand Up @@ -239,16 +239,19 @@ private fun onWindowPlacement(placement: WindowPlacement, state: AppState){
}


private fun computeTitle(typingWord: WordState) :String{
return if (typingWord.vocabulary.wordList.isNotEmpty()) {
when (typingWord.vocabularyName) {
private fun computeTitle(
name:String,
isNotEmpty:Boolean
) :String{
return if (isNotEmpty) {
when (name) {
"FamiliarVocabulary" -> {
"熟悉词库"
}
"HardVocabulary" -> {
"困难词库"
}
else -> typingWord.vocabularyName
else -> name
}
} else {
"请选择词库"
Expand Down

0 comments on commit 0851e64

Please sign in to comment.