[[434540]] NativeFier と Electron を使用して、任意の Web サイトからデスクトップ アプリケーションを作成します。
Mastodonは素晴らしいオープンソースの分散型ソーシャルネットワークです。私はMastodonを毎日使っていますが、Webインターフェースを使うのがおそらく最も一般的な方法です(オープンソースなので、ターミナルベースやモバイルアプリケーションなど、様々な方法で操作できます)。しかし、私は専用のアプリケーションウィンドウを使うのが好きです。 最近Nativefierを発見し、Mastodonやその他のWebアプリケーションをLinuxデスクトップでデスクトップアプリケーションとして使えるようになりました。NativefierはURLをElectronフレームワークでラップし、オープンソースのChromiumブラウザをバックエンドとして利用していますが、独自の実行ファイルで動作します。NativefierはMITライセンスに基づいており、Linux、Windows、macOSで利用可能です。 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.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 DevTools を無効にする --single-instance : アプリケーションのインスタンスを 1 つだけ許可します。
このコマンドを実行すると、次の出力が表示されます。 -
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アプリケーションがないと、技術ブログを書く意味がありませんよね? Ayush Sharmaのブログ コマンドは次のとおりです。 -
$ 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 用に作成したアプリです。 私のマストドンウェブサイトを見つける コマンドは次のとおりです。 -
$ 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
アプリケーションが作成され、実行できる状態になりました。次はデスクトップ アイコンを作成します。 例として、Mastodonランチャーのデスクトップアイコンを作成する方法をご紹介します。まず、Mastodonアイコンをダウンロードします。アイコンをネイティブアプリのディレクトリ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を採用しているので、他のブラウザと同様にセッションを記憶できます。Linuxデスクトップを完璧に近づけてくれたNativefierチームに特に感謝したいと思います。 |