如何把一个website变为一个snap应用

在很多的时候,我们想把一个website变为一个snap应用,从而我们可以直接从商店里进行下载它,并直接使用.我们不需要在浏览器中输入这个网站的地址.也有很多的时候,我们的游戏就在一个网站上,比如http://hexgl.bkcore.com/play/,我们可以直接把该网址打包进我们的snap应用,从而使得它直接可以从商店下载并运行.在今天的教程中,我们来展示如何把网址的url打包到我们的应用中.

为了说明问题方便,我们使用www.sina.com.cn来进行展示:

snapcraft.yaml


name: sina-webapp
version: '1.0'
summary: Sina webapp
description: |
  Webapp version of the Sina web application.

grade: stable
confinement: strict

apps:
  sina-webapp:
    command: webapp-launcher --enable-back-forward --webappUrlPatterns=http?://www.sina.com/* http://www.sina.com/ %u
    plugs:
      - browser-sandbox
      - camera
      - network
      - network-bind
      - opengl
      - pulseaudio
      - screen-inhibit-control
      - unity7
      - network-control
      - mount-observe

plugs:
  browser-sandbox:
    interface: browser-support
    allow-sandbox: false
  platform:
    interface: content
    content: ubuntu-app-platform1
    target: ubuntu-app-platform
    default-provider: ubuntu-app-platform

parts:
  webapp-container:
    after: [desktop-ubuntu-app-platform,webapp-helper]
    stage-packages:
      - fonts-wqy-zenhei
      - fcitx-frontend-qt5
    plugin: nil

在这里,我们使用里desktop-ubuntu-app-platform cloud part.注意在这里,我们也加入了对中文字体及输入法的支持:

      - fonts-wqy-zenhei
      - fcitx-frontend-qt5

我们可以参考我先前的文章" 利用ubuntu-app-platform提供的platform接口来减小Qt应用大小"来安装并使用ubuntu-app-platform:platform.具体来说,我们必须进行如下的安装:

$ sudo snap install ubuntu-app-platform

我们在terminal中打入:
$ snapcraft
就可以把我们的应用打包为snap格式.我们使用如下的命令来进行安装:
$ sudo snap install sina-webapp_1.0_amd64.snap --dangerous
等我们安装好后,我们可以发现:

liuxg@liuxg:~$ snap list
Name                 Version  Rev  Developer  Notes
amazon-webapp        1.3      x1              -
azure                0.1      x2              -
core                 16.04.1  714  canonical  -
hello-world          6.3      27   canonical  -
sina-webapp          1.0      x1              -
snappy-debug         0.26     25   canonical  -
ubuntu-app-platform  1        22   canonical  -

我们的sian-webapp已经被成功安装好了.在这里面,我们也可以发现ubuntu-app-platform及core两个snap应用.在我们的应用中,由于我们定义了如下的plug:
  • camera
  • mount-observe
  • network-control
  • content
根据在网址 http://snapcraft.io/docs/reference/interfaces里的介绍,我们发现这些接口必须是手动连接的,所以我们必须使用如下的命令:

$ sudo snap connect sina-webapp:platform ubuntu-app-platform:platform
$ sudo snap connect sina-webapp:camera core:camera
$ sudo snap connect sina-webapp:network-control core:network-control
$ sudo snap connect sina-webapp:mount-observe core:mount-observe

通过上面的命令,我们进行了手动的连接.如果由于我们重新安装或其它原因在我们运行我们的应用时出现诸如:

You need to connect the ubuntu-app-platform package with your application   
to reuse shared assets, please run:  
snap install ubuntu-app-platform  
snap connect sina-webapp:platform ubuntu-app-platform:platform  

这样的错误信息,我们需要使用如下的工具:
$ sudo /usr/lib/snapd/snap-discard-ns sina-webapp  
来清除先前的设置,然后在重新运行我们的应用之前,我们再手动连接我们上面所列出来的接口.

我们可以在我们的Desktop的dash中找到我们的应用的图标,并运行.





整个项目的源码在: https://github.com/liu-xiao-guo/sina-webapp.我们可以使用如下的命令从商店来下载这个应用:

$ sudo snap install sina-webapp --beta




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值