@geekpi
https://linux.cn/article-13975-1.html
This commit is contained in:
Xingyu Wang 2021-11-11 11:53:59 +08:00
parent 2f31de6642
commit 8ba74c37c7

View File

@ -3,18 +3,20 @@
[#]: author: "Ayush Sharma https://opensource.com/users/ayushsharma" [#]: author: "Ayush Sharma https://opensource.com/users/ayushsharma"
[#]: collector: "lujun9972" [#]: collector: "lujun9972"
[#]: translator: "geekpi" [#]: translator: "geekpi"
[#]: reviewer: " " [#]: reviewer: "wxy"
[#]: publisher: " " [#]: publisher: "wxy"
[#]: url: " " [#]: url: "https://linux.cn/article-13975-1.html"
用开源工具将任何网站变成 Linux 桌面应用 用开源工具将任何网站变成 Linux 桌面应用
====== ======
使用 Nativefier 和 Electron 从任何网站创建桌面应用。
![Text editor on a browser, in blue][1]
Mastodon 是一个很好的开源、去中心化的社交网络。我每天都在使用 Mastodon通过它的网页界面使用 Mastodon 可能是最常见的(尽管因为开源,它有许多不同的交互方式,包括基于终端的应用和移动应用),但我更喜欢专门的应用窗口 > 使用 Nativefier 和 Electron 从任何网站创建桌面应用。
最近,我发现了 [Nativefier][2],现在我可以在我的 Linux 桌面上把 Mastodon 或其他任何网络应用作为桌面应用来使用。Nativefier 将一个 URL 用 Electron 框架包装起来,它将开源的 Chromium 浏览器作为后端但使用自己的可执行程序运行。Nativefier 获得了 MIT 许可,可用于 Linux、Windows 和 MacOS。 ![](https://img.linux.net.cn/data/attachment/album/202111/11/115302e25o5laz8sex5ea6.jpg)
Mastodon 是一个很好的开源、去中心化的社交网络。我每天都在使用 Mastodon通过它的网页界面使用 Mastodon 可能是最常见的方式(尽管因为开源,它有许多不同的交互方式,包括基于终端的应用和移动应用),但我更喜欢专门的应用窗口。
最近,我发现了 [Nativefier][2],现在我可以在我的 Linux 桌面上把 Mastodon 或其他任何网页应用作为桌面应用来使用。Nativefier 将一个 URL 用 Electron 框架包装起来,它将开源的 Chromium 浏览器作为后端但使用自己的可执行程序运行。Nativefier 采用 MIT 许可证,可用于 Linux、Windows 和 MacOS。
### 安装 Nativefier ### 安装 Nativefier
@ -22,16 +24,14 @@ Nativefier 需要 Node.js。
安装 Nativefier 只需运行: 安装 Nativefier 只需运行:
``` ```
`$ sudo npm install -g nativefier` $ sudo npm install -g nativefier
``` ```
在我的 Ubuntu 桌面上,我必须先升级 NodeJS所以当你安装 Nativefier 时,一定要检查需要哪个 Node 版本。 在我的 Ubuntu 桌面上,我必须先升级 NodeJS所以当你安装 Nativefier 时,一定要检查需要哪个 Node 版本。
安装完毕后,你可以检查你的 Nativefier 的版本,以验证它是否已经安装: 安装完毕后,你可以检查你的 Nativefier 的版本,以验证它是否已经安装:
``` ```
$ nativefier --version $ nativefier --version
45.0.4 45.0.4
@ -43,7 +43,6 @@ $ nativefier --version
我建议你在开始用 Nativefier 创建应用之前,创建一个名为 `~/NativeApps` 的新文件夹。这有助于保持你的应用有序。 我建议你在开始用 Nativefier 创建应用之前,创建一个名为 `~/NativeApps` 的新文件夹。这有助于保持你的应用有序。
``` ```
$ mkdir ~/NativeApps $ mkdir ~/NativeApps
cd ~/NativeApps cd ~/NativeApps
@ -55,30 +54,26 @@ cd ~/NativeApps
使用以下命令: 使用以下命令:
``` ```
$ nativefier --name Mastodon \ $ nativefier --name Mastodon \
\--platform linux --arch x64 \ --platform linux --arch x64 \
\--width 1024 --height 768 \ --width 1024 --height 768 \
\--tray --disable-dev-tools \ --tray --disable-dev-tools \
\--single-instance <https://mastodon.technology> --single-instance https://mastodon.technology
``` ```
这个例子中的选项做了以下工作: 这个例子中的选项做了以下工作:
* `--name`:设置应用的名称为 Mastodon * `--name`:设置应用的名称为 Mastodon
* `--platform`:设置应用程序的平台为 Linux * `--platform`:设置应用程序的平台为 Linux
* `---arch x64`:设置架构为 x64 * `--arch x64`:设置架构为 x64
* `--width 1024 --height 768`:设置应用启动时的大小 * `--width 1024 --height 768`:设置应用启动时的大小
* `--tray`:为应用创建一个托盘图标 * `--tray`:为应用创建一个托盘图标
* `--disable-dev-tools`:禁用 Chrome 开发工具 * `--disable-dev-tools`:禁用 Chrome 开发工具
* `--single-instance`:只允许应用有一个实例 * `--single-instance`:只允许应用有一个实例
运行这条命令会显示以下输出: 运行这条命令会显示以下输出:
``` ```
Preparing Electron app... Preparing Electron app...
@ -88,10 +83,10 @@ Packaging app for platform linux x64 using electron v13.4.0 Finalizing build...
App built to /home/tux/NativeApps/Mastodon-linux-x64, move to wherever it makes sense for you and run the contained executable file (prefixing with ./ if necessary) App built to /home/tux/NativeApps/Mastodon-linux-x64, move to wherever it makes sense for you and run the contained executable file (prefixing with ./ if necessary)
Menu/desktop shortcuts are up to you, because Nativefier cannot know where you're going to move the app. Search for "linux .desktop file" for help, or see <https://wiki.archlinux.org/index.php/Desktop\_entries> Menu/desktop shortcuts are up to you, because Nativefier cannot know where you're going to move the app. Search for "linux .desktop file" for help, or see https://wiki.archlinux.org/index.php/Desktop_entries
``` ```
输出显示,文件被放置在 `/home/tux/NativeApps/Mastodon-linux-x64`。当你 `cd` 进入这个文件夹,你会看到一个名为 Mastodon 的文件。这是启动该应用的主要可执行文件。在你启动它之前,你必须给它适当的权限。 输出显示,文件被放置在 `/home/tux/NativeApps/Mastodon-linux-x64`。当你 `cd` 进入这个文件夹,你会看到一个名为 `Mastodon` 的文件。这是启动该应用的主要可执行文件。在你启动它之前,你必须给它适当的权限。
``` ```
$ cd Mastodon-linux-x64 $ cd Mastodon-linux-x64
@ -102,25 +97,20 @@ chmod +x Mastodon
![Mastodon app launched][4] ![Mastodon app launched][4]
Ayush Sharma, [CC BY-SA 4.0][5]
### 为我的博客创建一个应用 ### 为我的博客创建一个应用
为了好玩,我也要为我的博客创建一个应用。如果没有 Linux 应用,拥有一个技术博客有什么用? 为了好玩,我也要为我的博客创建一个应用。如果没有 Linux 应用,拥有一个技术博客有什么用?
![Ayush Sharma blog][6] ![Ayush Sharma blog][6]
Ayush Sharma, [CC BY-SA 4.0][5]
命令是: 命令是:
``` ```
$ nativefier -n ayushsharma \ $ nativefier -n ayushsharma \
-p linux -a x64 \ -p linux -a x64 \
\--width 1024 --height 768 \ --width 1024 --height 768 \
\--tray --disable-dev-tools \ --tray --disable-dev-tools \
\--single-instance <https://ayushsharma.in> --single-instance https://ayushsharma.in
$ cd ayushsharma-linux-x64 $ cd ayushsharma-linux-x64
chmod +x ayushsharma chmod +x ayushsharma
@ -132,17 +122,14 @@ chmod +x ayushsharma
![Find my mastodon website][8] ![Find my mastodon website][8]
Ayush Sharma, [CC BY-SA 4.0][5]
命令是: 命令是:
``` ```
$ nativefier -n findmymastodon \ $ nativefier -n findmymastodon \
-p linux -a x64 \ -p linux -a x64 \
\--width 1024 --height 768 \ --width 1024 --height 768 \
\--tray --disable-dev-tools \ --tray --disable-dev-tools \
\--single-instance <https://findmymastodon.com> --single-instance https://findmymastodon.com
$ cd findmymastodon-linux-x64 $ cd findmymastodon-linux-x64
chmod +x findmymastodon chmod +x findmymastodon
@ -156,7 +143,6 @@ chmod +x findmymastodon
然后创建一个名为 `Mastodon.desktop` 的文件并输入以下文本: 然后创建一个名为 `Mastodon.desktop` 的文件并输入以下文本:
``` ```
[Desktop Entry] [Desktop Entry]
Type=Application Type=Application
@ -170,11 +156,9 @@ Icon=/home/tux/NativeApps/Mastodon-linux-x64/icon.png
### 总结 ### 总结
我喜欢为我经常使用的工具配备专门的应用。我最喜欢的一个 Mastodon 应用特点是,当我登录到 Mastodon 后,我就不必再登录了! Nativefier 在底层运行 Chromium。所以它能够像其他浏览器一样记住你的会话。我想特别感谢 Nativefier 团队,他们让 Linux 桌面离完美更近了一步。 我喜欢为我经常使用的工具配备专门的应用。我最喜欢的一个 Mastodon 应用特点是,当我登录到 Mastodon 后,我就不必再登录了! Nativefier 在底层运行 Chromium。所以它能够像其他浏览器一样记住你的会话。我想特别感谢 Nativefier 团队,他们让 Linux 桌面离完美更近了一步。
* * * 本文最初发表在 [作者的网站][10] 上,并经授权转载。
_本文最初发表在[作者的网站][10]上并经授权转载。_
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -183,7 +167,7 @@ via: https://opensource.com/article/21/11/linux-apps-nativefier
作者:[Ayush Sharma][a] 作者:[Ayush Sharma][a]
选题:[lujun9972][b] 选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi) 译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出