marcomq / nimview

A Nim/Webview based helper to create Desktop/Server applications with Nim/C/C++ and HTML/CSS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting Window Icon

wwderw opened this issue · comments

Just fond this project and as someone that likes using HTML/CSS for UI work, I'm really enjoying it.

One thing and this is more of just a polish as well, is there anyway to set an icon for the webview window? I haven't been able to find anything in the examples (unless I overlooked it).

It may not even be possible, I don't know. Just a little extra polish if able to do.

Anyway, thanks for the project.

I haven't tried, but I think this might already work when unsing a .rc and an .ico file. Nimview is using the same webview code as wails and there already was a fix to wails for this:
wailsapp/wails#424

Aaahhh ok. I'll go digging around and see what I can come up with.

Thanks for the help.

Will probably also have a deeper look at this when I have time.
Keep me up to date if you somehow find a way to set the icon. Maybe it just works different for "Wails". Maybe this still is simple.

Thx for creating the issue. I completely forgot about the icon :)

Nothing so far, but it could be related to the fact that I'm on Linux, even that issue only referenced windows and mac, so even if I do have it right, it may still not be showing up due to being on Linux and having to run .png versus .ico and I'm still getting the standard x11 window icon for webkit.

I did take a look at a program that I use to flash my keyboard's firmware with as that is build with Wails and on their Linux version, they don't have an icon set. Looking through the documentation, apparently Linux isn't supported as far as easy packaging and since they "bundled" the conversation of the program's icon with packaging, I would say that it includes setting the icon as well for Linux.

Thx for having a look.
It seems that this might be something that gtk could do.
Nimview is using webview and webview is using gtk on linux. Using internal gtk functions could do the trick on linux.
Accoring to this gh issue webview/webview#28
There is a gtk api to change the icon.
https://developer.gnome.org/gtk3/stable/GtkWindow.html#gtk-window-set-icon
So - it might be necessary to call plain C functions and/or change webview.h to implement this.
Not sure if this function still exists, if this actually works or if this just might be complicate to implement.
Just wanted to let you know.

I just added an option to add an icon. You can call a function before calling run:

startDesktop("dist/index.html", run=false)
setIcon(currentSourcePath.parentDir() / "icon.ico")
run()

I only tested it on windows, but it may also work on linux. There is a sample icon in "tests/icon.ico"

Not sure if this is the final version. It would probably be better to have the icon included in the binary. But this is at least some good start.

Edit:
Oh - and this isn't included yet in the latest tag. It is only available in the main branch.

Oh cool, I'll give this a shot when I'm back at that computer and see how that work for Linux.

Thanks!

It works if the html file isn't declared anywhere outside of the location that the program looks for to bundle it in the binary on it's own. When I try to point it to the temp location that's when the icon doesn't show up. Since I use nimassets to bundle everything, I would be declaring outside of the normal location.

It also doesn't appear to close out the connection when closing out the program. I notice that my CLI is still going after exiting the gui portion of the program.

It appears that if I were to install your version of webview, further in nimview's source, and import webview, I am able to do everything as expected with using nimassets and having the icon show up. At least on the Linux side. I have not tried this on my Windows machines yet.

Just thought I would mention that, hope it helps.

@wwderw
Thx. This helps a lot. I need to find out how my own library can prefer its webview folder instead of using an installed webview. No idea yet how to do this in Nim.

I changed the way I import webview. This should hopefully avoid the "bad import".
Also, I changed the way webview is closed, so hopefully, the application stops when stopping webview now.

Currently, the only problem left is that the icon needs to be in some file when nimview starts and it is not compiled into the binary. I guess using nimassets is one do-able way to handle this.

Will close this for now and will create a new tag soon.
Let me know if you still have some issues and thx for the hints and for trying out :)