Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Expose _webui_find_best_browser #325

Closed
SpikeHD opened this issue Feb 10, 2024 · 4 comments · Fixed by #326
Closed

[Feature Request] Expose _webui_find_best_browser #325

SpikeHD opened this issue Feb 10, 2024 · 4 comments · Fixed by #326

Comments

@SpikeHD
Copy link
Contributor

SpikeHD commented Feb 10, 2024

I feel as though there may be some conditional logic developers may want to do based on the browser to use, BEFORE the window is shown. An example of this would be conditionally loading a Firefox XPI or Chromium extension, depending on which browser will be used (assuming #307 implements the feature for both platforms).

I imagine it would look something like this:

Window myWindow = new_window();

if (webui_find_best_browser() == Firefox) {
  // Set XPI file in extensions to load
} else if (webui_find_best_browser() == ChromiumBased) {
  // Set ZIP or whatever Chromium uses I can't remember
} else {
  // Do nothing? Attempt to load both and see which works? Idk, up to the developer
}

// Since `show()` internally also calls `webui_find_best_browser()`, this should match what was determined earlier UNLESS there is already a `current_browser` set internally (see: https://github.com/webui-dev/webui/blob/2a5f0c98fbb267a5aed921a8678f3f108bb12a6e/src/webui.c#L5272)
myWindow.show("<html>Hello World!</html>")

Perhaps the function should also be renamed to something like webui_determine_browser or something, just to make it more clear.

@jinzhongjia
Copy link
Contributor

Now, there is a api for choosing browser webui_show_browser:

WEBUI_EXPORT bool webui_show_browser(size_t window, const char* content, size_t browser);

It will return whether the setting is successful, which can indeed achieve the effect you mentioned.
But I think your proposal is better, it should provide an API to detect whether the browser is available

@SpikeHD
Copy link
Contributor Author

SpikeHD commented Feb 11, 2024

Totally! I think that the API you linked covers 90% of cases, but it would be good to have something that allows devs to know before the browser launches, in case they need to do any specific preparations (preloading a browser specific library, showing a warning/message asking the user if they want to use the browser that was detected, etc.)

@AlbertShown
Copy link
Contributor

Good point. We can probably create a new API like this:

WEBUI_EXPORT size_t webui_get_best_browser();
size_t webui_get_best_browser() {
    return _webui_find_best_browser();
}

@AlbertShown
Copy link
Contributor

if (webui_get_best_browser() == Firefox) {

  // Set XPI file in extensions to load
  webui_show_browser(myWindow, HTML, Firefox); 

} else if (webui_get_best_browser() == Chrome) {

  // Set ZIP or whatever Chrome uses
  webui_show_browser(myWindow, HTML, Chrome); 

} else {

  // ...
  webui_show(myWindow, HTML); 

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants