Skip to content

Commit

Permalink
Switch macOS update mechanism to static JSON mode (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Dec 5, 2022
1 parent 56370de commit 23fac47
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
16 changes: 16 additions & 0 deletions docs/updates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The Desktop app is capable of self-updating on macOS and Windows.
The update server base url is configurable as `update_base_url` in config.json and can be served by a static file host,
CDN or object storage.

Currently all packaging & deployment is handled by https:/vector-im/element-builder/

# Windows

On Windows the update mechanism used is [Squirrel.Windows](https:/Squirrel/Squirrel.Windows)
and can be served by any compatible Squirrel server, such as https:/Tiliq/squirrel-server

# macOS

On macOS the update mechanism used is [Squirrel.Mac](https:/Squirrel/Squirrel.Mac)
using the newer JSON format as documented [here](https:/Squirrel/Squirrel.Mac#update-file-json-format).

22 changes: 8 additions & 14 deletions src/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { app, autoUpdater, ipcMain } from "electron";
import { autoUpdater, ipcMain } from "electron";

const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000;
const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
Expand Down Expand Up @@ -50,20 +50,14 @@ export function start(updateBaseUrl: string): void {
}
try {
let url: string;
// For reasons best known to Squirrel, the way it checks for updates
// is completely different between macOS and windows. On macOS, it
// hits a URL that either gives it a 200 with some json or
// 204 No Content. On windows it takes a base path and looks for
// files under that path.
let serverType: "json" | undefined;

if (process.platform === 'darwin') {
// include the current version in the URL we hit. Electron doesn't add
// it anywhere (apart from the User-Agent) so it's up to us. We could
// (and previously did) just use the User-Agent, but this doesn't
// rely on NSURLConnection setting the User-Agent to what we expect,
// and also acts as a convenient cache-buster to ensure that when the
// app updates it always gets a fresh value to avoid update-looping.
url = `${updateBaseUrl}macos/?localVersion=${encodeURIComponent(app.getVersion())}`;
// On macOS it takes a JSON file with a map between versions and their URLs
url = `${updateBaseUrl}macos/releases.json`;
serverType = "json";
} else if (process.platform === 'win32') {
// On windows it takes a base path and looks for files under that path.
url = `${updateBaseUrl}win32/${process.arch}/`;
} else {
// Squirrel / electron only supports auto-update on these two platforms.
Expand All @@ -75,7 +69,7 @@ export function start(updateBaseUrl: string): void {

if (url) {
console.log(`Update URL: ${url}`);
autoUpdater.setFeedURL({ url });
autoUpdater.setFeedURL({ url, serverType });
// We check for updates ourselves rather than using 'updater' because we need to
// do it in the main process (and we don't really need to check every 10 minutes:
// every hour should be just fine for a desktop app)
Expand Down

0 comments on commit 23fac47

Please sign in to comment.