Skip to content

Commit

Permalink
Some minor improvements
Browse files Browse the repository at this point in the history
- No longer use KMP setup for desktop
- Upgrade dependencies
- Upgrade CI versions
- Re-enable UWP helper on windows
- Possibly fix msstore update
  • Loading branch information
DRSchlaubi committed Jun 2, 2024
1 parent 66cb75a commit d97d3c4
Show file tree
Hide file tree
Showing 28 changed files with 205 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ jobs:
with:
name: android-app
- name: Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
files: |
app/desktop/build/compose/binaries/main-release/deb/*.deb
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v1.13.1'


# Workaround: https://github.com/docker/build-push-action/issues/461
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
name: Publish To Maven
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 22
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/winget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- published
- created
- released
- prereleased

jobs:
winget:
Expand All @@ -29,5 +30,5 @@ jobs:
wingetcreate.exe update Schlaubi.Tonbrett -u $url --version $version
if ($version -notmatch "-") {
.\wingetcreate.exe submit .\manifests\s\Schlaubi\Tonbrett\${version}\ --token $env:WINGET_GITHUB_TOKEN
wingetcreate.exe submit .\manifests\s\Schlaubi\Tonbrett\${version}\ --token $env:WINGET_GITHUB_TOKEN
}
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions app/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dev.schlaubi.tonbrett.gradle.sdkInt
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
Expand Down Expand Up @@ -68,7 +67,7 @@ android {
}

compileOptions {
targetCompatibility = JavaVersion.VERSION_20
targetCompatibility = JavaVersion.VERSION_22
}

kotlin {
Expand Down
54 changes: 23 additions & 31 deletions app/desktop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.org.jline.utils.OSUtils

plugins {
alias(libs.plugins.kotlin.compose)
kotlin("multiplatform")
kotlin("jvm")
kotlin("plugin.serialization")
id("org.jetbrains.compose")
}

kotlin {
jvm()
val windowsBuild = HostManager.hostIsMingw && rootProject.property("dev.schlaubi.tonbrett.no_windows") != "true"

sourceSets {
val windowsMain by creating {
dependsOn(commonMain.get())
dependencies {
implementation(projects.app.desktop.uwpHelper)
}
}
val nonWindowsMain by creating {
dependsOn(commonMain.get())
dependencies {
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.cors)
}
}
dependencies {
implementation(projects.app.shared)
implementation(project.dependencies.compose.desktop.currentOs)
implementation(project.dependencies.compose.materialIconsExtended)
implementation(project.dependencies.compose.material3)
implementation(libs.logback)

jvmMain {
if (OSUtils.IS_WINDOWS && false) {
dependsOn(windowsMain)
} else {
dependsOn(nonWindowsMain)
}
dependencies {
implementation(projects.app.shared)
implementation(project.dependencies.compose.desktop.currentOs)
implementation(project.dependencies.compose.materialIconsExtended)
implementation(project.dependencies.compose.material3)
implementation(libs.logback)
}
}
if(windowsBuild) {
implementation(projects.app.desktop.uwpHelper)
} else {
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.cors)
}
}

sourceSets {
main {
if(windowsBuild) {
kotlin.srcDir("src/windowsMain/kotlin")
} else {
kotlin.srcDir("src/nonWindowsMain/kotlin")
}
}
}

compose.desktop {
application {
Expand Down
25 changes: 0 additions & 25 deletions app/desktop/src/commonMain/kotlin/Platform.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.material.icons.filled.OpenInNew
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
Expand All @@ -19,6 +18,9 @@ import androidx.compose.ui.unit.dp
import cafe.adriel.lyricist.LocalStrings
import dev.schlaubi.tonbrett.app.ColorScheme
import dev.schlaubi.tonbrett.app.api.getUrl
import dev.schlaubi.tonbrett.app.desktop.Platform.launchUri
import dev.schlaubi.tonbrett.app.desktop.Platform.loginType
import dev.schlaubi.tonbrett.app.desktop.Platform.prepareAuthentication
import dev.schlaubi.tonbrett.client.href
import dev.schlaubi.tonbrett.common.Route
import io.ktor.http.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.res.useResource
import androidx.compose.ui.window.*
import cafe.adriel.lyricist.LocalStrings
import dev.schlaubi.tonbrett.app.*
import dev.schlaubi.tonbrett.app.ColorScheme
import dev.schlaubi.tonbrett.app.ProvideLocalWindow
import dev.schlaubi.tonbrett.app.TonbrettApp
import dev.schlaubi.tonbrett.app.api.ProvideContext
import io.ktor.serialization.*
import dev.schlaubi.tonbrett.app.desktop.Platform.launchUri
import dev.schlaubi.tonbrett.app.desktop.Platform.start
import dev.schlaubi.tonbrett.app.title
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.serialization.*
import java.net.URI
import java.awt.Window as AWTWindow

Expand Down
32 changes: 32 additions & 0 deletions app/desktop/src/main/kotlin/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@file:JvmName("Platform")
package dev.schlaubi.tonbrett.app.desktop

import dev.schlaubi.tonbrett.common.Route
import java.net.URI

/**
* Implementations are in `src/nonWindowsMain` and `src/windowsMain`
*/
object Platform : IPlatform by currentPlatform

interface IPlatform {
val loginType: Route.Auth.Type

/**
* Runs any preparation steps for authentication
*/
fun prepareAuthentication(onAuth: () -> Unit)

fun start(args: Array<String>)

/**
* Tries to launch the URI using the UWP `Launcher`.
*
* @param uri the [URI] to launch
*/
fun launchUri(uri: URI)

fun getToken(): String

fun setToken(token: String)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package dev.schlaubi.tonbrett.app.desktop

import dev.schlaubi.tonbrett.app.api.AppContext
import dev.schlaubi.tonbrett.app.desktop.Platform.getToken
import dev.schlaubi.tonbrett.app.desktop.Platform.setToken


abstract class TokenStorageAppContext : AppContext() {
override var token: String
Expand Down
File renamed without changes.
File renamed without changes
36 changes: 21 additions & 15 deletions app/desktop/src/nonWindowsMain/kotlin/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.div

actual val loginType = Route.Auth.Type.APP
val currentPlatform: IPlatform = UnixPlatform()

actual fun start(args: Array<String>) {
val needsAuth = runCatching { getToken() }.isFailure
startApplication(needsAuth)
}
private class UnixPlatform : IPlatform {

override val loginType = Route.Auth.Type.APP

override fun start(args: Array<String>) {
val needsAuth = runCatching { getToken() }.isFailure
startApplication(needsAuth)
}

actual fun prepareAuthentication(onAuth: () -> Unit) = startAuthorizationServer(onAuth)
override fun prepareAuthentication(onAuth: () -> Unit) = startAuthorizationServer(onAuth)

actual fun launchUri(uri: URI) {
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri)
} else {
Runtime.getRuntime().exec(arrayOf("xdg-open", uri.toString()))
override fun launchUri(uri: URI) {
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri)
} else {
Runtime.getRuntime().exec(arrayOf("xdg-open", uri.toString()))
}
}

override fun getToken() = getConfig().sessionToken ?: error("Not signed in")
override fun setToken(token: String) = saveConfig(Config((token)))
}

fun getAppDataRoaming(): Path {
Expand All @@ -31,10 +39,8 @@ fun getAppDataRoaming(): Path {
os.contains("windows", ignoreCase = true) -> Path(System.getenv("APPDATA"))
os.contains("mac", ignoreCase = true) ->
Path(System.getenv("HOME")) / "Library" / "Application Support"

else -> Path(System.getProperty("user.home"))
}
return basePath / "Tonbrett"
}

actual fun getToken() = getConfig().sessionToken ?: error("Not signed in")
actual fun setToken(token: String) = saveConfig(Config((token)))
Loading

0 comments on commit d97d3c4

Please sign in to comment.