-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
227 additions
and
86 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
52 changes: 52 additions & 0 deletions
52
abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/desktop/config/AppCommonConfig.kt
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,52 @@ | ||
package me.yricky.abcde.desktop.config | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import me.yricky.abcde.desktop.DesktopUtils.dataDir | ||
import me.yricky.abcde.desktop.DesktopUtils.json | ||
import java.awt.GraphicsEnvironment | ||
import java.io.File | ||
|
||
@Serializable | ||
data class AppCommonConfig( | ||
@SerialName("density") | ||
val density:Float = GraphicsEnvironment.getLocalGraphicsEnvironment() | ||
?.defaultScreenDevice | ||
?.defaultConfiguration | ||
?.defaultTransform | ||
?.scaleX?.toFloat() ?: 1f, | ||
@SerialName("historyList") | ||
val historyList:List<String> = emptyList(), | ||
@SerialName("darkTheme") | ||
val darkTheme:Boolean? = true, | ||
@SerialName("futureFeature") | ||
val futureFeature:Boolean = false | ||
){ | ||
companion object{ | ||
suspend fun edit(action: (AppCommonConfig) -> AppCommonConfig){ | ||
withContext(Dispatchers.IO){ | ||
println("edit!") | ||
val appConfig = action(inst.value) | ||
file.writeText(json.encodeToString(appConfig)) | ||
inst.value = appConfig | ||
} | ||
} | ||
|
||
|
||
private val file = File(dataDir,"cfg.json") | ||
private val inst = MutableStateFlow(kotlin.runCatching { | ||
json.decodeFromString<AppCommonConfig>(file.readText()) | ||
}.onFailure { | ||
it.printStackTrace() | ||
}.getOrNull() ?: AppCommonConfig().also { | ||
file.writeText(json.encodeToString(it)) | ||
}) | ||
val flow :StateFlow<AppCommonConfig> = inst.asStateFlow() | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/desktop/config/HistoryConfig.kt
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,48 @@ | ||
package me.yricky.abcde.desktop.config | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import me.yricky.abcde.desktop.DesktopUtils.dataDir | ||
import me.yricky.abcde.desktop.DesktopUtils.json | ||
import java.awt.GraphicsEnvironment | ||
import java.io.File | ||
|
||
@Serializable | ||
data class HistoryConfig( | ||
@SerialName("openedFile") | ||
val openedFile: List<OpenedFile> = emptyList() | ||
){ | ||
@Serializable | ||
class OpenedFile( | ||
@SerialName("lastTime") | ||
val lastTime: Long, | ||
@SerialName("path") | ||
val path: String | ||
) | ||
companion object{ | ||
suspend fun edit(action: (HistoryConfig) -> HistoryConfig){ | ||
withContext(Dispatchers.IO){ | ||
val appConfig = action(inst.value) | ||
file.writeText(json.encodeToString(appConfig)) | ||
inst.value = appConfig | ||
} | ||
} | ||
|
||
|
||
private val file = File(dataDir,"history.json") | ||
private val inst = MutableStateFlow(kotlin.runCatching { | ||
json.decodeFromString<HistoryConfig>(file.readText()) | ||
}.onFailure { | ||
it.printStackTrace() | ||
}.getOrNull() ?: HistoryConfig().also { | ||
file.writeText(json.encodeToString(it)) | ||
}) | ||
val flow :StateFlow<HistoryConfig> = inst.asStateFlow() | ||
} | ||
} |
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.