Skip to content

Commit b9127c7

Browse files
committed
chore: silent auto updates for better update UX
1 parent 7c3b29d commit b9127c7

2 files changed

Lines changed: 40 additions & 25 deletions

File tree

src/extensionsIntegrated/appUpdater/main.js

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ define(function (require, exports, module) {
162162
// was actually done. We have a version number mismatch of 0.0.1 between phoenix-desktop and phoenix
163163
// repo, and that means that this can get triggered on statup on development builds. Wont happen in
164164
// actual pipeline generated build tho.
165-
console.log("Updates applied, waiting for app restart: ", phoenixBinaryVersion, phoenixLoadedAppVersion);
165+
console.log("Updates applied, waiting for app restart:", phoenixBinaryVersion, phoenixLoadedAppVersion);
166166
updateDetails.updatePendingRestart = true;
167167
PreferencesManager.setViewState(KEY_UPDATE_AVAILABLE, true);
168168
} else {
@@ -172,6 +172,7 @@ define(function (require, exports, module) {
172172
showOrHideUpdateIcon();
173173
} catch (e) {
174174
console.error("Error getting update metadata", e);
175+
logger.reportError(e, `Error getting app update metadata`);
175176
updateFailed = true;
176177
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'fail', "Unknown"+Phoenix.platform);
177178
}
@@ -217,15 +218,45 @@ define(function (require, exports, module) {
217218
return [updateLater, updateOnExit];
218219
}
219220

221+
async function _updateWithConfirmDialog(isUpgradableLoc, updateDetails) {
222+
const buttons = _getButtons(isUpgradableLoc);
223+
let markdownHtml = marked.parse(updateDetails.releaseNotesMarkdown || "");
224+
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "shown"+Phoenix.platform);
225+
Dialogs.showModalDialog(DefaultDialogs.DIALOG_ID_INFO, Strings.UPDATE_AVAILABLE_TITLE, markdownHtml, buttons)
226+
.done(option=>{
227+
if(option === Dialogs.DIALOG_BTN_CANCEL){
228+
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "cancel"+Phoenix.platform);
229+
return;
230+
}
231+
if(!isUpgradableLoc) {
232+
// user installed linux as binary without installer, we just open phcode.io
233+
const downloadPage = brackets.config.homepage_url || "https://phcode.io";
234+
NativeApp.openURLInDefaultBrowser(downloadPage);
235+
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "nonUpgradable"+Phoenix.platform);
236+
return;
237+
}
238+
if(option === Dialogs.DIALOG_BTN_OK && !updaterWindow){
239+
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "okUpdate"+Phoenix.platform);
240+
doUpdate(updateDetails.downloadURL);
241+
}
242+
});
243+
}
244+
220245
async function checkForUpdates(isAutoUpdate) {
221246
showOrHideUpdateIcon();
247+
if(!navigator.onLine) {
248+
return;
249+
}
222250
if(updateTask){
223251
$("#status-tasks .btn-dropdown").click();
224252
return;
225253
}
226254
const updateDetails = await getUpdateDetails(); // this will also show update icon if update present
227255
if(updateFailed) {
228-
Dialogs.showInfoDialog(Strings.UPDATE_FAILED_TITLE, Strings.UPDATE_FAILED_MESSAGE);
256+
if(!isAutoUpdate) {
257+
// we dont show auto update errors to user
258+
Dialogs.showInfoDialog(Strings.UPDATE_FAILED_TITLE, Strings.UPDATE_FAILED_MESSAGE);
259+
}
229260
return;
230261
}
231262
if(updatePendingRestart || updateDetails.updatePendingRestart){
@@ -246,29 +277,13 @@ define(function (require, exports, module) {
246277
// but, we don't show the dialog if auto update is off.
247278
return;
248279
}
249-
250280
const isUpgradableLoc = await isUpgradableLocation();
251-
const buttons = _getButtons(isUpgradableLoc);
252-
let markdownHtml = marked.parse(updateDetails.releaseNotesMarkdown || "");
253-
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "shown"+Phoenix.platform);
254-
Dialogs.showModalDialog(DefaultDialogs.DIALOG_ID_INFO, Strings.UPDATE_AVAILABLE_TITLE, markdownHtml, buttons)
255-
.done(option=>{
256-
if(option === Dialogs.DIALOG_BTN_CANCEL){
257-
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "cancel"+Phoenix.platform);
258-
return;
259-
}
260-
if(!isUpgradableLoc) {
261-
// user installed linux as binary without installer, we just open phcode.io
262-
const downloadPage = brackets.config.homepage_url || "https://phcode.io";
263-
NativeApp.openURLInDefaultBrowser(downloadPage);
264-
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "nonUpgradable"+Phoenix.platform);
265-
return;
266-
}
267-
if(option === Dialogs.DIALOG_BTN_OK && !updaterWindow){
268-
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'dialog', "okUpdate"+Phoenix.platform);
269-
doUpdate(updateDetails.downloadURL);
270-
}
271-
});
281+
if(!isUpgradableLoc || !isAutoUpdate) {
282+
_updateWithConfirmDialog(isUpgradableLoc, updateDetails);
283+
} else if(!updaterWindow) {
284+
Metrics.countEvent(Metrics.EVENT_TYPE.UPDATES, 'auto', "silent"+Phoenix.platform);
285+
doUpdate(updateDetails.downloadURL);
286+
}
272287
}
273288

274289
const UPDATE_COMMANDS = {

src/nls/root/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ define({
618618
"UPDATE_FAILED_TITLE": "Update Failed",
619619
"UPDATE_INSTALLING": "Installing Update\u2026",
620620
"UPDATE_INSTALLING_MESSAGE": "Update Installation in Progress: {APP_NAME} is currently installing the latest updates. The application will automatically close once the installation is complete.",
621-
"UPDATE_FAILED_MESSAGE": "Please close all {APP_NAME} app windows and reopen the application to attempt the update again.",
621+
"UPDATE_FAILED_MESSAGE": "Please close all {APP_NAME} app windows and reopen the application to attempt the update again. <br/> You can also install the update by downloading the installer from <a href='https://phcode.io'>phcode.io</a>",
622622
"UPDATE_FAILED_VISIT_SITE_MESSAGE": "To retry, please exit all instances of {APP_NAME} and restart the application. <br>You will be directed to our download page shortly, where you can manually download the latest version.",
623623
"UPDATE_MESSAGE": "Hey, there's a new build of {APP_NAME} available. Here are some of the new features:",
624624
"GET_IT_NOW": "Get it now!",

0 commit comments

Comments
 (0)