Lazarus Linux 建立選單及桌面快捷方式
阿新 • • 發佈:2021-10-13
Lazarus 編譯的程式執行時會自動建立選單及桌面快捷方式,在中標麒麟和樹莓派測試使用正常,在選單的快捷方式可直接開啟應用,沒有下圖的提示。
1 {$ifdef LINUX} 2 uses 3 process, 4 BaseUnix; 5 {$endif LINUX} 6 7 procedure TClientForm.FormCreate(Sender: TObject); 8 var 9 inif: Tinifile; 10 edtIP, edtPort, edtUser, edtPassword: string; 11 vFileName: string; 12 aDirectory,Output: string; 13 iniFile: TIniFile; 14 begin 15 {$IFDEF UNIX} 16 aDirectory := ConcatPaths([GetUserDir, '.local', 'share', 'applications']); 17 if DirectoryExists(aDirectory) then 18 // FileUtil.CopyFile(XdgDesktopFile,aDirectory+DirectorySeparator+ExtractFileName(XdgDesktopFile),[]);19 20 try 21 if DirectoryExists(aDirectory) then 22 begin 23 vFileName := aDirectory + DirectorySeparator + ExtractFileName('回彈檢測.desktop'); 24 IniFile := TIniFile.Create(vFileName); 25 try 26 iniFile.WriteString('Desktop Entry', 'Encoding', 'UTF-8'); 27 iniFile.WriteString('Desktop Entry', 'Name', '回彈檢測'); 28 iniFile.WriteString('Desktop Entry', 'Comment', '回彈檢測計算軟體'); 29 //說明 30 iniFile.WriteString('Desktop Entry', 'Exec', Format('"%s"', [ParamStr(0)])); 31 iniFile.WriteString('Desktop Entry', 'Type', 'Application'); 32 iniFile.WriteString('Desktop Entry', 'GenericName', '回彈檢測'); 33 iniFile.WriteString('Desktop Entry', 'Category','工程檢測;');//Development;GUIDesigner;Programming;'); 34 iniFile.WriteString('Desktop Entry', 'Categories','工程檢測;');//Development;GUIDesigner;Programming;'); 35 iniFile.WriteString('Desktop Entry', 'Terminal', 'false'); 36 iniFile.WriteString('Desktop Entry', 'Icon', ExtractFilePath(ParamStr(0)) + 37 '回彈檢測.png'); 38 finally 39 IniFile.Free; 40 end; 41 FpChmod(vFileName, &755); 42 43 aDirectory:=ConcatPaths([GetUserDir,'.local','share','applications']); 44 RunCommand('update-desktop-database' ,[aDirectory],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF}); 45 46 //拷貝"回彈檢測.desktop"到桌面,並設定為“可執行” 47 aDirectory:=ConcatPaths([GetUserDir,'桌面']); 48 if not DirectoryExists(aDirectory) then 49 aDirectory:=ConcatPaths([GetUserDir,'Desktop']); 50 FileUtil.CopyFile(vFileName,aDirectory+DirectorySeparator+ExtractFileName(vFileName),[]); 51 FpChmod(aDirectory+DirectorySeparator+ExtractFileName(vFileName), &755); 52 end; 53 except 54 end; 55 {$ENDIF} 56 end; 57