Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Mar 25, 2024
1 parent 87cf95c commit e241823
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies {
implementation(libs.koalaPlot.core)
}

val versionValue = "1.0.3"
val versionValue = "1.0.4"
val groupId = "forte.app"

// https://github.com/JetBrains/compose-multiplatform/blob/master/tutorials/Native_distributions_and_local_execution/README.md
Expand Down
19 changes: 18 additions & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ import org.slf4j.LoggerFactory
import view.App
import view.AppState
import java.awt.Toolkit
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.pathString

fun storeAppPath(): Path {
val localAppData = System.getenv("LOCALAPPDATA")
if (localAppData != null) {
return Path(localAppData, "StopBonus", "data")
}

val userHome = System.getProperty("user.home")
if (userHome != null) {
return Path(userHome, "StopBonus", "data")
}

return Path("./data")
}


@Composable
Expand Down Expand Up @@ -54,7 +71,7 @@ fun main() = application {
}

val winState = rememberWindowState(size = winSize)
val databaseOp = remember { connectDatabaseOperator("bonus") }
val databaseOp = remember { connectDatabaseOperator(dataDir = storeAppPath(), schemaName = "bonus") }

val trayState = rememberTrayState()

Expand Down
15 changes: 11 additions & 4 deletions src/main/kotlin/database/DatabaseConnector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
import org.jetbrains.exposed.sql.transactions.transaction
import org.jetbrains.exposed.sql.transactions.transactionManager
import java.nio.file.Path
import kotlin.coroutines.CoroutineContext
import kotlin.io.path.Path
import kotlin.io.path.div
import kotlin.io.path.pathString
import kotlin.math.max

class DatabaseOperator(
Expand Down Expand Up @@ -42,15 +46,17 @@ class DatabaseOperator(

}

fun connectDatabaseOperator(schemaName: String): DatabaseOperator {
private val DEFAULT_DATA_DIR = Path("./data")
private const val DATA_FILE_NAME = "bonus.d"

fun connectDatabaseOperator(dataDir: Path = DEFAULT_DATA_DIR, schemaName: String): DatabaseOperator {
val schema = Schema(schemaName)

val config = hikariConfig {
jdbcUrl = "jdbc:h2:file:./data/bonus.d"
jdbcUrl = "jdbc:h2:file:${(dataDir / DATA_FILE_NAME).pathString}"
driverClassName = "org.h2.Driver"
poolName = "BonusDBPool"
minimumIdle = max(4, Runtime.getRuntime().availableProcessors() / 2)
//threadFactory = Thread.ofVirtual().factory()
minimumIdle = max(1, Runtime.getRuntime().availableProcessors() / 2)
}

val dataSource = HikariDataSource(config)
Expand All @@ -61,6 +67,7 @@ fun connectDatabaseOperator(schemaName: String): DatabaseOperator {
// set other parameters here
defaultFetchSize = 100
keepLoadedReferencesOutOfTransaction = true
defaultMaxRepetitionDelay = 6000
}
)

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/view/account/stats/StatsPageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private fun MainStatsPageView(state: PageViewState) {


/**
* 月份统计
* 月份内的每日统计
*/
private class MonthModeState(yearMonth: YearMonth, type: StatsType) {
var yearMonth: YearMonth by mutableStateOf(yearMonth)
Expand All @@ -160,7 +160,7 @@ private class MonthModeStats(val monthModeState: MonthModeState) : StatsMode() {

@Composable
override fun Label(state: PageViewState) {
Text("月统计")
Text("日统计")
}

@OptIn(ExperimentalMaterial3Api::class)
Expand Down

0 comments on commit e241823

Please sign in to comment.