<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: montoyaaguirre</title>
    <description>The latest articles on DEV Community by montoyaaguirre (@montoyaaguirre).</description>
    <link>https://dev.to/montoyaaguirre</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F325949%2F5e2ae6d2-5f94-4c6e-8226-f65e85bc8e2c.png</url>
      <title>DEV Community: montoyaaguirre</title>
      <link>https://dev.to/montoyaaguirre</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/montoyaaguirre"/>
    <language>en</language>
    <item>
      <title>Adding a splash screen to portable electron builder apps</title>
      <dc:creator>montoyaaguirre</dc:creator>
      <pubDate>Mon, 20 Apr 2020 19:58:41 +0000</pubDate>
      <link>https://dev.to/montoyaaguirre/adding-a-splash-screen-to-portable-electron-builder-apps-34d3</link>
      <guid>https://dev.to/montoyaaguirre/adding-a-splash-screen-to-portable-electron-builder-apps-34d3</guid>
      <description>&lt;p&gt;Portable electron apps may take a few seconds to start. During this time there is no obvious feedback that the app is launching. Users might be confused and try to launch the app a few more times before they see a welcome screen.&lt;/p&gt;

&lt;p&gt;It takes time to launch the application because the portable executable is extracting files to a temp folder in the background. Only after extraction is complete, the electron app will start. It can take more than a few seconds depending on the user's system and the size of the application.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3G-EjD0h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4nyrdrht221ogtz7l1ku.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3G-EjD0h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4nyrdrht221ogtz7l1ku.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
To avoid this situation, we would like to see a splash screen while the extraction is taking place. Unfortunately, electron builder does not have a fully functioning implementation of this feature. (Hopefully &lt;a href="https://github.com/electron-userland/electron-builder/pull/4798"&gt;this PR&lt;/a&gt; will be merged in the near future)&lt;br&gt;
In the meantime this post will guide you through a workaround&lt;/p&gt;
&lt;h2&gt;
  
  
  Use the right version of electron builder
&lt;/h2&gt;

&lt;p&gt;Use electron-builder ^22.4.0 (earlier versions will not work)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i electron-builder@latest
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix portable.nsi
&lt;/h2&gt;

&lt;p&gt;There is an issue with the template for portable windows applications (ROOT_OF_YOUR_PROJECT/node_modules/app-builder-lib/templates/nsis/portable.nsi) in electron builder. We will modify this file in order to fix it.&lt;br&gt;
Let's take a look at the onInit function (Line 10 at the time of writing)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function .onInit
  SetSilent silent
  !insertmacro check64BitAndSetRegView
FunctionEnd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The mode is set to silent. Because of this, the UI will not be displayed during the extraction of our electron app.&lt;br&gt;
The fix is to check for an environment variable "SPLASH_IMAGE". Only if it's not defined we will start in silent mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Function .onInit
  !ifndef SPLASH_IMAGE
    SetSilent silent
  !endif
  !insertmacro check64BitAndSetRegView
FunctionEnd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's it for fixing electron-builder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add a splash screen bitmap image file
&lt;/h2&gt;

&lt;p&gt;Let's just add an image to display as splash screen.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O8NAWj52--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lymc8ok8ew343z1xmv4y.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O8NAWj52--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lymc8ok8ew343z1xmv4y.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
We will name it "splash.bmp" and put it in the root of the project.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configure electron build options
&lt;/h2&gt;

&lt;p&gt;Now let's configure our electron app to build a portable executable that displays a splash image during extraction.&lt;br&gt;
In package.json the build property should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; "build": {
    "portable": {
      "splashImage": "..\\..\\..\\..\\splash.bmp"
    },
    "win": {
      "target": "portable"
    }
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The path must be relative to "/node_modules/app-builder-lib/templates/nsis/"&lt;br&gt;
Alternatively we can use an absolute path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build your electron app and behold the splash screen
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tTov_Q6z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/23tl8fv22fp2w8olpjua.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tTov_Q6z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/23tl8fv22fp2w8olpjua.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>electron</category>
      <category>builder</category>
      <category>splash</category>
      <category>portable</category>
    </item>
  </channel>
</rss>
