秋·风

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

加上下面的代码后,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; 
posted on 2021-10-13 11:45  秋·风  阅读(461)  评论(0编辑  收藏  举报