Recent

Author Topic: (Re)Create .desktop file using Project Options?  (Read 5319 times)

dsiders

  • Hero Member
  • *****
  • Posts: 1282
(Re)Create .desktop file using Project Options?
« on: June 23, 2024, 07:50:57 pm »
The idea is to add a frame to Project Options which enables creation (or recreation) of the .desktop file on supported platforms when the project is built. The major Linux DEs (Gnome and KDE) seem to be reliant on them. Not sure what macOS or other platforms require.

The frame / page could contain edit controls for the required and optional name/value pairs in the Desktop Entry Specification (https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html). It could write the .desktop file to the same directory as the executable when the project is built. Obviously the IDE and LazBuild (and make files?) would need to support the new feature.

I convinced myself that this was a good idea. But I am relatively new to the Linux environment, I realize it is just an INI-style file... but it would be convenient to automate it. Is there an existing tool or mechanism to do this already? I could not find one...
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

MarkMLl

  • Hero Member
  • *****
  • Posts: 8032
Re: (Re)Create .desktop file using Project Options?
« Reply #1 on: June 23, 2024, 08:37:51 pm »
I agree that it would be a useful thing to have, provision of .desktop file editors is... erratic.

I suggest familiarising yourself with the various related programs:

Code: Text  [Select][+][-]
  1. $ apropos xdg
  2.  
  3. exmendis (1)         - enable or disable extra menus for GNOME, KDE and other XDG menu-spec compliant desktops
  4. exmenen (1)          - enable or disable extra menus for GNOME, KDE and other XDG menu-spec compliant desktops
  5. systemd-xdg-autostart-generator (8) - User unit generator for XDG autostart files
  6. user-dirs.conf (5)   - configuration for xdg-user-dirs-update
  7. user-dirs.defaults (5) - default settings for XDG user dirs
  8. user-dirs.dirs (5)   - settings for XDG user dirs
  9. xdg-dbus-proxy (1)   - D-Bus proxy
  10. xdg-desktop-icon (1) - command line tool for (un)installing icons to the desktop
  11. xdg-desktop-menu (1) - command line tool for (un)installing desktop menu items
  12. xdg-email (1)        - command line tool for sending mail using the user's preferred e-mail composer
  13. xdg-icon-resource (1) - command line tool for (un)installing icon resources
  14. xdg-mime (1)         - command line tool for querying information about file type handling and adding descriptions for new file types
  15. xdg-open (1)         - opens a file or URL in the user's preferred application
  16. xdg-screensaver (1)  - command line tool for controlling the screensaver
  17. xdg-settings (1)     - get various settings from the desktop environment
  18. xdg-user-dir (1)     - Find an XDG user dir
  19. xdg-user-dirs-update (1) - Update XDG user dir configuration
  20.  

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: (Re)Create .desktop file using Project Options?
« Reply #2 on: June 23, 2024, 09:17:36 pm »
I agree that it would be a useful thing to have, provision of .desktop file editors is... erratic.

I was only considering creation... not deployment. Like the path for the executable, that's hard to automate for the various Linuxes .

I suggest familiarising yourself with the various related programs:
Code: Text  [Select][+][-]
  1. $ apropos xdg
  2. (elided)
  3.  

XDG seems to be a lot like Wayland.... very good at creating specifications that they don't have to implement. :)

Useful links, I'll add those to my retirement reading list.


Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

MarkMLl

  • Hero Member
  • *****
  • Posts: 8032
Re: (Re)Create .desktop file using Project Options?
« Reply #3 on: June 23, 2024, 10:02:25 pm »
XDG seems to be a lot like Wayland.... very good at creating specifications that they don't have to implement. :)

No, that stuff's important.

What they've done is said "Right, this is the functionality that a desktop will probably need. Format the command lines like this..." and various distreaux have, by and large, complied with their own implementation. However it's my experience that some of the lesser desktops like LXDE (hence the RPi) quite simply don't have a .desktop editor that a developer can invoke to create the file in the first place.

Where does Windows (and for that matter the Mac) stand on this? Is there a concrete file format that can be used to create a shortcut etc.?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

bobby100

  • Sr. Member
  • ****
  • Posts: 260
    • Malzilla
Re: (Re)Create .desktop file using Project Options?
« Reply #4 on: June 23, 2024, 10:55:20 pm »
Where does Windows (and for that matter the Mac) stand on this? Is there a concrete file format that can be used to create a shortcut etc.?
On Windows, the .lnk files are binary files, but one can use Shell API to create or read .lnk files.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8032
Re: (Re)Create .desktop file using Project Options?
« Reply #5 on: June 23, 2024, 11:04:08 pm »
On Windows, the .lnk files are binary files, but one can use Shell API to create or read .lnk files.

OK, so they exist as a file rather than being embedded in the registry or as EAs, and the IDE could decide on the format (i.e. .lnk vs .desktop) based on the binary format.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

duralast

  • New Member
  • *
  • Posts: 23
Re: (Re)Create .desktop file using Project Options?
« Reply #6 on: June 24, 2024, 03:58:28 am »
OK, so they exist as a file rather than being embedded in the registry
MarkMLl
.lnk files are in the registry, but the Windows default is not to show them from the NeverShowExt property.

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: (Re)Create .desktop file using Project Options?
« Reply #7 on: June 24, 2024, 04:56:12 am »
(Linux comments) I consider making a Desktop file more a packaging thing than a building one. In my git tree I have a template desktop file (as shown below) and use sed to edit it as necessary as I build each particular type of package. But the important things remain constant.

Code: [Select]
[Desktop Entry]
Name=tomboy-ng
Name[de]=tomboy-ng
Name[es]=tomboy-ng
Name[fr]=tomboy-ng
Name[nl]=tomboy-ng
Comment=Cross Platform Notes
Comment[de]=Notizen Plattformübergreifend
Comment[es]=Notas Multiplatforma
Comment[fr]=Notes Multiplateforme
Comment[nl]=Platformoverschrijdend notities
GenericName=Note Taker
GenericName[de]=Notizanwendung
GenericName[es]=Tomador de apuntes
GenericName[fr]=Application de prise de notes
GenericName[nl]=Notities maken
Exec=env QT_QPA_PLATFORM=xcb tomboy-ng %f
Icon=/usr/share/icons/hicolor/256x256/apps/tomboy-ng.png
Terminal=false
Type=Application
Categories=GNOME;Utility
Keywords=notes;

It has a number of lines that are subject to i18n so that would need be considered in a build model. The executable, depending on packaging, is typically found in the PATH so thats easy, an icon is necessary, packaging says that belongs in /usr/share/icons/ but that requires root access to install. Its also reasonable to put that icon in (eg) $HOME/.icons and the Desktop file in $HOME/.local/share/applications/ (and system will look for it there) but that conflicts with the idea that an "install" is multiuser.  So, its a solution for a DIY install script, not a formal package.

So, Don's "make a desktop" form can -
  • get executable name from the Lazarus project,
  • offer to use executable name as application name,
  • request a Comment and Generic Name (and push those to the i18n pot file)
  • suggest an icon location
  • Suggest Terminal is false for GUI app
  • request Categories
  • request Keywords (and push that to the i18n pot file)
  • Maybe, just maybe, a button to put desktop file and an icon in the (local) appropriate places ???


Note that I set an environment variable, QT_QPA_PLATFORM=xcb in the Exec line, thats needed for a Qt5 app (else some things don't work under Wayland) and does no harm for a gtk2 app.

A big, strong warning that a desktop file in your source tree is of no use at all. It must go into either  $HOME/.local/share/applications/  or /usr/share/applications/ to be used. I see lots of messages to the forum "I made a desktop file but it gets ignored"

A desktop file is not absolutely necessary but does a heap of good things.
  • Automatically (when installed) shows up in menu system
  • Defines what Icon is associated with the app.
  • Allows running the app in a predetermined environment or with predefined options. Such as my 'xcb' above.
  • is observed by any menu (or menu like) launch or from the command line with, eg, $> gtk-launch myapp [enter}


I think its a good idea Don, we already do something vaguely similar for Mac users with the app bundle.

Davo

Phew ! I hate long posts, sorry !


 
« Last Edit: June 24, 2024, 04:58:29 am by dbannon »
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

bobby100

  • Sr. Member
  • ****
  • Posts: 260
    • Malzilla
Re: (Re)Create .desktop file using Project Options?
« Reply #8 on: June 24, 2024, 06:14:38 am »
OK, so they exist as a file rather than being embedded in the registry
MarkMLl
.lnk files are in the registry, but the Windows default is not to show them from the NeverShowExt property.
You are making confusion. Files are on the physical media (hdd etc), but the file extensions are displayed or not according to the settings in the registry.

@dbannon
my .desktop file is like this:
Code: [Select]
Name=MiniDexed Control Center
Version=1.0
Exec=MiniDexedCC
Comment=Librarian/Editor for MiniDexed
Icon=MiniDexedCC.png
Type=Application
Terminal=false
StartupNotify=true
Encoding=UTF-8
Categories=Utility;
where the icons are in /usr/share/pixmaps and the app in /usr/bin and it works fine on Linux Mint.
I use Debreate for packaging, and this is the file created by Debreate

MarkMLl

  • Hero Member
  • *****
  • Posts: 8032
Re: (Re)Create .desktop file using Project Options?
« Reply #9 on: June 24, 2024, 08:16:19 am »
OK, so they exist as a file rather than being embedded in the registry
MarkMLl
.lnk files are in the registry, but the Windows default is not to show them from the NeverShowExt property.

Right, so if they're in the registry they're not files then.

Are you saying that, like the old .reg files, they can be used to load stuff into the registry? Because that sounds like what's needed.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

bobby100

  • Sr. Member
  • ****
  • Posts: 260
    • Malzilla
Re: (Re)Create .desktop file using Project Options?
« Reply #10 on: June 24, 2024, 04:39:58 pm »
OK, so they exist as a file rather than being embedded in the registry
MarkMLl
.lnk files are in the registry, but the Windows default is not to show them from the NeverShowExt property.

Right, so if they're in the registry they're not files then.

Are you saying that, like the old .reg files, they can be used to load stuff into the registry? Because that sounds like what's needed.

MarkMLl
No.
Read my previous post. LNK files are not imported into registry. LNK files are open and executed by the shell (Windows Explorer). In LNK file you can put a path to an executable, or you can put a URL, or or or, and it will be open by the shell just like clicking on files in Explorer - it will be open with an associated app according to the extension of the link inside the LNK file.

Here is the code I use to create LNK files (code source: internet):

Code: Pascal  [Select][+][-]
  1. uses ...shlobj, activex, comobj....
  2.  
  3. procedure CreateDesktopShortCut(LinkName: WideString;
  4.   WorkDir, Target, TargetArguments, Description, IconPath: string; IconIndex: integer);
  5. var
  6.   IObject: IUnknown;
  7.   ISLink: IShellLink;
  8.   IPFile: IPersistFile;
  9. begin
  10.   IObject := CreateComObject(CLSID_ShellLink);
  11.   ISLink := IObject as IShellLink;
  12.   IPFile := IObject as IPersistFile;
  13.   ISLink.SetPath(PChar(Target));
  14.   ISLink.SetArguments(PChar(TargetArguments));
  15.   ISLink.SetWorkingDirectory(PChar(WorkDir));
  16.   ISLink.SetDescription(PChar(Description));
  17.   ISLink.SetIconLocation(PChar(IconPath), IconIndex);
  18.   IPFile.Save(PWChar(LinkName), False);
  19. end;

rca

  • Jr. Member
  • **
  • Posts: 88
Re: (Re)Create .desktop file using Project Options?
« Reply #11 on: June 24, 2024, 07:42:21 pm »
Or you can check out the source code for fpcupdeluxe, which creates desktop shortcuts within Windows, Linux, or Mac Os.
https://github.com/LongDirtyAnimAlf/fpcupdeluxe/blob/fdef17b59377fe6a0b113c9a685781410aca6d20/sources/fpcuputil.pas#L994

Code: Pascal  [Select][+][-]
  1. {$IFDEF MSWINDOWS}
  2. procedure CreateDesktopShortCut(const Target, TargetArguments, ShortcutName: string; const AddContext:boolean);
  3. var
  4.   IObject: IUnknown;
  5.   ISLink: IShellLink;
  6.   IPFile: IPersistFile;
  7.   PIDL: PItemIDList;
  8.   InFolder: array[0..MAX_PATH] of Char;
  9.   LinkName: WideString;
  10. begin
  11.   { Creates an instance of IShellLink }
  12.   IObject := CreateComObject(CLSID_ShellLink);
  13.   ISLink := IObject as IShellLink;
  14.   IPFile := IObject as IPersistFile;
  15.  
  16.   ISLink.SetPath(pChar(Target));
  17.   ISLink.SetArguments(pChar(TargetArguments));
  18.   ISLink.SetWorkingDirectory(pChar(ExtractFilePath(Target)));
  19.  
  20.   { Get the desktop location }
  21.   SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);
  22.   SHGetPathFromIDList(PIDL, InFolder);
  23.   LinkName := IncludeTrailingPathDelimiter(InFolder) + ShortcutName+'.lnk';
  24.  
  25.   { Get rid of any existing shortcut first }
  26.   SysUtils.DeleteFile(LinkName);
  27.  
  28.   { Create the link }
  29.   IPFile.Save(PWChar(LinkName), false);
  30. end;
  31. {$ELSE}
  32. {$IFDEF DARWIN}
  33. procedure CreateDesktopShortCut(const Target, TargetArguments, ShortcutName: string; const AddContext:boolean);
  34. begin
  35.   // Create shortcut on Desktop and in Applications
  36.   fpSystem(
  37.     '/usr/bin/osascript << EOF'+#10+
  38.     'tell application "Finder"'+#10+
  39.       'set myLazApp to POSIX file "'+IncludeLeadingPathDelimiter(Target)+'.app" as alias'+#10+
  40.       'try'+#10+
  41.           'set myLazDeskShort to (path to desktop folder as string) & "'+ShortcutName+'" as alias'+#10+
  42.           'on error'+#10+
  43.              'make new alias to myLazApp at (path to desktop folder as text)'+#10+
  44.              'set name of result to "'+ShortcutName+'"'+#10+
  45.       'end try'+#10+
  46.       'try'+#10+
  47.           'set myLazAppShort to (path to applications folder as string) & "'+ShortcutName+'" as alias'+#10+
  48.           'on error'+#10+
  49.              'make new alias to myLazApp at (path to applications folder as text)'+#10+
  50.              'set name of result to "'+ShortcutName+'"'+#10+
  51.       'end try'+#10+
  52.  
  53.     'end tell'+#10+
  54.     'EOF');
  55. end;
  56. {$ELSE}
  57. {$IFDEF UNIX}
  58. procedure CreateDesktopShortCut(const Target, TargetArguments, ShortcutName: string; const AddContext:boolean);
  59. var
  60.   OperationSucceeded: boolean;
  61.   XdgDesktopContent: TStringList;
  62.   XdgMimeContent: TStringList;
  63.   Output,XdgDesktopFile,XdgMimeFile: string;
  64.   aDirectory:string;
  65.   aIconFile:string;
  66. begin
  67.   {$ifdef Haiku}
  68.   exit;
  69.   {$endif}
  70.  
  71.   // Fail by default:
  72.   OperationSucceeded:=false;
  73.  
  74.   XdgDesktopFile:=IncludeTrailingPathDelimiter(GetTempDir(false))+'fpcup-'+shortcutname+'.desktop';
  75.   XdgDesktopContent:=TStringList.Create;
  76.   try
  77.     XdgDesktopContent.Add('[Desktop Entry]');
  78.     XdgDesktopContent.Add('Version=1.0');
  79.     XdgDesktopContent.Add('Encoding=UTF-8');
  80.     XdgDesktopContent.Add('Type=Application');
  81.     aIconFile:='';
  82.     {$ifdef LINUX}
  83.     aIconFile:=ExtractFilePath(Target)+'images/icons/lazarus128x128.png';
  84.     if (NOT FileExists(aIconFile)) then aIconFile:=ExtractFilePath(Target)+'images/icons/lazarus32x32.png';
  85.     if (NOT FileExists(aIconFile)) then aIconFile:=ExtractFilePath(Target)+'images/icons/lazarus.png';
  86.     {$endif}
  87.     if (Length(aIconFile)=0) OR (NOT FileExists(aIconFile)) then aIconFile:=ExtractFilePath(Target)+'images/icons/lazarus.ico';
  88.     XdgDesktopContent.Add('Icon='+aIconFile);
  89.     XdgDesktopContent.Add('Path='+ExtractFilePath(Target));
  90.     {$ifdef DISABLE_PPC_CONFIG_PATH}
  91.     XdgDesktopContent.Add('Exec=env -u PPC_CONFIG_PATH '+Target+' '+TargetArguments+' %f');
  92.     {$else}
  93.     XdgDesktopContent.Add('Exec='+Target+' '+TargetArguments+' %f');
  94.     {$endif}
  95.     XdgDesktopContent.Add('Name='+ShortcutName);
  96.     XdgDesktopContent.Add('GenericName=Lazarus IDE with Free Pascal Compiler');
  97.     XdgDesktopContent.Add('Category=Application;IDE;Development;GUIDesigner;Programming;');
  98.     XdgDesktopContent.Add('Categories=Application;IDE;Development;GUIDesigner;Programming;');
  99.     XdgDesktopContent.Add('Keywords=editor;Pascal;IDE;FreePascal;fpc;Design;Designer;');
  100.  
  101.     if AddContext then
  102.     begin
  103.       //XdgDesktopContent.Add('StartupWMClass=Lazarus');
  104.       XdgDesktopContent.Add('MimeType=application/x-lazarus;');
  105.       //XdgDesktopContent.Add('Patterns=*.pas;*.pp;*.p;*.inc;*.lpi;*.lpk;*.lpr;*.lfm;*.lrs;*.lpl;');
  106.     end;
  107.  
  108.     // We're going to try and call xdg-desktop-icon/menu
  109.     // this may fail if shortcut exists already
  110.     try
  111.       XdgDesktopContent.SaveToFile(XdgDesktopFile);
  112.       FpChmod(XdgDesktopFile, &711); //rwx--x--x
  113.       OperationSucceeded:=RunCommand('xdg-desktop-icon' ,['install','--novendor',XdgDesktopFile],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF});
  114.       OperationSucceeded:=RunCommand('xdg-desktop-menu' ,['install','--novendor',XdgDesktopFile],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF});
  115.     except
  116.       OperationSucceeded:=false;
  117.     end;
  118.  
  119.     if (true) then
  120.     begin
  121.       aDirectory:=ConcatPaths(['usr','share','applications']);
  122.       if ( (FpGeteuid=0) AND DirectoryExists(aDirectory) ) then
  123.       begin
  124.         FileCopy(XdgDesktopFile,aDirectory+DirectorySeparator+ExtractFileName(XdgDesktopFile),[]);
  125.       end
  126.       else
  127.       begin
  128.         // Create shortcut directly on User-Desktop
  129.         aDirectory:=ConcatPaths([GetUserDir,'Desktop']);
  130.         if DirectoryExists(aDirectory) then
  131.            FileCopy(XdgDesktopFile,aDirectory+DirectorySeparator+ExtractFileName(XdgDesktopFile),[]);
  132.         // Create user menu item
  133.         if (NOT OperationSucceeded) then
  134.         begin
  135.           aDirectory:=ConcatPaths([GetUserDir,'.local','share','applications']);
  136.           if DirectoryExists(aDirectory) then
  137.             FileCopy(XdgDesktopFile,aDirectory+DirectorySeparator+ExtractFileName(XdgDesktopFile),[]);
  138.         end;
  139.       end;
  140.     end;
  141.     // Temp file is no longer needed....
  142.     try
  143.       SysUtils.DeleteFile(XdgDesktopFile);
  144.     finally
  145.       // Swallow, let filesystem maintenance clear it up
  146.     end;
  147.   finally
  148.     XdgDesktopContent.Free;
  149.     OperationSucceeded:=true;
  150.   end;
  151.  
  152.   if (OperationSucceeded) then
  153.   begin
  154.     aDirectory:=ConcatPaths([GetUserDir,'.local','share','applications']);
  155.     OperationSucceeded:=RunCommand('update-desktop-database' ,[aDirectory],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF});
  156.   end;
  157.  
  158.   if AddContext then
  159.   begin
  160.     ThreadLog('Adding context !');
  161.     {$ifdef LCL}
  162.     Application.ProcessMessages;
  163.     {$endif}
  164.  
  165.     aDirectory:=ConcatPaths([GetUserDir,'.local','share','mime']);
  166.     ForceDirectoriesSafe(aDirectory);
  167.  
  168.     //Create mime file associations
  169.     XdgMimeFile:=IncludeTrailingPathDelimiter(GetTempDir(false))+'fpcup-'+shortcutname+'.xml';
  170.     XdgMimeContent:=TStringList.Create;
  171.     try
  172.       XdgMimeContent.Add('<?xml version="1.0" encoding="UTF-8"?>');
  173.       XdgMimeContent.Add('<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">');
  174.       XdgMimeContent.Add('    <mime-type type="application/x-lazarus">');
  175.       XdgMimeContent.Add('        <comment>Lazarus file</comment>');
  176.       XdgMimeContent.Add('        <icon name="application-x-lazarus"/>');
  177.       XdgMimeContent.Add('        <glob-deleteall/>');
  178.       XdgMimeContent.Add('        <glob pattern="*.lpi"/>');
  179.       XdgMimeContent.Add('        <glob pattern="*.lpr"/>');
  180.       XdgMimeContent.Add('        <glob pattern="*.lfm"/>');
  181.       XdgMimeContent.Add('        <glob pattern="*.pas"/>');
  182.       XdgMimeContent.Add('        <glob pattern="*.pp"/>');
  183.       XdgMimeContent.Add('        <glob pattern="*.inc"/>');
  184.       XdgMimeContent.Add('    </mime-type>');
  185.       XdgMimeContent.Add('</mime-info>');
  186.       aDirectory:=ConcatPaths([GetUserDir,'.local','share','mime','packages']);
  187.       ForceDirectoriesSafe(aDirectory);
  188.       XdgMimeContent.SaveToFile(XdgMimeFile);
  189.       OperationSucceeded:=RunCommand('xdg-mime' ,['install','--novendor',XdgMimeFile],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF});
  190.       SysUtils.DeleteFile(XdgMimeFile);
  191.     finally
  192.       XdgMimeContent.Free;
  193.     end;
  194.  
  195.     //Process icon
  196.     aDirectory:=ConcatPaths([GetUserDir,'.local','share','icons']);
  197.     ForceDirectoriesSafe(aDirectory);
  198.     //OperationSucceeded:=RunCommand('xdg-icon-resource' ,['install','--novendor','--context','mimetypes','--size','64',ExtractFilePath(Target)+'images/icons/lazarus.ico','application-x-lazarus'],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF});
  199.     OperationSucceeded:=RunCommand('xdg-icon-resource' ,['install','--novendor','--context','mimetypes','--size','64',ExtractFilePath(Target)+'images/icons/lazarus64x64.png','application-x-lazarus'],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF});
  200.  
  201.     //Update mime database
  202.     aDirectory:=ConcatPaths([GetUserDir,'.local','share','mime']);
  203.     OperationSucceeded:=RunCommand('update-mime-database' ,[aDirectory],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF});
  204.   end;
  205.  
  206. end;
  207. {$ELSE}
  208. procedure CreateDesktopShortCut(const Target, TargetArguments, ShortcutName: string; const AddContext:boolean);
  209. begin
  210.   ThreadLog('Not creating desktop shortcut: don''t know how to do this.');
  211. end;
  212. {$ENDIF UNIX}
  213. {$ENDIF DARWIN}
  214. {$ENDIF MSWINDOWS}
  215.  

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: (Re)Create .desktop file using Project Options?
« Reply #12 on: June 25, 2024, 01:02:27 am »
Or you can check out the source code for fpcupdeluxe, which creates desktop shortcuts within Windows, Linux, or Mac Os.
https://github.com/LongDirtyAnimAlf/fpcupdeluxe/blob/fdef17b59377fe6a0b113c9a685781410aca6d20/sources/fpcuputil.pas#L994

Thanks for the link. More to consider.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: (Re)Create .desktop file using Project Options?
« Reply #13 on: June 26, 2024, 08:30:39 pm »
After some reflection, I am leaning towards making this a stand-alone tool. I created a prototype. (See attached).

Not ready to share code yet. It's not complete.

Comments?

Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

rca

  • Jr. Member
  • **
  • Posts: 88
Re: (Re)Create .desktop file using Project Options?
« Reply #14 on: June 29, 2024, 07:09:32 am »
After some reflection, I am leaning towards making this a stand-alone tool. I created a prototype. (See attached).

Not ready to share code yet. It's not complete.

Comments?

Looks great!

Have you thought about making it work also on Windows and Mac OS?

IMHO, as far as possible most fields should be filled with default values, including the icon field... (one can be provided initially)

 

TinyPortal © 2005-2018