Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Building Flatpak apps in Gnome Builder on Fedora Silverblue

#1
Building Flatpak apps in Gnome Builder on Fedora Silverblue

<div style="margin: 5px 5% 10px 5%;"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue.png" width="1024" height="203" title="" alt="" /></div><div><p>If you are developing software using <a href="https://silverblue.fedoraproject.org/">Fedora Silverblue</a>, and especially if what you are developing is a Gnome application, Gnome Builder 3.30.3 feels like an obvious choice of IDE.</p>
<p>In this article, I will show you how you can create a simple Gnome application, and how to build it and install it as a Flatpak app on your system.</p>
<h2>Gnome and Flatpak applications</h2>
<p>Builder has been a part of Gnome for a long time. It is a very mature IDE to me in terms of consistency and completeness.</p>
<p>The <a href="https://wiki.gnome.org/Apps/Builder">Gnome Builder project website</a> offers extensive documentation regarding Gnome application development — I highly recommend spending some time there to anyone interested.</p>
<h2>Editor’s note: Getting Builder</h2>
<p>Because the initial Fedora Silverblue installation doesn’t include Builder, let’s walk through the installation process first.</p>
<p>Starting with a freshly installed system, the first thing you’ll need to do is to enable a repository providing Builder as a Flatpak — we’ll use <a href="https://flathub.org">Flathub</a> which is a popular 3rd-party repository with many desktop apps.</p>
<p>To enable Flathub on your system, download the repository file from the <a href="https://flatpak.org/setup/Fedora/">Fedora Quick Setup</a> page, and double-click it which opens Gnome Software asking you to enable this repository on your system.</p>
<p>After you’re done with that, you can search for Builder in Gnome Software and install it.</p>
<h2>Creating a new project</h2>
<p>So let’s walk through the creation of a new project for our Gnome app. When you start Gnome Builder, the first display is oriented towards project management.</p>
<p><img class="wp-image-24872 size-large" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue.png" alt="" width="616" height="122" /></p>
<p>To create a new project, I clicked on the <em>New…</em> button at the top-left corner which showed me the following view.</p>
<p><img class="wp-image-24873 size-large" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue-1.png" alt="" width="616" height="347" /></p>
<p>You’ll need to fill out the project name, choose your preferred language (I chose C, but other languages will work for this example as well), and the license. Leave the version control on, and select Gnome Application as your template.</p>
<p>I chose <em>gbfprtfsb</em> as the name of my project which means <em>Hello from Gnome 3 on Fedora SilverBlue</em>.</p>
<p>The IDE creates and opens the project once you press create.</p>
<h2>Tweaking our new project</h2>
<p>The newly created project is opened in the Builder IDE and on my system looks like the following.</p>
<p><img class="wp-image-24876 size-large" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue-2.png" alt="" width="616" height="347" /></p>
<p>This project could be run from within the IDE right now and would give you the ever popular “Hello World!” titled gnome windowed application with a label that says, yup “Hello World!”.</p>
<p>Let’s get a little disruptive and mess up the title and greeting a bit. Complacency leads to mediocrity which leads to entropy overcoming chaos to enforce order, stasis, then finally it all just comes to a halt. It’s therefore our duty to shake it up at every opportunity, if only to knock out any latent entropy that may have accumulated in our systems. Towards such lofty goals, we only need to change two lines of one file, and the file isn’t even a C language file, it’s an XML file used to describe the GUI named <em>gbfprtfsb-window.ui</em>. All we have to do is open it and edit the title and label text, save and then build our masterpiece!</p>
<p>Looking at the screenshot below, I have circled the text we are going to replace. The window is a <em>GtkApplicationWindow</em>, and uses a <em>GtkHeaderBar</em> and <em>GtkLabel</em> to display the text we are changing. In the <em>GtkHeaderBar</em> we will type <em>GBFPRTFSB </em>for the <em>title</em> property. In the <em>GtkLabel</em> we will type <em>Hello from Gnome 3 on Fedora SilverBlue</em> in the <em>label</em> property. Now save the file to record our changes.</p>
<p><img class="aligncenter wp-image-24877 size-large" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue-3.png" alt="" width="616" height="334" /></p>
<h2>Building the project</h2>
<p>Well, we have made our changes, and expressed our individualism (cough) at the same time. All that is left is to build it and see what it looks like. The build panel is located near the top of the IDE, middle right, and is represented by the icon that appears to be a brick wall being built as shown on the following picture.</p>
<p><img class="size-full wp-image-24878" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue-4.png" alt="" width="186" height="125" /></p>
<p>Press the button, and the build process completes. You can also preview your application by clicking on the “play” button next to it.</p>
<h2>Building a Flatpak</h2>
<p>When we’re happy with our creation, the next step will be building it as a Flatpak. To do that, click on the title in the middle of the top bar, and then on the Export Bundle button.</p>
<p><img class="wp-image-24879 size-large" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue-5.png" alt="" width="616" height="347" /></p>
<p>Once the export has successfully completed, Gnome Builder will open a Nautilus file browser window showing the export directory, with the Flatpak bundle already selected.</p>
<p><img class="wp-image-24880 size-large" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue-6.png" alt="" width="616" height="347" /></p>
<p>To install the app on your system, simply double-click the icon which opens Gnome Software allowing you to install the app. On my system I had to enter my user password twice, which I take to be due to the fact we had no configured GPG key for the project. After it was installed, the application was shown alongside all of the other applications on my system. It can be seen running below.</p>
<p><img class="wp-image-24881 size-large" src="http://www.sickgaming.net/blog/wp-content/uploads/2019/02/building-flatpak-apps-in-gnome-builder-on-fedora-silverblue-7.png" alt="" width="616" height="347" /></p>
<p>I think this has successfully shown how easy it is to deploy an application as a Flatpak bundle for Gnome using Builder, and then running it on Fedora Silverblue.</p></p>
</div>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016