Commit b34e4abf authored by Guido Gunther's avatar Guido Gunther
Browse files

Allow to run 'global webapps'

This allows to put the desktop file to /usr/share/applications and use
an icon from e.g. /usr/share/icons.

Tested with this desktop file:

```
[Desktop Entry]
Name=Webapp test
Exec=epiphany --webapp-desktop-file=/usr/share/applications/epiphany-webapp-test.desktop --application-mode --profile="/home/purism/.local/share/epiphany-webapp-test" https://social.librem.one/@agx
StartupNotify=true
Terminal=false
Type=Application
Categories=Network;GNOME;GTK;
Icon=/tmp/app-icon.png
StartupWMClass=webapp-test
```

The profile directory does not need to exist. Webapps still need
to start with `epiphany-`.
parent eae0580c
Pipeline #52537 failed with stages
in 0 seconds
......@@ -137,6 +137,29 @@ ephy_web_application_get_program_name_from_profile_directory (const char *profil
return name;
}
char *
ephy_web_application_get_program_name_from_desktop_file (const char *desktop_file)
{
char *pos, *name;
if (!g_str_has_suffix (desktop_file, ".desktop")) {
g_warning ("Desktop file %s does not end in .desktop", desktop_file);
return NULL;
}
pos = strrchr (desktop_file, G_DIR_SEPARATOR);
if (pos == NULL) {
g_warning ("Desktop file %s is not a valid file name", desktop_file);
return NULL;
}
pos++; /* Strip '/' */
name = g_strndup (pos, strlen (desktop_file) - strlen (".desktop"));
g_debug ("Program name: %s", name);
return name;
}
static const char *
get_app_id_from_program_name (const char *name)
{
......@@ -435,18 +458,22 @@ ephy_web_application_ensure_for_app_info (GAppInfo *app_info)
}
void
ephy_web_application_setup_from_profile_directory (const char *profile_directory)
ephy_web_application_setup_from_profile_directory (const char *profile_directory,
const char *webapp_desktop_file)
{
const char *program_name;
char *program_name;
const char *id;
char *app_icon;
char *desktop_basename;
char *desktop_filename;
char *desktop_basename = NULL;
char *desktop_filename = NULL;
GDesktopAppInfo *desktop_info;
g_assert (profile_directory != NULL);
program_name = ephy_web_application_get_program_name_from_profile_directory (profile_directory);
if (webapp_desktop_file)
program_name = ephy_web_application_get_program_name_from_desktop_file (webapp_desktop_file);
else
program_name = ephy_web_application_get_program_name_from_profile_directory (profile_directory);
if (!program_name)
exit (1);
......@@ -457,16 +484,30 @@ ephy_web_application_setup_from_profile_directory (const char *profile_directory
exit (1);
/* Get display name from desktop file */
desktop_basename = get_app_desktop_filename (id);
desktop_filename = g_build_filename (profile_directory, desktop_basename, NULL);
desktop_info = g_desktop_app_info_new_from_filename (desktop_filename);
if (!desktop_info) {
g_warning ("Required desktop file not present at %s", desktop_filename);
exit (1);
if (webapp_desktop_file) {
desktop_info = g_desktop_app_info_new_from_filename (webapp_desktop_file);
if (!desktop_info) {
g_warning ("Required desktop file not present at %s", webapp_desktop_file);
exit (1);
}
} else {
desktop_basename = get_app_desktop_filename (id);
desktop_filename = g_build_filename (profile_directory, desktop_basename, NULL);
desktop_info = g_desktop_app_info_new_from_filename (desktop_filename);
if (!desktop_info) {
g_warning ("Required desktop file not present at %s", desktop_filename);
exit (1);
}
}
g_set_application_name (g_app_info_get_name (G_APP_INFO (desktop_info)));
app_icon = g_build_filename (profile_directory, EPHY_WEB_APP_ICON_NAME, NULL);
if (webapp_desktop_file) {
GIcon *icon;
icon = g_app_info_get_icon (G_APP_INFO (desktop_info));
app_icon = g_icon_to_string (icon);
} else {
app_icon = g_build_filename (profile_directory, EPHY_WEB_APP_ICON_NAME, NULL);
}
gtk_window_set_default_icon_from_file (app_icon, NULL);
/* We need to re-set this because we have already parsed the
......@@ -478,6 +519,8 @@ ephy_web_application_setup_from_profile_directory (const char *profile_directory
g_free (desktop_basename);
g_free (desktop_filename);
g_object_unref (desktop_info);
if (webapp_desktop_file)
g_free (program_name);
}
void
......
......@@ -47,7 +47,8 @@ char *ephy_web_application_ensure_for_app_info (GAppInfo *app_info
gboolean ephy_web_application_delete (const char *id);
void ephy_web_application_setup_from_profile_directory (const char *profile_directory);
void ephy_web_application_setup_from_profile_directory (const char *profile_directory,
const char *webapp_desktop_file);
void ephy_web_application_setup_from_desktop_file (GDesktopAppInfo *desktop_info);
......
......@@ -32,6 +32,8 @@
#include "ephy-web-app-utils.h"
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <glib-unix.h>
#include <gtk/gtk.h>
......@@ -56,6 +58,7 @@ static gboolean application_mode = FALSE;
static gboolean automation_mode = FALSE;
static char *desktop_file_basename = NULL;
static char *profile_directory = NULL;
static char *webapp_desktop_file = NULL;
static EphyShell *ephy_shell = NULL;
static int shutdown_signum = 0;
......@@ -122,6 +125,8 @@ static const GOptionEntry option_entries[] = {
N_("Start a private instance for WebDriver control"), NULL },
{ "profile", 0, 0, G_OPTION_ARG_STRING, &profile_directory,
N_("Custom profile directory for private instance"), N_("DIR") },
{ "webapp-desktop-file", 0, 0, G_OPTION_ARG_STRING, &webapp_desktop_file,
N_("Custom desktop file for webapp"), N_("DIR") },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &arguments,
"", N_("URL …") },
{ "version", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
......@@ -289,9 +294,18 @@ main (int argc,
exit (1);
}
if (application_mode && profile_directory && !g_file_test (profile_directory, G_FILE_TEST_IS_DIR)) {
g_print ("--profile must be an existing directory when --application-mode is requested\n");
exit (1);
if (application_mode && profile_directory) {
if (!g_file_test (profile_directory, G_FILE_TEST_IS_DIR)) {
if (webapp_desktop_file) {
if (g_mkdir (profile_directory, 0700)) {
g_print ("Failed to create webapp directory\n");
exit (1);
}
} else {
g_print ("--profile must be an existing directory when --application-mode is requested\n");
exit (1);
}
}
}
if (application_mode && !profile_directory) {
......@@ -392,7 +406,8 @@ main (int argc,
ephy_web_application_setup_from_desktop_file (desktop_info);
g_object_unref (desktop_info);
} else {
ephy_web_application_setup_from_profile_directory (profile_directory);
ephy_web_application_setup_from_profile_directory (profile_directory,
webapp_desktop_file);
}
} else if (profile_directory) {
/* This mode exists purely for letting EphyShell know it should
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment