如何为我们snap包里的每个应用生产相应的desktop文件

我们知道在一个snap包里,我们可以定义任何数量的app.针对desktop应用来说,那么我们如何使得我们的每个应用都有自己的icon及desktop文件呢?在今天的文章中,我们将介绍如何实现这个.特别注意的是,这个新的feature只有在snapcraft 2.25+版本中才可以有.


首先,我们来看一下我已经做好的一个项目:

https://github.com/liu-xiao-guo/helloworld-desktop

整个应用的文件架构如下:

liuxg@liuxg:~/snappy/desktop/helloworld-desktop$ tree -L 3
.
├── bin
│   ├── createfile
│   ├── createfiletohome
│   ├── echo
│   ├── env
│   ├── evil
│   ├── sh
│   └── writetocommon
├── echo.desktop
├── README.md
├── setup
│   └── gui
│       ├── echo.png
│       ├── helloworld.desktop
│       └── helloworld.png
└── snapcraft.yaml

从上面我们可以看出来,我们已经有一个叫做setup/gui的目录.它里面包含了一个叫做helloworld.desktop的文件:

helloworld.desktop

[Desktop Entry]
Type=Application
Name=Hello
GenericName=Hello world
Comment=A hello world Ubuntu Desktop
Keywords=hello;world;
Exec=hello-xiaoguo.env
Icon=${SNAP}/meta/gui/helloworld.png
Terminal=true
X-Ubuntu-Touch=false
X-Ubuntu-Default-Department-ID=accessories
X-Ubuntu-Splash-Color=#F5F5F5
StartupNotify=true

在这里它指定了这个应用的icon及执行的脚本hello-xiaoguo.env.

我们再来看看我们的snapcraft.yaml文件:

snapcraft.yaml

name: hello-xiaoguo
version: "1.0"
summary: The 'hello-world' of snaps
description: |
    This is a simple snap example that includes a few interesting binaries
    to demonstrate snaps and their confinement.
    * hello-world.env  - dump the env of commands run inside app sandbox
    * hello-world.evil - show how snappy sandboxes binaries
    * hello-world.sh   - enter interactive shell that runs in app sandbox
    * hello-world      - simply output text
grade: stable
confinement: strict
type: app  #it can be gadget or framework

apps:
 env:
   command: bin/env
 evil:
   command: bin/evil
 sh:
   command: bin/sh
 hello-world:
   command: bin/echo
   desktop: usr/share/applications/echo.desktop
 createfile:
   command: bin/createfile
 createfiletohome:
   command: bin/createfiletohome
 writetocommon:
   command: bin/writetocommon

plugs:
    home:
        interface: home

parts:
 hello:
  plugin: dump
  source: .
  organize:
    echo.desktop: usr/share/applications/echo.desktop

在这个文件中,我们也定义了其它的应用,比如hello-world.那么我们如何为它也定义自己的desktop文件呢?答案是:

 hello-world:
   command: bin/echo
   desktop: usr/share/applications/echo.desktop

我们可以在它的command下面指定一个属于自己的desktop文件.在这里我们的echo.desktop文件如下:

echo.desktop

[Desktop Entry]
Type=Application
Name=Echo
GenericName=Hello world
Comment=A hello world Ubuntu Desktop
Keywords=hello;world;
Exec=hello-xiaoguo.hello-world
Icon=${SNAP}/meta/gui/echo.png
Terminal=true
X-Ubuntu-Touch=false
X-Ubuntu-Default-Department-ID=accessories
X-Ubuntu-Splash-Color=#F5F5F5
StartupNotify=true

在这里它指定了自己的执行文件及一个属于自己的icon.我们打包我们的应用,并安装.在Ubuntu Desktop的dash中,我们可以看到:



运行"Hello World"应用显示:



运行我们的"echo"应用:








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值