setup dock icon for macos

This commit is contained in:
Denis-Cosmin NUTIU 2024-03-24 19:22:25 +02:00
parent fce5bc754f
commit 80dd84d657
2 changed files with 29 additions and 4 deletions

View file

@ -20,7 +20,7 @@ class ImageTagsPrediction private constructor() {
init {
try {
logger.info("Loaded ML model.")
logger.info("Loading ML model. Please wait.")
ImageTagsPrediction::class.java.getResourceAsStream("/dev/nuculabs/imagetagger/ai/prediction.onnx").let { modelFile ->
ortSession = ortEnv.createSession(
modelFile!!.readBytes(),

View file

@ -6,6 +6,8 @@ import javafx.fxml.FXMLLoader
import javafx.scene.Scene
import javafx.scene.image.Image
import javafx.stage.Stage
import java.awt.Taskbar
import java.awt.Toolkit
import java.util.logging.Logger
class MainPage : Application() {
@ -13,9 +15,16 @@ class MainPage : Application() {
private lateinit var fxmlLoader: FXMLLoader
private lateinit var mainStage: Stage
override fun start(stage: Stage) {
ImageTagsPrediction.getInstance()
// Initial resource loading
fxmlLoader = FXMLLoader(MainPage::class.java.getResource("main-window-view.fxml"))
mainStage = stage
ImageTagsPrediction.getInstance()
setUpApplicationIcon()
// Load the FXML.
val scene = Scene(fxmlLoader.load(), 640.0, 760.0)
@ -28,11 +37,27 @@ class MainPage : Application() {
stage.minWidth = 640.0
stage.minHeight = 760.0
// Add main icon
stage.icons.add(Image(MainPage::class.java.getResourceAsStream("image-analysis.png")));
stage.show()
}
/**
* Loads and sets up the main application icon.
*/
private fun setUpApplicationIcon() {
// Add main icon
try {
// This is only needed for MacOS.
val defaultToolkit = Toolkit.getDefaultToolkit();
val taskbar = Taskbar.getTaskbar()
taskbar.iconImage = defaultToolkit.getImage(MainPage::class.java.getResource("image-analysis.png"))
} catch (e: UnsupportedOperationException) {
logger.fine("Failed to setup application icon.")
}
val mainIcon = Image(MainPage::class.java.getResourceAsStream("image-analysis.png"))
mainStage.icons.add(mainIcon)
}
override fun stop() {
logger.info("Stop called.")
val controller = fxmlLoader.getController<MainPageController>()