wails
wails copied to clipboard
Add version getters
Is your feature request related to a problem? Please describe.
It would be nice, if an app could query some version strings from wails e.g. wails own version, the gtk3 library version, webkit2gtk's version etc. It could then be used by applications to generate better logs / crashreports or just to display version information.
Describe the solution you'd like
some getter functions for version strings of components used in wails. i.e.:
-
wails.version()
-
wails.gtkVersion()
- ...
Describe alternatives you've considered
No response
Additional context
No response
That's a great idea. How would you capture that information? @KiddoV has done some work with SBoM so perhaps he has some insight
@leaanthony hmmm... I'm not recall doing something like you said 🤔
My bad. I must be mistaken 🙏
I would use a mix of static informations & already present api's:
-
wails own version would be simple: a constant:
const Version = "2.x.x";
-
gtk3 & webkit2gtk both have on the one hand version getter functions and macros which can be used to get the version running and the version compiled against respectivly:
// gtk3 guint gtk_get_major_version (void); guint gtk_get_minor_version (void); guint gtk_get_micro_version (void); #define GTK_MAJOR_VERSION #define GTK_MINOR_VERSION #define GTK_MICRO_VERSION // webkit2gtk guint webkit_get_major_version (); guint webkit_get_minor_version (); guint webkit_get_micro_version (); #define WEBKIT_MAJOR_VERSION #define WEBKIT_MINOR_VERSION #define WEBKIT_MICRO_VERSION
This then could be used to build a version string. I would keep all four and implement the defines both into constants while the methods get called by a getter method:
const CompiledGtkVersion = "x.x.x"; const CompiledWebkit2gtkVersion = "x.x.x"; func GetRunningGtkVersion() string; func GetRunningWebkit2gtkVersion() string;
Refs:
-
For the dev-env would only the echo version be interesting, but since it's not used in the production build and echo exposes it itself via a constant it's questionable if we want to expose echo's version ourself again. Reference
I think that are the big dependencies we need to care about. If Im forgetting something please let me know.
For any other dependency (that has no own constant or function to get the version) we most likely need to use some sort of go:generate helper to crawl through files and generate static strings that then can be used. (note: I dont know really if go:generate is able to do such things tbh; would need testing).
Edit: remembered that I only focused on linux here; would need research how/what versions to get for displaying on windows/macos and a way to provide this infos to the user without breaking apps when compiling for different platforms. Maybe with a version struct for each platform which getter can error? or a map that holds dependency_name->version.
Did some research for macos and windows:
In macos all versions for libraries from apple seems to be tied to the os version, so retrieving the os version and using that should be fine; that could also be done via a different package in a app.
In windows there is atleast the webview2 version we could expose, which can be get with the already present webviewloader.GetWebviewVersion
function, which might should be wrapped since it's expects a browserpath that propably shouldn't be set by a wails application.
Other versions we could expose include:
- the version of GDI+, which needs to be generated by interpreting the macro
GDIPVER
which is always0x0110
for GDI+ 1.1 . - the
wCreatorVersion
field of theWINDOWINFO
struct (retrieved by callingGetWindowInfo
with a window handle), which per microsoft docs should containThe Windows version of the application that created the window.
(source). However, this seems to be internal field since you can't get much infos about what values there are.
As to the other part of my edit; I tend to the following as API to retrieve the versions (mimicing a bit how the different options per OS work):
type NativeWindowsVersions struct {
Webview2 string
}
type NativeMacVersions struct {
// None yet
}
type NativeLinuxVersions struct {
Gtk string
Webkit2Gtk string
}
type NativeVersions struct {
Windows NativeWindowsVersions
Mac NativeMacVersions
Linux NativeLinuxVersions
}
func GetNativeVersions() (NativeVersions, error);
If Native
isnt fitting it also could be replaced with NativeFrontend
, Frontend
or Display
.
One thing left though would be how consumers of this API figure out on which OS they are; maybe wails should support some simple checkers/getters there as well? But this might be another Issue altogether.
If there are no takers, I would work on a first draft in the coming days.
Thanks for the research. I'm wondering whether instead of trying to write an API that could change and l/or not have parity, perhaps a simple map would work where we can offer keys as consts?
Thanks for the research. I'm wondering whether instead of trying to write an API that could change and l/or not have parity, perhaps a simple map would work where we can offer keys as consts?
Had a similar idea initially, but wasn't sure if it was a good API xD With using maps it would look like this:
type FrontendVersionType string
const (
GtkVersion FrontendVersionType = "gtk3"
Webkit2GtkVersion FrontendVersionType = "webkit2gtk"
Webview2 FrontendVersionType = "webview2"
)
func GetNativeVersions() map[FrontendVersionType]string
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@Mai-Lapyst are you still keen to do this?
Yes still want it to do; have actually a fist draft but not gotten to the point to test it in the last weeks so it got stalled a bit. Will open a draft PR so you guys can help to test it.
Edit: opened an PR: #2044