Skip to content

Commit

Permalink
Ported several improvements from obmenu-generator.
Browse files Browse the repository at this point in the history
- Support for the "Path" key.
- Create icons and cache.db in ~/.cache
  • Loading branch information
trizen committed Sep 22, 2023
1 parent e28c0a9 commit 5424331
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions fbmenugen
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl

# Copyright (C) 2010-2022 Daniel "Trizen" Șuteu <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d>.
# Copyright (C) 2010-2023 Daniel "Trizen" Șuteu <echo dHJpemVuQHByb3Rvbm1haWwuY29tCg== | base64 -d>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -22,15 +22,15 @@
# Name: fbmenugen
# License: GPLv3
# Created on: 01 August 2010
# Latest edit on: 06 September 2022
# Latest edit on: 22 September 2023
# https://github.com/trizen/fbmenugen

use 5.014;
use File::Spec;
use Linux::DesktopFiles 0.25;

my $pkgname = 'fbmenugen';
my $version = '0.87';
my $version = '0.88';

my ($with_icons, $db_clean, $create_menu, $pipe, $reload_config, $update_config);

Expand All @@ -43,14 +43,16 @@ my $home_dir =
|| `echo -n ~`;

my $xdg_config_home = $ENV{XDG_CONFIG_HOME} || "$home_dir/.config";
my $xdg_cache_home = $ENV{XDG_CACHE_HOME} || "$home_dir/.cache";

my $config_dir = "$xdg_config_home/$pkgname";
my $schema_file = "$config_dir/schema.pl";
my $config_file = "$config_dir/config.pl";
my $cache_db = "$config_dir/cache.db";
my $cache_dir = "$xdg_cache_home/$pkgname";
my $fluxbox_dir = "$home_dir/.fluxbox";
my $menu_file = "$fluxbox_dir/menu";
my $icons_dir = "$config_dir/icons";
my $cache_db = "$cache_dir/cache.db";
my $icons_dir = "$cache_dir/icons";

sub usage {
print <<"HELP";
Expand Down Expand Up @@ -179,6 +181,12 @@ if (not -d $config_dir) {
or die "$0: can't create configuration directory `$config_dir': $!\n";
}

if (not -d $cache_dir) {
require File::Path;
File::Path::make_path($cache_dir)
or die "$0: can't create cache directory `$cache_dir': $!\n";
}

if ($with_icons and not -d $icons_dir) {
remove_database($cache_db);
require File::Path;
Expand Down Expand Up @@ -281,12 +289,23 @@ if ($CONFIG{VERSION} != $version) {
dump_configuration();
}

#<<<
my @desktop_files_paths = do {
my %seen;
grep { !$seen{$_}++ } (
($ENV{XDG_DATA_DIRS} ? split(/:/, $ENV{XDG_DATA_DIRS}) : ()),
@{$CONFIG{'Linux::DesktopFiles'}{desktop_files_paths}},
);
};
#>>>

my $desk_obj = Linux::DesktopFiles->new(
%{$CONFIG{'Linux::DesktopFiles'}},
desktop_files_paths => \@desktop_files_paths,

categories => [map { exists($_->{cat}) ? $_->{cat}[0] : () } @$SCHEMA],

keys_to_keep => ['Name', 'Exec',
keys_to_keep => ['Name', 'Exec', 'Path',
($with_icons ? 'Icon' : ()),
(
ref($CONFIG{'Linux::DesktopFiles'}{skip_entry}) eq 'ARRAY'
Expand Down Expand Up @@ -475,6 +494,7 @@ foreach my $file ($desk_obj->get_desktop_files) {
%info = (
Name => $entry->{Name} // next,
Exec => $entry->{Exec} // next,
Path => $entry->{Path} // '',

(
$with_icons
Expand All @@ -487,6 +507,15 @@ foreach my $file ($desk_obj->get_desktop_files) {
);
#>>>

# Support for the Path key
if ($info{Path} ne '') {
require Encode;
my $path = Encode::decode_utf8($info{Path});
my $exec = Encode::decode_utf8($info{Exec});
$exec = "$^X -e 'chdir(\$ARGV[0]) && exec(\$ARGV[1])' \Q$path\E \Q$exec\E";
$info{Exec} = Encode::encode_utf8($exec);
}

eval {

state $x = do {
Expand Down

0 comments on commit 5424331

Please sign in to comment.