https://kotlinlang.org logo
Title
t

theapache64

08/06/2021, 5:41 PM
RESOVED: `Window`*’*s
icon
property not working 🧵
fun main(args: Array<String>) = application(
) {
    Window(
        onCloseRequest = ::exitApplication,
        icon = painterResource("drawables/launcher_icons/linux.png")
    ) {

    }
}
I’ve verified the image path and the image dimension is
192x192
. but am getting below default java icon. Is there anything else i need to do to make it work? In the deprecated
Window
API it was working fine with the same image.
i

Igor Demin

08/06/2021, 6:21 PM
macOs doesn't work well with setting icon in runtime. Icon in the Dock can be changed via icon in
build.gradle
(for native distribution) or via global function:
Taskbar.getTaskbar().iconImage
But I don't recommend to use it, as the icon in the taskbar will be changed not immediately, but after some time (1-2 sec). We covered that in tutorials:
Note that to change the icon on the taskbar on some OS (macOs), you should change icon in build.gradle
And in JavaDoc:
@param icon Icon in the titlebar of the window (for platforms which support this)
I assume, we should write about macOs in JavaDoc, and even throw an exception with the link to the tutorial. But I am not 100% sure, will this decision be good for the users of library? Maybe we should return to the old approach - setting
Taskbar.getTaskbar().iconImage
in runtime automatically (as in AppWindow) 🤔 Will setting icon in build.gradle be enough for you, or it would be better to set icon in Window, only to not see the default icon every time you debug your application?
👍 1
t

theapache64

08/06/2021, 6:56 PM
By saying “setting icon in build.gradle”
macOS {
    iconFile.set(iconsRoot.resolve("launcher_icons/macos.icns"))
}
do you mean this? (or is this changed in new APIs) I already have that in place.
I’ve tried the
Taskbar#iconImage
it works. but as a developer, I expect to work this via the
icon
param (
Window
API)
i

Igor Demin

08/06/2021, 7:28 PM
By saying “setting icon in build.gradle”
Yes, but this will work only for native distribution. For
./gradlew run
you can set it via:
application {
    ...
    jvmArgs("-Xdock:icon=src/jvmMain/resources/ic_launcher.png")
It is not obvious, so I think, we should make it a default.
expect to work this via the 
icon
 param
There is another problem - if you set icon for Window not in
icns
format, then the icon will be changed in 1-2 seconds after you run the application. By “changed” I mean the quality of icon will be changed, if you use something like png (icns have different resolutions, so it scales better)
☝️ 1
t

theapache64

08/06/2021, 7:30 PM
Ohh. got it. Would be great if u can add these points to the javDoc 😬 that’s the first place I look when things dont work as expected
i

Igor Demin

08/06/2021, 7:34 PM
Yes, we will write about this. And probably we should write the warning into the console. Exception would be too deadly, because it can be unnoticed in a crossplatform app, if it is not tested on macOs.
t

theapache64

08/06/2021, 7:35 PM
yeah, you’re right. thanks 🙂
@Igor Demin I got a stacktrace today saying
java.lang.UnsupportedOperationException: The ICON_IMAGE feature is not supported on the current platform!
        at java.awt.Taskbar.checkFeatureSupport(Unknown:-1)
        at java.awt.Taskbar.setIconImage(Unknown:-1)
This is happening when I call
Taskbar.getTaskbar().iconImage
in Windows 10. Any idea why its crashing? 🤔
i

Igor Demin

09/12/2021, 9:07 AM
Windows doesn't support setting taskbar icon explicitly. Taskbar icon on Windows always equals to the icon of the current windows (which is set via
icon
parameter in Window). If you really want to set the taskbar icon for macOs in Runtime, you should check
Taskbar.getTaskbar().isSupported(Taskbar.Feature.ICON_IMAGE)
But the recommendation for Compose is still the same - not to use
Taskbar.getTaskbar().iconImage
and use
icon
in build.gradle. We will add
-Xdock:icon
by default in the future, so the icon will also be working in "debug" mode. Until then, you can add it yourself via
jvmArgs
.
t

theapache64

09/12/2021, 9:33 AM
Okay 👍