Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ system tray support #10

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -43,6 +43,15 @@ compose.desktop {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "com.clipevery"
packageVersion = "1.0.0"
macOS {
bundleID = "com.clipevery.desktop"
infoPlist {
extraKeysRawXml = """
<key>LSUIElement</key>
<string>true</string>
""".trimIndent()
}
}
}
}
}
34 changes: 33 additions & 1 deletion composeApp/src/desktopMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -2,13 +2,19 @@ import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.toComposeImageBitmap
import androidx.compose.ui.window.Tray
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.clipevery.ClipeveryApp
import com.clipevery.getClipboard
import org.jetbrains.skia.Image
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.Transferable
import java.io.InputStream
import java.util.function.Consumer
import kotlin.system.exitProcess


fun main() = application {
@@ -25,11 +31,37 @@ fun main() = application {
}
val clipboard = getClipboard(consumer)
clipboard.start()
Window(onCloseRequest = ::exitApplication) {

val imageBitmap = loadIconFromResources("clipevery_icon.png")


Tray(icon = imageBitmap,
menu = {
Item(
"Exit",
onClick = { exitProcess(1) }
)
}
)

Window(onCloseRequest = ::exitApplication,
title = "Clipevery",
icon = imageBitmap,
undecorated = true,
resizable = false) {
ClipeveryApp(clipboard, copyText)
}
}

fun loadIconFromResources(resourceName: String): BitmapPainter {
val resourceStream: InputStream? = Thread.currentThread().contextClassLoader.getResourceAsStream(resourceName)
resourceStream?.let {
val image = Image.makeFromEncoded(it.readAllBytes())
return BitmapPainter(image.toComposeImageBitmap())
}
throw IllegalArgumentException("Resource not found: $resourceName")
}

@Preview
@Composable
fun AppDesktopPreview() {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.