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
:只允许该应用的一个实例
运行这条命令显示了以下输出。
Preparing Electron app...
Converting icons...
Packaging... This will take a few seconds, maybe minutes if the requested Electron isn't cached yet...
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)
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的文件。这是启动该应用程序的主要可执行文件。在你启动它之前,你必须给它适当的权限。
$ cd Mastodon-linux-x64
chmod +x Mastodon
现在,执行./Mastodon
,就可以看到你的Linux应用程序启动了
为我的博客创建一个应用程序
为了好玩,我也要为我的博客网站创建一个应用程序。如果没有Linux应用程序,拥有一个技术博客有什么用呢?
这个命令。
$ nativefier -n ayushsharma \
-p linux -a x64 \
--width 1024 --height 768 \
--tray --disable-dev-tools \
--single-instance https://ayushsharma.in
$ cd ayushsharma-linux-x64
chmod +x ayushsharma
为findmymastodon.com创建一个应用程序
最后,这是为我的宠物项目findmymastodon.com创建的应用程序。
该命令。
$ nativefier -n findmymastodon \
-p linux -a x64 \
--width 1024 --height 768 \
--tray --disable-dev-tools \
--single-instance https://findmymastodon.com
$ cd findmymastodon-linux-x64
chmod +x findmymastodon
创建Linux桌面图标
随着应用程序的创建和可执行文件的准备,现在是创建桌面图标的时候了。
作为示范,这里是如何为Mastodon启动器创建一个桌面图标。首先,下载一个Mastodon的图标。将该图标放在其Nativefier应用目录下,作为icon.png
。
然后创建一个名为Mastodon.desktop
的文件,并输入这个文本。
[Desktop Entry]
Type=Application
Name=Mastodon
Path=/home/tux/NativeApps/Mastodon-linux-x64
Exec=/home/tux/NativeApps/Mastodon-linux-x64/Mastodon
Icon=/home/tux/NativeApps/Mastodon-linux-x64/icon.png
你可以把.desktop
文件移到你的Linux桌面上,让它作为一个桌面启动器。你也可以把它的副本放在~/.local/share/applications
,这样它就会显示在你的应用程序菜单或活动启动器中。
总结
我喜欢为我经常使用的工具配备专用的应用程序。我最喜欢为Mastodon准备的应用程序的特点是,一旦我登录到Mastodon,我就不必再去登录了Nativefier在下面运行Chromium。所以它能够像其他浏览器一样记住你的会话。我想特别感谢Nativefier团队,他们让Linux桌面离完美更近了一步。
本文最初出现在作者的网站上,经授权转载。