Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
springeye committed Jan 18, 2024
1 parent 449bb72 commit ecafc98
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
13 changes: 12 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

import com.codingfeline.buildkonfig.compiler.FieldSpec
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
Expand All @@ -9,6 +9,7 @@ plugins {
id("com.google.devtools.ksp") version "1.9.21-1.0.16"
id("de.jensklingenberg.ktorfit") version "1.11.0"
id("app.cash.sqldelight") version "2.0.1"
id("com.codingfeline.buildkonfig") version "0.15.1"

}
sqldelight {
Expand Down Expand Up @@ -50,6 +51,7 @@ kotlin {
// implementation("app.cash.paging:paging-runtime-uikit:3.3.0-alpha02-0.4.0")
// }
androidMain.dependencies {

implementation(libs.compose.ui.tooling.preview.android)
implementation(libs.androidx.activity.compose)
implementation(libs.ktor.client.okhttp)
Expand Down Expand Up @@ -183,6 +185,15 @@ android {
}
}

buildkonfig {
packageName = "com.github.springeye.memosc"
// objectName = 'YourAwesomeConfig'
// exposeObjectWithName = 'YourAwesomePublicConfig'

defaultConfigs {
buildConfigField(FieldSpec.Type.STRING, "versionCode", libs.versions.packageVersion.get())
}
}
compose.desktop {
application {
mainClass = "com.github.springeye.memosc.MainKt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.os.Build

class AndroidPlatform : Platform {
override val name: String = "Android ${Build.VERSION.SDK_INT}"
override val versionCode: Long
get() = TODO("Not yet implemented")
}

actual fun getPlatform(): Platform = AndroidPlatform()
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ interface MemosApi {
@Query("limit") limit: Int? = null,
@Query("offset") offset: Int? = null
): List<Memo>
@GET
suspend fun get(@Url url: String):Map<String,Any>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.springeye.memosc
interface Platform {
val name: String
val versionCode:String
}

expect fun getPlatform(): Platform
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ val appModule = module {
}
single<HttpClient> {
HttpClient {
this.followRedirects=true
defaultRequest {

if(headers["Content-Type"].isNullOrEmpty()){
Expand All @@ -78,7 +79,7 @@ val appModule = module {
install(Logging) {
logger = object: Logger {
override fun log(message: String) {
Napier.v("HTTP Client", null, message)
// Napier.v("HTTP Client", null, message)
}
}
level = LogLevel.ALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import com.github.springeye.memosc.AppPreferences
import com.github.springeye.memosc.MemosApi
import com.github.springeye.memosc.getPlatform
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.cookies.cookies
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.statement.bodyAsText
import io.ktor.utils.io.printStack
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json

class AppScreenModel(private val api: MemosApi,
private val httpClient: HttpClient,
Expand All @@ -20,8 +27,8 @@ class AppScreenModel(private val api: MemosApi,
}

fun check(){

screenModelScope.launch {
checkUpdate()
val host=prefers.host()
val username=prefers.username()
val password=prefers.password()
Expand All @@ -38,4 +45,22 @@ class AppScreenModel(private val api: MemosApi,
// println("cookies===>${cookies}")
}
}
suspend fun checkUpdate(){
runCatching {
val appVersion=getPlatform().versionCode
httpClient.get("https://api.githhub.com/repos/springeye/memosc/releases/latest"){
header("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
header("Accept","application/vnd.github+json")
header("X-GitHub-Api-Version","2022-11-28")


}.bodyAsText()

}.onSuccess {
println(it)
}.onFailure {
it.printStack()
}

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.springeye.memosc

class JVMPlatform: Platform {
override val name: String = "Java ${System.getProperty("java.version")}"
override val versionCode: String
get() = BuildKonfig.versionCode
}

actual fun getPlatform(): Platform = JVMPlatform()
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ coroutines = "1.7.3"
androidx-startup = "1.1.1"
composeIcons = "1.1.0"
uiGraphicsDesktop = "1.6.0-beta03"
packageVersion="1.0.0"
packageVersion="0.0.1"


[libraries]
Expand Down

0 comments on commit ecafc98

Please sign in to comment.