运用Ubuntu Core所提供的xdg-open打开我们需要的文件或网址

如果我们打开我们的Ubuntu Core安装的Core应用,在这个Core应用的安装目录中,我们会发现一个应用叫做xdg-open:

/snap/core/current/usr/local/bin$ ls
apt  apt-cache  apt-get  no-apt  xdg-open

关于xdg-open的更多描述可以在地址: https://linux.die.net/man/1/xdg-open找到。我们可以利用它来打开我们的所需要的文件或url。现在我们来利用它来启动一个应用,比如一个网站。为此,我们的snapcraft.yaml文件如下:


snapcraft.yaml


name: google
version: "1"
summary: this is a test program for launching a website using browser
description: |
     Launch google website using xdg-open
grade: stable
confinement: strict
architectures: [amd64]

apps:
   google:
     command: run.sh "http://www.google.com"
     plugs: [network, network-bind, x11, home, unity7, gsettings]

parts:
   files:
    plugin: dump
    source: scripts
    organize:
     run.sh: bin/run.sh

   integration:
    plugin: nil
    after: [desktop-gtk2]


scripts

#!/bin/sh

PATH="$PATH:/usr/local/bin"

xdg-open $1

我在Ubuntu Desktop上安装一个debian包:

$ sudo apt install snapd-xdg-open

打包完我们的应用并安装,运行:

$ google

运用Ubuntu Core所提供的xdg-open打开我们需要的文件或网址_第1张图片

我们可以看出google网站被成功启动。
整个项目的源码在: https://github.com/liu-xiao-guo/launchwebsite


你可能感兴趣的:(Ubuntu,Core)