-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Impl the app information model (#29)
- Loading branch information
1 parent
99701b3
commit 529e83d
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.clipevery | ||
|
||
data class AppInfo( | ||
val appName: String = "Clipevery", | ||
val appVersion: String, | ||
val userName: String | ||
) |
5 changes: 5 additions & 0 deletions
5
composeApp/src/commonMain/kotlin/com/clipevery/AppInfoFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.clipevery | ||
|
||
interface AppInfoFactory { | ||
fun createAppInfo(): AppInfo | ||
} |
50 changes: 50 additions & 0 deletions
50
composeApp/src/desktopMain/kotlin/com/clipevery/DesktopAppInfoFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.clipevery | ||
|
||
import com.clipevery.platform.currentPlatform | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import java.io.IOException | ||
import java.nio.file.Paths | ||
import java.util.Properties | ||
|
||
|
||
val logger = KotlinLogging.logger {} | ||
|
||
fun getFactory(): AppInfoFactory { | ||
val platform = currentPlatform() | ||
return if (platform.isMacos()) { | ||
MacosAppInfoFactory() | ||
} else if (platform.isWindows()) { | ||
WindowsAppInfoFactory() | ||
} else { | ||
throw IllegalStateException("Unknown platform: ${platform.name}") | ||
} | ||
} | ||
|
||
class MacosAppInfoFactory: AppInfoFactory { | ||
override fun createAppInfo(): AppInfo { | ||
return AppInfo(appVersion = getVersion(), userName = getUserName()) | ||
} | ||
} | ||
|
||
class WindowsAppInfoFactory: AppInfoFactory { | ||
override fun createAppInfo(): AppInfo { | ||
return AppInfo(appVersion = getVersion(), userName = getUserName()) | ||
} | ||
} | ||
|
||
fun getVersion(): String { | ||
val properties = Properties() | ||
try { | ||
properties.load( Thread.currentThread().contextClassLoader | ||
.getResourceAsStream("version.properties")) | ||
return properties.getProperty("version", "Unknown") | ||
} catch (e: IOException) { | ||
logger.error(e) { "Failed to read version" } | ||
} | ||
return "Unknown" | ||
} | ||
|
||
fun getUserName(): String { | ||
val userHome = System.getProperty("user.home") | ||
return Paths.get(userHome).toFile().name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version=1.0.0 |