Skip to content

Commit

Permalink
Desktop test
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzemehdi committed Jun 16, 2024
1 parent f7b1378 commit 2e2b4c3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 3 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/desktop_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test Desktop
on:
push:
branches: [ "desktop_support" ]




concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true



jobs:
test:
strategy:
matrix:
config: [
{ target: macos, os: macos-latest, tasks: jvmTest},
{ target: linux, os: ubuntu-latest, tasks: jvmTest iosSimulatorArm64Test},
{ target: windows, os: windows-latest, tasks: jvmTest iosSimulatorArm64Test},
]
runs-on: ${{ matrix.config.os }}
name: Testing on ${{ matrix.config.target }}
steps:
- uses: actions/checkout@v3
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Setup gradle
uses: gradle/[email protected]

- name: Test ${{ matrix.config.target }} targets
continue-on-error: false
run: ./gradlew ${{ matrix.config.tasks }}
5 changes: 5 additions & 0 deletions kmpnotifier/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ kotlin {
commonMain.dependencies {
implementation(libs.koin.core)
}

commonTest.dependencies {
implementation(libs.kotlin.test)
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mmk.kmpnotifier.extensions

internal sealed interface DesktopPlatform {
data object Linux:DesktopPlatform
data object Windows:DesktopPlatform
data object MacOs:DesktopPlatform
}

internal fun getDesktopPlatformType(): DesktopPlatform? {
val name = System.getProperty("os.name")
return when {
name?.contains("Linux") == true -> DesktopPlatform.Linux
name?.contains("Win") == true -> DesktopPlatform.Windows
name?.contains("Mac") == true -> DesktopPlatform.MacOs
else -> null
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mmk.kmpnotifier.notification

import com.mmk.kmpnotifier.extensions.getDesktopPlatformType
import com.mmk.kmpnotifier.notification.configuration.NotificationPlatformConfiguration
import java.awt.SystemTray
import java.awt.Toolkit
Expand All @@ -9,6 +10,9 @@ import kotlin.random.Random

internal class DesktopNotifier(private val desktopNotificationConfiguration: NotificationPlatformConfiguration.Desktop) :
Notifier {
init {
println("CurrentDesktopPlatform: ${getDesktopPlatformType()}")
}
override fun notify(title: String, body: String, payloadData: Map<String, String>): Int {
if (isTraySupported.not()) return -1

Expand All @@ -18,10 +22,12 @@ internal class DesktopNotifier(private val desktopNotificationConfiguration: Not
}

override fun notify(id: Int, title: String, body: String, payloadData: Map<String, String>) {
val iconPath = kotlin.runCatching {
if (isTraySupported.not()) return

val iconPath = kotlin.runCatching {
val resourcesDirectory = File(System.getProperty("compose.application.resources.dir"))
val canoncialPath = resourcesDirectory.canonicalPath
canoncialPath + File.separator + desktopNotificationConfiguration.notificationIconPath
val canonicalPath = resourcesDirectory.canonicalPath
canonicalPath + File.separator + desktopNotificationConfiguration.notificationIconPath
}.getOrNull()

val icon = Toolkit.getDefaultToolkit().getImage(iconPath)
Expand All @@ -36,6 +42,7 @@ internal class DesktopNotifier(private val desktopNotificationConfiguration: Not

}

//TODO for now all notifications are deleted
override fun remove(id: Int) {
removeAll()
}
Expand All @@ -55,4 +62,5 @@ internal class DesktopNotifier(private val desktopNotificationConfiguration: Not
)
}


}
14 changes: 14 additions & 0 deletions kmpnotifier/src/jvmTest/kotlin/NotificationSupporterTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.junit.Assert
import org.junit.Test
import java.awt.SystemTray

class NotificationSupporterTest {


@Test
fun testIsTraySupported() {
println("Os name: ${System.getProperty("os.name")}")
val isTraySupported = SystemTray.isSupported()
Assert.assertTrue(isTraySupported)
}
}

0 comments on commit 2e2b4c3

Please sign in to comment.