使用 Nativefier 和 Electron 从任何网站创建桌面应用。
Mastodon 是一个很好的开源、去中心化的社交网络。我每天都在使用 Mastodon,通过它的网页界面使用 Mastodon 可能是最常见的方式(尽管因为开源,它有许多不同的交互方式,包括基于终端的应用和移动应用),但我更喜欢专门的应用窗口。
最近,我发现了 Nativefier,现在我可以在我的 Linux 桌面上把 Mastodon 或其他任何网页应用作为桌面应用来使用。Nativefier 将一个 URL 用 Electron 框架包装起来,它将开源的 Chromium 浏览器作为后端,但使用自己的可执行程序运行。Nativefier 采用 MIT 许可证,可用于 Linux、Windows 和 MacOS。
安装 Nativefier
Nativefier 需要 Node.js。
安装 Nativefier 只需运行:
$ sudo npm install -g nativefier
在我的 Ubuntu 桌面上,我必须先升级 NodeJS,所以当你安装 Nativefier 时,一定要检查需要哪个 Node 版本。
安装完毕后,你可以检查你的 Nativefier 的版本,以验证它是否已经安装:
$ nativefier --version
45.0.4
运行 nativefier --help 列出了应用支持的所有选项。
设置
我建议你在开始用 Nativefier 创建应用之前,创建一个名为 ~/NativeApps 的新文件夹。这有助于保持你的应用有序。
$ mkdir ~/NativeApps
cd ~/NativeApps
为 Mastodon 创建一个应用程序
我将首先为 mastodon.technology 创建一个应用。
使用以下命令:
$ nativefier --name Mastodon \
--platform linux --arch x64 \
--width 1024 --height 768 \
--tray --disable-dev-tools \
--single-instance https://mastodon.technology
这个例子中的选项做了以下工作:
--name:设置应用的名称为 Mastodon
--platform:设置应用程序的平台为 Linux
--arch x64:设置架构为 x64
--width 1024 --height 768:设置应用启动时的大小
--tray:为应用创建一个托盘图标
--disable-dev-tools:禁用 Chrome 开发工具
--single-instance:只允许应用有一个实例
大型站长资讯类网站! https://www.0518zz.cn