Skip to content

Instantly share code, notes, and snippets.

@aperezdc
Created March 2, 2023 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aperezdc/f6a65a95f2baa222c0ce9d65e516e13b to your computer and use it in GitHub Desktop.
Save aperezdc/f6a65a95f2baa222c0ce9d65e516e13b to your computer and use it in GitHub Desktop.
Minimal WPE launcher using libcogcore
/*
* SPDX-License-Identifier: MIT
*
* cc -o minicog minicog.c $(pkg-config wpe-webkit-1.1 cogcore --cflags --libs)
*/
#include <cog/cog.h>
static const char *s_starturl = NULL;
static WebKitWebView*
on_create_view(CogShell *shell, CogPlatform *platform)
{
g_autoptr(GError) error = NULL;
WebKitWebViewBackend *view_backend = cog_platform_get_view_backend(platform, NULL, &error);
if (!view_backend)
g_error("Cannot obtain view backend: %s", error->message);
g_autoptr(WebKitWebView) web_view =
g_object_new(WEBKIT_TYPE_WEB_VIEW,
"settings", cog_shell_get_web_settings(shell),
"web-context", cog_shell_get_web_context(shell),
"backend", view_backend,
NULL);
cog_platform_init_web_view(platform, web_view);
webkit_web_view_load_uri(web_view, s_starturl);
return g_steal_pointer(&web_view);
}
int
main(int argc, char *argv[])
{
g_set_application_name("minicog");
if (argc != 2 && argc != 3) {
g_printerr("Usage: %s [URL [platform]]\n", argv[0]);
return EXIT_FAILURE;
}
g_autoptr(GError) error = NULL;
if (!(s_starturl = cog_uri_guess_from_user_input(argv[1], TRUE, &error)))
g_error("Invalid URL '%s': %s", argv[1], error->message);
cog_modules_add_directory(COG_MODULEDIR);
g_autoptr(GApplication) app = g_application_new(NULL, G_APPLICATION_DEFAULT_FLAGS);
g_autoptr(CogShell) shell = cog_shell_new("minicog", FALSE);
g_autoptr(CogPlatform) platform =
cog_platform_new((argc == 3) ? argv[2] : g_getenv("COG_PLATFORM"), &error);
if (!platform)
g_error("Cannot create platform: %s", error->message);
if (!cog_platform_setup(platform, shell, "", &error))
g_error("Cannot setup platform: %s\n", error->message);
g_signal_connect(shell, "create-view", G_CALLBACK(on_create_view), platform);
g_signal_connect_swapped(app, "shutdown", G_CALLBACK(cog_shell_shutdown), shell);
g_signal_connect_swapped(app, "startup", G_CALLBACK(cog_shell_startup), shell);
g_signal_connect(app, "activate", G_CALLBACK(g_application_hold), NULL);
return g_application_run(app, 1, argv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment