16. Create an entry for the Linux-starter
16. Einen Programm-Eintrag für den Linux-Starter erzeugen

GERMAN

Wenn Sie Ihre Anwendung mit FMXLinux entwickelt und auf dem Linux-Desktop installiert haben, wäre es schön, wenn zumindest nach ersten Programmstart ein Anwendungs-Icon für den Starter bereitgestellt werden würde.

Es existieren zwar verschiedene Hilfsprogramme dafür, aber komfortabler ist es natürlich, wenn der Anwender sich darum nicht kümmern muss, sondern das Programm das selbst erledigt.

Das ist noch mehr von Bedeutung, da unter Ubuntu 16.04 zwar noch ein Eintrag im Kontext-Menü "Im Starter behalten" existierte, aber dies für Ubuntu 18.04 nicht mehr der Fall ist.

English

If you have developed your application with FMXLinux and installed it on the Linux desktop, it would be nice if an application icon for the starter were provided after the first program startup.

Although there are various utilities for it, but of course it is more comfortable if the user does not have to worry about it, but the program does it itself.

This is even more important because under Ubuntu 16.04 there was still an entry in the context menu "Keep in the starter", but this is no longer the case for Ubuntu 18.04.



 


Im oberen Bild können Sie das Programm-Icon für mein Programm "Safer Mail" sehen, das auf der hier beschriebenen Art und Weise erzeugt wurde.

Alles was Sie dafür tun müssen, ist letztlich eine ".desktop" Datei zu erzeugen und diese in das "applications" Verzeichnis, unter .local/share zu speichern und zusätzlich mit dem Datei-Attribut "ausführbar" zu versehen (hier ein Auszug in meinem Dateimanager Programm FileIO im unteren Bild):
 


In the picture above you can see the program icon for my program "Safer Mail", which was created in the way described here.


All you have to do is create a ".desktop" file and save it in the "applications" directory, under ".local/ share" and additionally with the file attribute "executable" (here an excerpt in my file manager program FileIO in the picture below):


Am einfachsten ist es, zum Programmstart zu prüfen, ob diese Datei vorhanden ist und wenn nicht, sie zu erzeugen. Das erreichen Sie mit dem folgenden Source-Code:

 


The easiest way is to check if this file is present at the start of the program and if not to generate it.
You can do this with the following source code:

{$IFDEF Linux}
procedure CheckForDesktopIcon (DesktopFilename, DesktopDisplayName, Comment, IconPath: string);
var
  DesktopFile: string; sl: TstringList; Attr: TFileAttributes;
begin
  // Web-Info: https://wiki.ubuntuusers.de/.desktop-Dateien/
  DesktopFile := IncludeTrailingPathDelimiter (GetHomePath) +
  '.local/share/applications/' + DesktopFileName;

  if not FileExists (DesktopFile) then begin
    sl := TStringList.create;

    // Unity-Manager can't handle .desktop-files with BOM (!)
    sl.WriteBOM := false;
    sl.add ('[Desktop Entry]');
    sl.add ('Encoding=UTF-8');
    sl.add ('Name=' + DesktopDisplayName);
    sl.add ('Comment=' + Comment);
    sl.add ('Type=Application');
    sl.add ('Exec=' + Paramstr(0));
    sl.add ('Icon=' + IconPath);
    sl.add ('Terminal=false');
    sl.add ('StartupNotify=true');

    try
      sl.SaveToFile(DesktopFile, TEncoding.UTF8);
    except
     // here you can handle errors...
    end;

    sl.free;

    // Set necessary execution-attributs
    Attr := System.IOutils.TFile.GetAttributes (DesktopFile);
    Include (Attr, TFileAttribute.faOwnerExecute);
    Include (Attr, TFileAttribute.faOthersExecute);
    Include (Attr, TFileAttribute.faGroupExecute);
    System.IOutils.TFile.SetAttributes (Desktopfile, attr);
  end;
end;
{$ENDIF}

// And here the call at programstart

procedure MainForm.create (sender);
begin
{$IFDEF Linux}
  CheckForDesktopIcon ('SaferMail.desktop', 'Safer Mail', 'Mailprogramm', IncludeTrailingPathDelimiter (ExtractFilePath
    (Paramstr(0))) +  'MainIcon.ico');
{$ENDIF}
...
end;


Ich habe Stunden gebraucht, um herauszufinden, dass Ubuntu nicht mit der Desktop-Datei zurecht kommt, wenn die UTF-8 Datei mit BOM gespeichert wurde.
 

It took me hours to figure out that Ubuntu could not handle the desktop file when the UTF-8 file was saved with BOM.
Als Anwendungs-Icon können Sie sowohl eine .ico-Datei als auch eine .png-Datei verwenden.

Ich gehe davon aus, dass diese Vorgehensweise auch für andere Linux-Distrubutionen gültig sein wird.

 

As an application icon, you can use both a .ico file and a .png file.

I assume that this approach will be valid for other Linux distributions as well.