Skip to content

Commit

Permalink
feat: rounded icon on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-Fabi committed Jul 21, 2024
1 parent 3ee6ce7 commit 0e1f75d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 14 deletions.
7 changes: 4 additions & 3 deletions conveyor.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// This is a hashbang include. You can run the command after the #! to see what
// configuration is being extracted from the Gradle build using the Conveyor plugin.
include "#!./gradlew -q printConveyorConfig"

// This enables native library extraction, which improves app startup time and robustness.
Expand All @@ -16,7 +14,10 @@ app {
vendor = DatePollSystems
contact-email = "[email protected]"

icons = icon.svg // TODO add and change loading of it in App.kt
icons = icon.svg
mac.icons = icon-rounded.svg
site.icons = icon-rounded.svg

windows.inputs += TASK/rendered-icons/windows
linux.inputs += TASK/rendered-icons/linux

Expand Down
70 changes: 70 additions & 0 deletions icon-rounded.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.datepollsystems.waiterrobot.mediator.ui

import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.loadImageBitmap
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
Expand All @@ -11,21 +11,12 @@ import androidx.compose.ui.window.rememberWindowState
import org.datepollsystems.waiterrobot.mediator.core.ShortcutManager
import org.datepollsystems.waiterrobot.mediator.navigation.Navigation
import org.datepollsystems.waiterrobot.mediator.ui.theme.WaiterRobotTheme
import java.nio.file.Paths
import java.nio.file.Path
import kotlin.io.path.exists
import kotlin.io.path.inputStream

fun startUI(onClose: () -> Unit = {}) {
application {
val appIcon = remember {
System.getProperty("app.dir") // Only available when packaged
?.let { Paths.get(it, "icon-512.png") }
?.takeIf { it.exists() }
?.inputStream()
?.buffered()
?.use { BitmapPainter(loadImageBitmap(it)) }
}

Window(
title = "kellner.team",
icon = appIcon,
Expand All @@ -44,3 +35,19 @@ fun startUI(onClose: () -> Unit = {}) {
}
}
}

private val appIcon: Painter? by lazy {
// app.dir is set when packaged to point at our collected inputs.
val appDir = System.getProperty("app.dir")?.let { Path.of(it) }
// On Windows we should use the .ico file.
// On Linux, there's no native compound image format and Compose can't render SVG icons, so we pick the 128x128
// icon and let the frameworks/desktop environment rescale.
// On macOS we don't need to do anything.
var iconPath = appDir?.resolve("app.ico")?.takeIf { it.exists() }
iconPath = iconPath ?: appDir?.resolve("icon-square-128.png")?.takeIf { it.exists() }
if (iconPath?.exists() == true) {
BitmapPainter(iconPath.inputStream().buffered().use { loadImageBitmap(it) })
} else {
null
}
}

0 comments on commit 0e1f75d

Please sign in to comment.