home / tils / til

Menu
  • GraphQL API

til: electron_electrion-auto-update.md

This data as json

path topic title url body html shot created created_utc updated updated_utc shot_hash slug
electron_electrion-auto-update.md electron Configuring auto-update for an Electron app https://github.com/simonw/til/blob/main/electron/electrion-auto-update.md This is _almost_ really simple. I used [electron/update-electron-app](https://github.com/electron/update-electron-app) for it, the instructions for which are: - Add it to `packages.json` with `npm i update-electron-app` - Make sure your `"repository"` field in that file points to your GitHub repository - Use GitHub releases to release signed versions of your application - Add `require('update-electron-app')()` somewhere in your `main.js` I added this... and it didn't work ([#106](https://github.com/simonw/datasette-app/issues/106)). Then I spotted [this recipe](https://github.com/electron/update.electronjs.org#manual-setup) in the manual setup instructions for the `update.electronjs.org` server that it uses: ```javascript const server = 'https://update.electronjs.org' const feed = `${server}/OWNER/REPO/${process.platform}-${process.arch}/${app.getVersion()}` ``` I ran that in the Electron debugger, swapping in `simonw/datasette-app` as the `OWNER/REPO` and got this URL: `https://update.electronjs.org/simonw/datasette-app/darwin-x64/0.2.0` Which returned this: > `No updates found (needs asset matching *{mac,darwin,osx}*.zip in public repository)` It turns out your asset filename needs to match that pattern! I renamed the asset I was attaching to the release to `Datasette-mac.app.zip` and the auto-update mechanism started working instantly. ## How it works That update URL is interesting. If you hit it with the most recent version of the software (`0.2.1` at time of writing) you get this: ``` ~ % curl -i 'https://update.electronjs.org/simonw/datasette-app/darwin-x64/0.2.1' HTTP/1.1 204 No Content Server: Cowboy Content-Length: 0 Connection: keep-alive Date: Tue, 14 Sep 2021 03:54:47 GMT Via: 1.1 vegur ``` But if you tell it you are running a previous version you get this instead: ``` ~ % curl -i 'https://update.electronjs.org/simonw/datasette-app/darwin-x64/0.2.0' HTTP/1.1 200 OK Server: Cowboy Connection: keep-alive Content-Type: application/json Date: Tue, 14 Sep 2021 03:55:19 GMT Content-Length: 740 Via: 1.1 vegur {"name":"0.2.1","notes":"- Fixed bug where application would not start without a working internet connection. [#115](https://github.com/simonw/datasette-app/issues/115)\r\n- The \"Debug -> Open Chromium DevTools\" menu item no longer shows an error if no windows are focused. [#113](https://github.com/simonw/datasette-app/issues/113)\r\n- Fixed bug where the `datasette-leaflet` plugin could be uninstalled despite being automatically re-installed. [#118](https://github.com/simonw/datasette-app/issues/118)\r\n- Time limit for facet calculations increased from 1 second to 3 seconds. [#114](https://github.com/simonw/datasette-app/issues/114)","url":"https://github.com/simonw/datasette-app/releases/download/0.2.1/Datasette-mac.app.zip"} ``` Which pretty-prints to: ```json { "name": "0.2.1", "notes": "- Fixed bug where application would not start without a working internet connection. [#115](https://github.com/simonw/datasette-app/issues/115)\r\n- The \"Debug -> Open Chromium DevTools\" menu item no longer shows an error if no windows are focused. [#113](https://github.com/simonw/datasette-app/issues/113)\r\n- Fixed bug where the `datasette-leaflet` plugin could be uninstalled despite being automatically re-installed. [#118](https://github.com/simonw/datasette-app/issues/118)\r\n- Time limit for facet calculations increased from 1 second to 3 seconds. [#114](https://github.com/simonw/datasette-app/issues/114)", "url": "https://github.com/simonw/datasette-app/releases/download/0.2.1/Datasette-mac.app.zip" } ``` <p>This is <em>almost</em> really simple. I used <a href="https://github.com/electron/update-electron-app">electron/update-electron-app</a> for it, the instructions for which are:</p> <ul> <li>Add it to <code>packages.json</code> with <code>npm i update-electron-app</code> </li> <li>Make sure your <code>"repository"</code> field in that file points to your GitHub repository</li> <li>Use GitHub releases to release signed versions of your application</li> <li>Add <code>require('update-electron-app')()</code> somewhere in your <code>main.js</code> </li> </ul> <p>I added this... and it didn't work (<a href="https://github.com/simonw/datasette-app/issues/106">#106</a>).</p> <p>Then I spotted <a href="https://github.com/electron/update.electronjs.org#manual-setup">this recipe</a> in the manual setup instructions for the <code>update.electronjs.org</code> server that it uses:</p> <div class="highlight highlight-source-js"><pre><span class="pl-k">const</span> <span class="pl-s1">server</span> <span class="pl-c1">=</span> <span class="pl-s">'https://update.electronjs.org'</span> <span class="pl-k">const</span> <span class="pl-s1">feed</span> <span class="pl-c1">=</span> <span class="pl-s">`<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">server</span><span class="pl-kos">}</span></span>/OWNER/REPO/<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">platform</span><span class="pl-kos">}</span></span>-<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">arch</span><span class="pl-kos">}</span></span>/<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">app</span><span class="pl-kos">.</span><span class="pl-en">getVersion</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">}</span></span>`</span></pre></div> <p>I ran that in the Electron debugger, swapping in <code>simonw/datasette-app</code> as the <code>OWNER/REPO</code> and got this URL:</p> <p><code>https://update.electronjs.org/simonw/datasette-app/darwin-x64/0.2.0</code></p> <p>Which returned this:</p> <blockquote> <p><code>No updates found (needs asset matching *{mac,darwin,osx}*.zip in public repository)</code></p> </blockquote> <p>It turns out your asset filename needs to match that pattern!</p> <p>I renamed the asset I was attaching to the release to <code>Datasette-mac.app.zip</code> and the auto-update mechanism started working instantly.</p> <h2> <a id="user-content-how-it-works" class="anchor" href="#how-it-works" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>How it works</h2> <p>That update URL is interesting. If you hit it with the most recent version of the software (<code>0.2.1</code> at time of writing) you get this:</p> <pre><code>~ % curl -i 'https://update.electronjs.org/simonw/datasette-app/darwin-x64/0.2.1' HTTP/1.1 204 No Content Server: Cowboy Content-Length: 0 Connection: keep-alive Date: Tue, 14 Sep 2021 03:54:47 GMT Via: 1.1 vegur </code></pre> <p>But if you tell it you are running a previous version you get this instead:</p> <pre><code>~ % curl -i 'https://update.electronjs.org/simonw/datasette-app/darwin-x64/0.2.0' HTTP/1.1 200 OK Server: Cowboy Connection: keep-alive Content-Type: application/json Date: Tue, 14 Sep 2021 03:55:19 GMT Content-Length: 740 Via: 1.1 vegur {"name":"0.2.1","notes":"- Fixed bug where application would not start without a working internet connection. [#115](https://github.com/simonw/datasette-app/issues/115)\r\n- The \"Debug -&gt; Open Chromium DevTools\" menu item no longer shows an error if no windows are focused. [#113](https://github.com/simonw/datasette-app/issues/113)\r\n- Fixed bug where the `datasette-leaflet` plugin could be uninstalled despite being automatically re-installed. [#118](https://github.com/simonw/datasette-app/issues/118)\r\n- Time limit for facet calculations increased from 1 second to 3 seconds. [#114](https://github.com/simonw/datasette-app/issues/114)","url":"https://github.com/simonw/datasette-app/releases/download/0.2.1/Datasette-mac.app.zip"} </code></pre> <p>Which pretty-prints to:</p> <div class="highlight highlight-source-json"><pre>{ <span class="pl-s"><span class="pl-pds">"</span>name<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>0.2.1<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>notes<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>- Fixed bug where application would not start without a working internet connection. [#115](https://github.com/simonw/datasette-app/issues/115)<span class="pl-cce">\r\n</span>- The <span class="pl-cce">\"</span>Debug -&gt; Open Chromium DevTools<span class="pl-cce">\"</span> menu item no longer shows an error if no windows are focused. [#113](https://github.com/simonw/datasette-app/issues/113)<span class="pl-cce">\r\n</span>- Fixed bug where the `datasette-leaflet` plugin could be uninstalled despite being automatically re-installed. [#118](https://github.com/simonw/datasette-app/issues/118)<span class="pl-cce">\r\n</span>- Time limit for facet calculations increased from 1 second to 3 seconds. [#114](https://github.com/simonw/datasette-app/issues/114)<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>url<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>https://github.com/simonw/datasette-app/releases/download/0.2.1/Datasette-mac.app.zip<span class="pl-pds">"</span></span> }</pre></div> <Binary: 73,758 bytes> 2021-09-13T20:57:03-07:00 2021-09-14T03:57:03+00:00 2021-09-13T21:11:18-07:00 2021-09-14T04:11:18+00:00 b3d1f989fac8930682b18b7c984199ea electrion-auto-update
Powered by Datasette · How this site works · Code of conduct