加上下面的代码后,Lazarus 编译的程序运行时会自动创建菜单及桌面快捷方式,在菜单的快捷方式可直接打开应用(在中标麒麟和树莓派测试使用正常),还解决了每次运行时都会出现下图提示的问题。
1 {$ifdef LINUX} 2 uses 3 process, 4 BaseUnix; 5 {$endif LINUX} 6 7 procedure TClientForm.FormCreate(Sender: TObject); 8 var 9 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 try 19 if DirectoryExists(aDirectory) then 20 begin 21 vFileName := aDirectory + DirectorySeparator + ExtractFileName('回弹检测.desktop'); 22 IniFile := TIniFile.Create(vFileName); 23 try 24 iniFile.WriteString('Desktop Entry', 'Encoding', 'UTF-8'); 25 iniFile.WriteString('Desktop Entry', 'Name', '回弹检测'); 26 iniFile.WriteString('Desktop Entry', 'Comment', '回弹检测计算软件'); 27 iniFile.WriteString('Desktop Entry', 'Exec', Format('"%s"', [ParamStr(0)])); 28 iniFile.WriteString('Desktop Entry', 'Type', 'Application'); 29 iniFile.WriteString('Desktop Entry', 'GenericName', '回弹检测'); 30 iniFile.WriteString('Desktop Entry', 'Category','工程检测;'); 31 iniFile.WriteString('Desktop Entry', 'Categories','工程检测;'); 32 iniFile.WriteString('Desktop Entry', 'Terminal', 'false'); 33 iniFile.WriteString('Desktop Entry', 'Icon', ExtractFilePath(ParamStr(0)) +'回弹检测.png'); 34 finally 35 IniFile.Free; 36 end; 37 FpChmod(vFileName, &755); 38 aDirectory:=ConcatPaths([GetUserDir,'.local','share','applications']); 39 RunCommand('update-desktop-database' ,[aDirectory],Output,[poUsePipes, poStderrToOutPut]{$IF DEFINED(FPC_FULLVERSION) AND (FPC_FULLVERSION >= 30200)},swoHide{$ENDIF}); 40 //拷贝"回弹检测.desktop"到桌面,并设置为“可执行” 41 aDirectory:=ConcatPaths([GetUserDir,'桌面']); 42 if not DirectoryExists(aDirectory) then 43 aDirectory:=ConcatPaths([GetUserDir,'Desktop']); 44 FileUtil.CopyFile(vFileName,aDirectory+DirectorySeparator+ExtractFileName(vFileName),[]); 45 FpChmod(aDirectory+DirectorySeparator+ExtractFileName(vFileName), &755);//FpChmod需要在uses添加BaseUnix 46 end; 47 except 48 end; 49 {$ENDIF} 50 end;
分类:
Raspberry Pi
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~