-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from mbakgun/feature/desktop-app
- Loading branch information
Showing
15 changed files
with
246 additions
and
24 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
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
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
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
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,39 @@ | ||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
jvmToolchain(11) | ||
withJava() | ||
} | ||
sourceSets { | ||
val jvmMain by getting { | ||
dependencies { | ||
implementation(project(":shared")) | ||
implementation(compose.desktop.currentOs) | ||
} | ||
} | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "com.mbakgun.mj.MainKt" | ||
nativeDistributions { | ||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) | ||
packageVersion = "1.0.0" | ||
copyright = "Mbakgun" | ||
description = "MjImagesDesktopApp" | ||
packageName = "MjImagesDesktopApp" | ||
|
||
macOS { | ||
dockName = "MjImagesDesktopApp" | ||
appCategory = "public.app-category.utilities" | ||
} | ||
} | ||
} | ||
} |
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,12 @@ | ||
# Ktor | ||
-keep class io.ktor.** { *; } | ||
-keepclassmembers class io.ktor.** { volatile <fields>; } | ||
-keep class io.ktor.client.engine.cio.** { *; } | ||
-keep class kotlinx.coroutines.** { *; } | ||
-dontwarn kotlinx.atomicfu.** | ||
-dontwarn io.netty.** | ||
-dontwarn com.typesafe.** | ||
-dontwarn org.slf4j.** | ||
|
||
# Obfuscation breaks coroutines/ktor for some reason | ||
-dontobfuscate |
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,39 @@ | ||
package com.mbakgun.mj | ||
|
||
import androidx.compose.ui.input.key.Key | ||
import androidx.compose.ui.input.key.key | ||
import androidx.compose.ui.window.Window | ||
import androidx.compose.ui.window.application | ||
import di.initKoin | ||
import domain.usecase.MjImagesFetchUseCase | ||
import domain.usecase.MjImagesUseCase | ||
import org.koin.java.KoinJavaComponent.inject | ||
import ui.MjImagesApp | ||
import ui.MjImagesViewModel | ||
|
||
fun main() { | ||
System.setProperty("apple.awt.application.appearance", "system") | ||
initKoin { } | ||
val fetchUseCase by inject<MjImagesFetchUseCase>(MjImagesFetchUseCase::class.java) | ||
val useCase by inject<MjImagesUseCase>(MjImagesUseCase::class.java) | ||
val viewModel = MjImagesViewModel(fetchUseCase, useCase) | ||
|
||
application { | ||
Window( | ||
onCloseRequest = ::exitApplication, | ||
title = "MjImages", | ||
onKeyEvent = { | ||
when (it.key) { | ||
Key.R -> { | ||
viewModel.refreshImages() | ||
true | ||
} | ||
|
||
else -> false | ||
} | ||
} | ||
) { | ||
MjImagesApp(viewModel) | ||
} | ||
} | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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,12 @@ | ||
package util | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
|
||
internal actual fun getDispatcherProvider(): DispatcherProvider = JvmDispatcherProvider() | ||
|
||
private class JvmDispatcherProvider : DispatcherProvider { | ||
override val main = Dispatchers.Main | ||
override val io = Dispatchers.IO | ||
override val default = Dispatchers.Default | ||
override val unconfined = Dispatchers.Unconfined | ||
} |
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,58 @@ | ||
package util | ||
|
||
import com.seiko.imageloader.ImageLoader | ||
import com.seiko.imageloader.component.setupDefaultComponents | ||
import com.seiko.imageloader.defaultImageResultMemoryCache | ||
import okio.Path.Companion.toOkioPath | ||
import java.io.File | ||
|
||
actual fun generateImageLoader(): ImageLoader { | ||
return ImageLoader { | ||
components { | ||
setupDefaultComponents() | ||
} | ||
interceptor { | ||
defaultImageResultMemoryCache() | ||
memoryCacheConfig { | ||
maxSizeBytes(32 * 1024 * 1024) // 32MB | ||
} | ||
diskCacheConfig { | ||
directory(getCacheDir().toOkioPath().resolve("image_cache")) | ||
maxSizeBytes(512L * 1024 * 1024) // 512MB | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class OperatingSystem { | ||
Windows, Linux, MacOS, Unknown | ||
} | ||
|
||
private val currentOperatingSystem: OperatingSystem | ||
get() { | ||
val operSys = System.getProperty("os.name").lowercase() | ||
return if (operSys.contains("win")) { | ||
OperatingSystem.Windows | ||
} else if (operSys.contains("nix") || operSys.contains("nux") || | ||
operSys.contains("aix") | ||
) { | ||
OperatingSystem.Linux | ||
} else if (operSys.contains("mac")) { | ||
OperatingSystem.MacOS | ||
} else { | ||
OperatingSystem.Unknown | ||
} | ||
} | ||
|
||
private fun getCacheDir(): File { | ||
val appName = "MidJourneyImagesComposeMultiplatform" | ||
return when (currentOperatingSystem) { | ||
OperatingSystem.Windows -> File(System.getenv("AppData"), "$appName/cache") | ||
OperatingSystem.Linux -> File(System.getProperty("user.home"), ".cache/$appName") | ||
OperatingSystem.MacOS -> File( | ||
System.getProperty("user.home"), | ||
"Library/Caches/$appName" | ||
) | ||
else -> throw IllegalStateException("Unsupported operating system") | ||
} | ||
} |