Skip to content

Commit

Permalink
[DRun] Launch desktop links via xdg-open
Browse files Browse the repository at this point in the history
Note that this introduces a new dependency on xdg-open, which may not
be installed. In that case, rofi will display an error dialog
with something like:

  "Failed to execute child process xdg-open (No such file or directory)"

which hopefully is explanatory enough for folks.

part of davatorium#1166
  • Loading branch information
flavorjones committed Aug 26, 2020
1 parent e646147 commit 83cbc5a
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion source/dialogs/drun.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

#define DRUN_CACHE_FILE "rofi3.druncache"
#define DRUN_DESKTOP_CACHE_FILE "rofi-drun-desktop.cache"
#define XDG_OPEN_COMMAND "xdg-open"

char *DRUN_GROUP_NAME = "Desktop Entry";

Expand Down Expand Up @@ -222,7 +223,40 @@ static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpoi
}
static void launch_link_entry ( DRunModeEntry *e )
{
g_debug ( "launch_link_entry: implementing launcher" );
if ( e->key_file == NULL ) {
GKeyFile *kf = g_key_file_new ();
GError *error = NULL;
gboolean res = g_key_file_load_from_file ( kf, e->path, 0, &error );
if ( res ) {
e->key_file = kf;
}
else {
g_warning ( "[%s] [%s] Failed to parse desktop file because: %s.", e->app_id, e->path, error->message );
g_error_free ( error );
g_key_file_free ( kf );
return;
}
}

gchar *url = g_key_file_get_string ( e->key_file, e->action, "URL", NULL );
if ( url == NULL || strlen ( url ) == 0 ) {
g_warning ( "[%s] [%s] No URL found.", e->app_id, e->path );
g_free ( url );
return ;
}

gsize command_len = strlen( XDG_OPEN_COMMAND ) + strlen( url ) + 2; // space + terminator = 2
gchar *command = g_newa ( gchar, command_len );
g_snprintf( command, command_len, "%s %s", XDG_OPEN_COMMAND, url );
g_free ( url );

g_debug ( "Link launch command: |%s|", command );
if ( helper_execute_command ( NULL, command, FALSE, NULL ) ) {
char *path = g_build_filename ( cache_dir, DRUN_CACHE_FILE, NULL );
// Store it based on the unique identifiers (desktop_id).
history_set ( path, e->desktop_id );
g_free ( path );
}
}
static void exec_cmd_entry ( DRunModeEntry *e )
{
Expand Down

0 comments on commit 83cbc5a

Please sign in to comment.