How to produce the appropriate desktop file for each app in our snap package

Source: Internet
Author: User
Tags touch

We know that in a snap package, we can define any number of apps. For desktop applications, how do we make each of our apps have its own icon and desktop files? In today's article, we'll show you how to implement this. It is particularly important to note that this new feature is available only in the Snapcraft 2.25+ version.


First, let's take a look at one of the projects I've done:

Https://github.com/liu-xiao-guo/helloworld-desktop the file schema for the entire application is as follows:

liuxg@liuxg:~/snappy/desktop/helloworld-desktop$ tree-l 3
.
├──bin
│├──createfile
│├──createfiletohome
│├──echo
│├──env
│├──evil
│├── SH
│└──writetocommon
├──echo.desktop
├──readme.md
├──setup
│└──gui
│     ├──ec Ho.png
│     ├──helloworld.desktop
│     └──helloworld.png
└──snapcraft.yaml

From the above we can see that we already have a directory called Setup/gui. It contains a file called 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

Here it specifies the app's icon and the executed script hello-xiaoguo.env.
Let's take a look at our Snapcraft.yaml file: Snapcraft.yaml
Name:hello-xiaoguo version: "1.0" summary:the ' hello-world ' of snaps description: |
    This was a simple snap example, 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 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.des Ktop createfile:command:bin/createfile createfiletohome:command:bin/createfiletohome Writetocommon:comman
  D:bin/writetocommon plugs:home:interface:home parts:hello:plugin:dump Source:. Organize:echo.desktop:usr/share/applications/echo.desktop

In this file, we also define other applications, such as Hello-world. So how do we define our own desktop file for it too? The answer is:
Hello-world:
   command:bin/echo
   desktop:usr/share/applications/echo.desktop

We can specify a desktop file that belongs to itself under its command. Here our Echo.desktop file is as follows: 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

Here it specifies its own execution file and an icon that belongs to itself. We pack our apps and install them. In the Ubuntu Desktop Dash, we can see:


Run the "Hello World" app display:


Run our "echo" app:







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.