Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
leavesCZY committed Jul 3, 2024
1 parent e091ca5 commit 66c0032
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 45 deletions.
26 changes: 16 additions & 10 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,30 @@ on:
- "**/workflows-trigger.properties"

env:
PACKAGE_VERSION: 1.0.0
V_PACKAGE_VERSION: v1.0.0
PACKAGE_VERSION: 1.0.1
V_PACKAGE_VERSION: v1.0.1

jobs:

current-time:
runs-on: ubuntu-latest
name: get current time
outputs:
currentTime: ${{steps.currentTime.outputs.formattedTime}}
steps:
- id: currentTime
uses: josStorer/get-current-time@v2
with:
format: YYYY.MM.DD
utcOffset: "+08:00"

create-release-distribution:
strategy:
matrix:
os: [ windows-latest , ubuntu-latest , macos-13 , macos-14 ]
runs-on: ${{ matrix.os }}
name: create release distribution
needs: current-time

steps:
- if: matrix.os != 'macos-14'
Expand Down Expand Up @@ -74,13 +87,6 @@ jobs:
run: |
mv /Users/runner/work/compose-multiplatform-xlog-decode/compose-multiplatform-xlog-decode/build/compose/binaries/main-release/dmg/compose-multiplatform-xlog-decode-${{env.PACKAGE_VERSION}}.dmg /Users/runner/work/compose-multiplatform-xlog-decode/compose-multiplatform-xlog-decode/build/compose/binaries/main-release/dmg/compose-multiplatform-xlog-decode-${{env.V_PACKAGE_VERSION}}-macos-arm64.dmg
- name: get current time
id: currentTime
uses: josStorer/get-current-time@v2
with:
format: YYYY-MM-DD
utcOffset: "+08:00"

- name: draft a new release
uses: ncipollo/release-action@v1
with:
Expand All @@ -89,6 +95,6 @@ jobs:
artifactErrorsFailBuild: false
generateReleaseNotes: true
artifacts: "**/exe/*.exe,**/app/compose-multiplatform-xlog-decode/*.zip,**/deb/*.deb,**/rpm/*.rpm,**/dmg/*.dmg"
body: "## ${{env.V_PACKAGE_VERSION}} / ${{steps.currentTime.outputs.formattedTime}}"
body: "## ${{env.V_PACKAGE_VERSION}} / ${{needs.current-time.outputs.currentTime}}"
tag: "${{env.V_PACKAGE_VERSION}}"
name: "${{env.V_PACKAGE_VERSION}}"
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ compose.desktop {
}
}
packageName = mPackageName
packageVersion = "1.0.0"
packageVersion = "1.0.1"
description = "compose multiplatform xlog decode"
copyright = "© 2024 leavesCZY. All rights reserved."
vendor = "leavesCZY"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ object DecryptUtils {
}

private fun bytesToInt(b: ByteArray, offset: Int): Int {
return b[offset].toInt() and 0xFF or (
(b[offset + 1].toInt() and 0xFF) shl 8) or (
(b[offset + 2].toInt() and 0xFF) shl 16) or (
(b[offset + 3].toInt() and 0xFF) shl 24)
return b[offset].toInt() and 0xFF or ((b[offset + 1].toInt() and 0xFF) shl 8) or ((b[offset + 2].toInt() and 0xFF) shl 16) or ((b[offset + 3].toInt() and 0xFF) shl 24)
}

private fun teaDecipher(byteArray: ByteArray, k: ByteArray): ByteArray {
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/github/leavesczy/xlog/decode/DataStoreManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object DataStoreManager {

private val THEME = intPreferencesKey("theme")

private val AUT_OPEN_FILE_WHEN_PARSING_IS_SUCCESSFUL = booleanPreferencesKey("autOpenFileWhenParsingIsSuccessful")
private val AUTO_OPEN_FILE_WHEN_PARSING_IS_SUCCESSFUL = booleanPreferencesKey("autoOpenFileWhenParsingIsSuccessful")

fun privateKeyFlow(): Flow<String> {
return dataStores.data.map { preferences ->
Expand All @@ -34,9 +34,9 @@ object DataStoreManager {
}
}

fun autOpenFileWhenParsingIsSuccessful(): Flow<Boolean> {
fun autoOpenFileWhenParsingIsSuccessful(): Flow<Boolean> {
return dataStores.data.map { preferences ->
preferences[AUT_OPEN_FILE_WHEN_PARSING_IS_SUCCESSFUL] ?: true
preferences[AUTO_OPEN_FILE_WHEN_PARSING_IS_SUCCESSFUL] ?: true
}
}

Expand All @@ -52,9 +52,9 @@ object DataStoreManager {
}
}

suspend fun autOpenFileWhenParsingIsSuccessful(autoOpen: Boolean) {
suspend fun autoOpenFileWhenParsingIsSuccessful(autoOpen: Boolean) {
dataStores.edit { settings ->
settings[AUT_OPEN_FILE_WHEN_PARSING_IS_SUCCESSFUL] = autoOpen
settings[AUTO_OPEN_FILE_WHEN_PARSING_IS_SUCCESSFUL] = autoOpen
}
}

Expand Down
32 changes: 17 additions & 15 deletions src/main/kotlin/github/leavesczy/xlog/decode/LogDecodeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class LogDecodeViewModel : ViewModel(viewModelScope = CoroutineScope(SupervisorJ
var settingsPageViewState by mutableStateOf(
value = SettingsPageViewState(
theme = Theme.Light,
autOpenFileWhenParsingIsSuccessful = false,
switchTheme = ::switchTheme,
updateAutOpenFileWhenParsingIsSuccessful = ::updateAutOpenFileWhenParsingIsSuccessful
autoOpenFileWhenParsingIsSuccessful = false,
updateAutoOpenFileWhenParsingIsSuccessful = ::updateAutoOpenFileWhenParsingIsSuccessful
)
)
private set
Expand All @@ -83,14 +83,14 @@ class LogDecodeViewModel : ViewModel(viewModelScope = CoroutineScope(SupervisorJ
val privateKey = DataStoreManager.privateKeyFlow().first()
val themeType = DataStoreManager.themeFlow().first()
val theme = Theme.entries.find { it.type == themeType } ?: settingsPageViewState.theme
val autOpenFileWhenParsingIsSuccessful = DataStoreManager.autOpenFileWhenParsingIsSuccessful().first()
val autOpenFileWhenParsingIsSuccessful = DataStoreManager.autoOpenFileWhenParsingIsSuccessful().first()
if (mainPageViewState.privateKey != privateKey) {
mainPageViewState = mainPageViewState.copy(privateKey = privateKey)
}
if (settingsPageViewState.theme != theme || settingsPageViewState.autOpenFileWhenParsingIsSuccessful != autOpenFileWhenParsingIsSuccessful) {
if (settingsPageViewState.theme != theme || settingsPageViewState.autoOpenFileWhenParsingIsSuccessful != autOpenFileWhenParsingIsSuccessful) {
settingsPageViewState = settingsPageViewState.copy(
theme = theme,
autOpenFileWhenParsingIsSuccessful = autOpenFileWhenParsingIsSuccessful
autoOpenFileWhenParsingIsSuccessful = autOpenFileWhenParsingIsSuccessful
)
}
}
Expand Down Expand Up @@ -163,18 +163,20 @@ class LogDecodeViewModel : ViewModel(viewModelScope = CoroutineScope(SupervisorJ
}

private suspend fun autoOpenFileIfNeed(file: File) {
if (settingsPageViewState.autOpenFileWhenParsingIsSuccessful) {
if (settingsPageViewState.autoOpenFileWhenParsingIsSuccessful) {
openFile(file = file)
}
}

private fun generateKeyPair() {
viewModelScope.launch {
val keyPair = DecryptUtils.generateKeyPair()
cryptKeyPageViewState = cryptKeyPageViewState.copy(
privateKey = keyPair.privateKey,
publicKey = keyPair.publicKey
)
withContext(context = Dispatchers.Default) {
val keyPair = DecryptUtils.generateKeyPair()
cryptKeyPageViewState = cryptKeyPageViewState.copy(
privateKey = keyPair.privateKey,
publicKey = keyPair.publicKey
)
}
}
}

Expand All @@ -183,16 +185,16 @@ class LogDecodeViewModel : ViewModel(viewModelScope = CoroutineScope(SupervisorJ
}

private fun switchTheme(theme: Theme) {
settingsPageViewState = settingsPageViewState.copy(theme = theme)
viewModelScope.launch {
settingsPageViewState = settingsPageViewState.copy(theme = theme)
DataStoreManager.updateTheme(theme = theme.type)
}
}

private fun updateAutOpenFileWhenParsingIsSuccessful(autoOpen: Boolean) {
settingsPageViewState = settingsPageViewState.copy(autOpenFileWhenParsingIsSuccessful = autoOpen)
private fun updateAutoOpenFileWhenParsingIsSuccessful(autoOpen: Boolean) {
viewModelScope.launch {
DataStoreManager.autOpenFileWhenParsingIsSuccessful(autoOpen = autoOpen)
settingsPageViewState = settingsPageViewState.copy(autoOpenFileWhenParsingIsSuccessful = autoOpen)
DataStoreManager.autoOpenFileWhenParsingIsSuccessful(autoOpen = autoOpen)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import java.nio.file.Path
@Composable
fun FrameWindowScope.FileLoadDialog(
title: String = "Choose a file",
fileExtension: String? = null,
isMultipleMode: Boolean = false,
isMultipleMode: Boolean,
fileExtension: String?,
onResult: (result: Path?) -> Unit
) = AwtWindow(
create = {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/github/leavesczy/xlog/decode/ui/MainPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import kotlin.io.path.toPath
* @Date: 2024/6/4 14:15
* @Desc:
*/
internal const val xLogFileExtension = "xlog"
private const val xLogFileExtension = "xlog"

@Composable
fun FrameWindowScope.MainPage(
Expand Down Expand Up @@ -127,9 +127,9 @@ fun FrameWindowScope.MainPage(
fileExtension = xLogFileExtension,
onResult = {
if (it != null) {
confirmLogFilePath(paths = listOf(it))
confirmLogFilePath(paths = listOf(element = it))
}
pageViewState.openDialog.onResult(it)
pageViewState.openDialog.onResult(result = it)
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/github/leavesczy/xlog/decode/ui/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data class CryptKeyPageViewState(
@Stable
data class SettingsPageViewState(
val theme: Theme,
val autOpenFileWhenParsingIsSuccessful: Boolean,
val switchTheme: (Theme) -> Unit,
val updateAutOpenFileWhenParsingIsSuccessful: (Boolean) -> Unit
val autoOpenFileWhenParsingIsSuccessful: Boolean,
val updateAutoOpenFileWhenParsingIsSuccessful: (Boolean) -> Unit
)
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ fun SettingsPage(pageViewState: SettingsPageViewState) {
modifier = Modifier,
text = "解析成功后自动打开文件"
)
val checked = pageViewState.autOpenFileWhenParsingIsSuccessful
val checked = pageViewState.autoOpenFileWhenParsingIsSuccessful
Switch(
checked = checked,
onCheckedChange = pageViewState.updateAutOpenFileWhenParsingIsSuccessful
onCheckedChange = pageViewState.updateAutoOpenFileWhenParsingIsSuccessful
)
}
}
Expand Down
Binary file modified src/main/resources/application_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/linux_launch_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/macos_launch_icon.icns
Binary file not shown.
Binary file modified src/main/resources/windows_launch_icon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion workflows-trigger.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
trigger=3
trigger=4

0 comments on commit 66c0032

Please sign in to comment.