Skip to content

Commit

Permalink
Fix bugs in update notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Nov 25, 2021
1 parent 03a165c commit c644e06
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
The auto-update system has received an overhaul, bringing a few improvements:
* The download button now links directly to the relevant asset on GitHub, matching the current platform and architecture.
* The messages no longer include the most recent changelog (this feature was confusing when incrementing multiple versions).
* All prompts are now more consistent with the rest of the app.
* Detection of a translated environment on macOS and Winodws is now integrated into the update checker.
Fixes some minor bugs in the update notifier:
* When running on ARM Windows, the app incorrectly prompted the user to download the native version.
* The updater failed to reliably detect when the user was offline.
29 changes: 19 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const WindowStateKeeper = require("./windowState.js")
const jsonfile = require("jsonfile")
const Holidays = require("date-holidays")
const fetch = require("electron-fetch").default
const { Headers } = require("electron-fetch")
const path = require("path")
const fs = require("fs")
const os = require("os")
Expand Down Expand Up @@ -33,13 +34,13 @@ app.whenReady().then(() => {
switch (process.platform) {
case "win32":
iconPath = path.join(__dirname, "assets/app-icon-4096.png") // Square icon
break;
break
case "linux":
iconPath = path.join(__dirname, "assets/app-icon-rounded.png") // Rounded icon
break;
break
default:
iconPath = null // macOS uses the app icon by default
break;
break
}

// Check preferences and set theme
Expand Down Expand Up @@ -496,11 +497,19 @@ function checkForUpdate(alwaysNotify) {
return
}

fetch("https://api.github.com/repos/" + repository + "/releases").then(res => res.json()).then(json => {
var fetchHeaders = new Headers()
fetchHeaders.append("pragma", "no-cache")
fetchHeaders.append("cache-control", "no-cache")
var fetchInit = {
method: "GET",
headers: fetchHeaders,
}
fetch("https://api.github.com/repos/" + repository + "/releases", fetchInit).then(res => res.json()).then(json => {
var currentVersion = app.getVersion()
var latestVersion = json[0].tag_name.slice(1)
var latestDate = new Date(json[0].published_at)
var latestDateText = latestDate.toLocaleDateString()
var translated = process.arch != "arm64" && app.runningUnderARM64Translation
var options = process.platform == "darwin" ? ["Download", "Later", "View Changelog"] : ["Download", "View Changelog", "Later"]

var handleResponse = result => {
Expand All @@ -510,15 +519,15 @@ function checkForUpdate(alwaysNotify) {
switch (process.platform) {
case "win32":
platformKey = "win"
break;
break
case "linux":
platformKey = "linux"
break;
break
case "darwin":
platformKey = "mac"
break;
break
}
var arch = app.runningUnderARM64Translation ? "arm64" : process.arch // If under translation, switch to ARM
var arch = translated ? "arm64" : process.arch // If under translation, switch to ARM

var url = null
json[0].assets.forEach(asset => {
Expand All @@ -538,7 +547,7 @@ function checkForUpdate(alwaysNotify) {
}

// Send appropriate prompt
if (currentVersion != latestVersion && app.runningUnderARM64Translation) {
if (currentVersion != latestVersion && translated) {
dialog.showMessageBox({
type: "info",
title: "Update Checker",
Expand All @@ -558,7 +567,7 @@ function checkForUpdate(alwaysNotify) {
buttons: options,
defaultId: 0,
}).then(handleResponse)
} else if (app.runningUnderARM64Translation) {
} else if (translated) {
dialog.showMessageBox({
type: "info",
title: "Update Checker",
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "advantage-scope",
"productName": "Advantage Scope",
"version": "1.8.0",
"version": "1.8.1",
"description": "Logging tool from FRC Team 6328.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit c644e06

Please sign in to comment.