• Lazarus Linux 创建菜单及桌面快捷方式


    加上下面的代码后,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);
    46       end;
    47     except
    48     end;
    49 {$ENDIF}  
    50 end; 
  • 相关阅读:
    云原生网关 Kong 和Kong 管理UI 的完全安装攻略
    微服务最强开源流量网关Kong
    如何在java中判断一个字符串是否是数字
    设计模式之责任链模式讲解
    我的第一个react native
    封装缓动动画3
    封装缓动动画2
    封装缓动动画1
    获取用户选中的文字内容
    窗口事件onresize
  • 原文地址:https://www.cnblogs.com/qiufeng2014/p/15401468.html
Copyright © 2020-2023  润新知