Skip to content

Commit 23fac47

Browse files
authored
Switch macOS update mechanism to static JSON mode (element-hq#461)
1 parent 56370de commit 23fac47

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

docs/updates.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The Desktop app is capable of self-updating on macOS and Windows.
2+
The update server base url is configurable as `update_base_url` in config.json and can be served by a static file host,
3+
CDN or object storage.
4+
5+
Currently all packaging & deployment is handled by https://github.com/vector-im/element-builder/
6+
7+
# Windows
8+
9+
On Windows the update mechanism used is [Squirrel.Windows](https://github.com/Squirrel/Squirrel.Windows)
10+
and can be served by any compatible Squirrel server, such as https://github.com/Tiliq/squirrel-server
11+
12+
# macOS
13+
14+
On macOS the update mechanism used is [Squirrel.Mac](https://github.com/Squirrel/Squirrel.Mac)
15+
using the newer JSON format as documented [here](https://github.com/Squirrel/Squirrel.Mac#update-file-json-format).
16+

src/updater.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { app, autoUpdater, ipcMain } from "electron";
17+
import { autoUpdater, ipcMain } from "electron";
1818

1919
const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000;
2020
const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
@@ -50,20 +50,14 @@ export function start(updateBaseUrl: string): void {
5050
}
5151
try {
5252
let url: string;
53-
// For reasons best known to Squirrel, the way it checks for updates
54-
// is completely different between macOS and windows. On macOS, it
55-
// hits a URL that either gives it a 200 with some json or
56-
// 204 No Content. On windows it takes a base path and looks for
57-
// files under that path.
53+
let serverType: "json" | undefined;
54+
5855
if (process.platform === 'darwin') {
59-
// include the current version in the URL we hit. Electron doesn't add
60-
// it anywhere (apart from the User-Agent) so it's up to us. We could
61-
// (and previously did) just use the User-Agent, but this doesn't
62-
// rely on NSURLConnection setting the User-Agent to what we expect,
63-
// and also acts as a convenient cache-buster to ensure that when the
64-
// app updates it always gets a fresh value to avoid update-looping.
65-
url = `${updateBaseUrl}macos/?localVersion=${encodeURIComponent(app.getVersion())}`;
56+
// On macOS it takes a JSON file with a map between versions and their URLs
57+
url = `${updateBaseUrl}macos/releases.json`;
58+
serverType = "json";
6659
} else if (process.platform === 'win32') {
60+
// On windows it takes a base path and looks for files under that path.
6761
url = `${updateBaseUrl}win32/${process.arch}/`;
6862
} else {
6963
// Squirrel / electron only supports auto-update on these two platforms.
@@ -75,7 +69,7 @@ export function start(updateBaseUrl: string): void {
7569

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

0 commit comments

Comments
 (0)