Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Improve updater stability & UX (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanglam2807 authored Jul 20, 2020
1 parent 7b1d1aa commit 1716790
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 27 deletions.
37 changes: 28 additions & 9 deletions public/libs/create-menu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {
BrowserWindow,
Menu,
app,
shell,
Expand All @@ -15,6 +16,18 @@ const { getPreference } = require('./preferences');
const createMenu = () => {
const updaterEnabled = process.env.SNAP == null && !process.mas && !process.windowsStore;
const handleCheckForUpdates = () => {
// restart & apply updates
if (global.updaterObj && global.updaterObj.status === 'update-downloaded') {
setImmediate(() => {
app.removeAllListeners('window-all-closed');
const win = BrowserWindow.getFocusedWindow();
if (win != null) {
win.close();
}
autoUpdater.quitAndInstall(false);
});
}

// https://github.com/atomery/webcatalog/issues/634
// https://github.com/electron-userland/electron-builder/issues/4046
// disable updater if user is using AppImageLauncher
Expand All @@ -39,6 +52,19 @@ const createMenu = () => {
autoUpdater.checkForUpdates();
};

const updaterMenuItem = {
label: getLocale('checkForUpdates'),
click: handleCheckForUpdates,
visible: updaterEnabled,
};
if (global.updaterObj && global.updaterObj.status === 'update-downloaded') {
updaterMenuItem.label = getLocale('restartToApplyUpdates');
} else if (global.updaterObj && global.updaterObj.status === 'update-available') {
updaterMenuItem.enabled = false;
} else if (global.updaterObj && global.updaterObj.status === 'checking-for-update') {
updaterMenuItem.enabled = false;
}

const template = [
{
role: 'edit',
Expand Down Expand Up @@ -166,11 +192,7 @@ const createMenu = () => {
type: 'separator',
visible: updaterEnabled,
},
{
label: getLocale('checkForUpdates'),
click: handleCheckForUpdates,
visible: updaterEnabled,
},
updaterMenuItem,
{
type: 'separator',
visible: !process.mas,
Expand Down Expand Up @@ -236,10 +258,7 @@ const createMenu = () => {
submenu.splice(1, 0, {
type: 'separator',
});
submenu.splice(2, 0, {
label: getLocale('checkForUpdates'),
click: handleCheckForUpdates,
});
submenu.splice(2, 0, updaterMenuItem);
submenu.splice(3, 0, {
type: 'separator',
});
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/de/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "Später",
"applicationUpdate": "App-Update",
"applicationUpdateDesc": "Eine neue Version {version} wurde heruntergeladen. Starten Sie die Anwendung neu, um die Updates zu übernehmen.",
"restartToApplyUpdates": "Starten Sie die Anwendung neu, um die Updates zu übernehmen",
"resetNow": "Jetzt zurücksetzen",
"resetDesc": "Sind Sie sicher? Alle Einstellungen werden auf ihre ursprünglichen Standardwerte zurückgesetzt. Diese Aktion kann nicht rückgängig gemacht werden.",
"requireRestartDescMas": "Sie müssen die App beenden und dann manuell neu starten, damit diese Änderung wirksam wird.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/en/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "Later",
"applicationUpdate": "Application Update",
"applicationUpdateDesc": "A new version {version} has been downloaded. Restart the application to apply the updates.",
"restartToApplyUpdates": "Restart the application to apply the updates",
"resetNow": "Reset Now",
"resetDesc": "Are you sure? All preferences will be restored to their original defaults. This action cannot be undone.",
"requireRestartDescMas": "You need to quit and then manually restart the app for this change to take effect.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/es-ES/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "Más tarde",
"applicationUpdate": "Actualización de la aplicación",
"applicationUpdateDesc": "Se ha descargado una nueva versión {version}. Reinicie la aplicación para aplicar las actualizaciones.",
"restartToApplyUpdates": "Reinicie la aplicación para aplicar las actualizaciones",
"resetNow": "Restablecer ahora",
"resetDesc": "¿Está seguro? Todas las preferencias se restablecerán con sus valores predeterminados originales. Esta acción no se puede deshacer.",
"requireRestartDescMas": "Necesita salir y luego reiniciar manualmente la aplicación para que este cambio surta efecto.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/fr/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "Plus tard",
"applicationUpdate": "Mise à jour de l'application",
"applicationUpdateDesc": "Une nouvelle version {version} a été téléchargée. Redémarrez l'application pour appliquer les mises à jour.",
"restartToApplyUpdates": "Redémarrez l'application pour appliquer les mises à jour",
"resetNow": "Réinitialiser maintenant",
"resetDesc": "Êtes-vous sûr ? Toutes les préférences seront restaurées à leurs valeurs par défaut. Cette action ne peut pas être annulée.",
"requireRestartDescMas": "Vous devez quitter, puis redémarrer manuellement l'application pour que cette modification prenne effet.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/it/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "Più tardi",
"applicationUpdate": "Aggiornamento applicazione",
"applicationUpdateDesc": "È stata scaricata la nuova versione {version}. Riavviare l'applicazione per applicare gli aggiornamenti.",
"restartToApplyUpdates": "Riavviare l'applicazione per applicare gli aggiornamenti",
"resetNow": "Reimpostare ora",
"resetDesc": "Continuare? Tutte le preferenze saranno ripristinate ai valori predefiniti originali. Questa azione non può essere annullata.",
"requireRestartDescMas": "È necessario uscire e quindi riavviare manualmente l'app per rendere effettiva questa modifica.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/ko/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "나중에",
"applicationUpdate": "애플리케이션 업데이트",
"applicationUpdateDesc": "새로운 버전 {version}이(가) 다운로드되었습니다. 애플리케이션을 다시 시작하여 업데이트를 적용하세요.",
"restartToApplyUpdates": "애플리케이션을 다시 시작하여 업데이트를 적용하세요",
"resetNow": "지금 재설정",
"resetDesc": "계속하시겠습니까? 모든 기본 설정이 원래 기본값으로 복원됩니다. 이 작업은 실행 취소할 수 없습니다.",
"requireRestartDescMas": "이 변경 사항을 적용하려면 앱을 끝낸 다음 수동으로 다시 시작해야 합니다.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/ru/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "Позже",
"applicationUpdate": "Обновление приложения",
"applicationUpdateDesc": "Загружена новая версия: {version}. Чтобы применить обновления, перезапустите приложение.",
"restartToApplyUpdates": "Чтобы применить обновления, перезапустите приложение",
"resetNow": "Сбросить",
"resetDesc": "Действительно выполнить сброс? Настройки вернутся к значениям по умолчанию. Это действие отменить нельзя.",
"requireRestartDescMas": "Чтобы изменения вступили в силу, нужно выйти, а затем снова запустить приложение.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/vi/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "Để sau",
"applicationUpdate": "Cập nhật Ứng dụng",
"applicationUpdateDesc": "Phiên bản mới {version} đã được tải về. Khởi động lại ứng dụng để cập nhật.",
"restartToApplyUpdates": "Khởi động lại ứng dụng để cập nhật",
"resetNow": "Cài đặt lại Bây giờ",
"resetDesc": "Bạn chắc chứ? Tất cả tuỳ chọn sẽ được khôi phục về trạng thái ban đầu. Tác vụ này không thể được hoàn tác.",
"requireRestartDescMas": "Bạn cần thoát và tự khởi động lại ứng dụng để thay đổi này có hiệu lực.",
Expand Down
1 change: 1 addition & 0 deletions public/libs/locales/zh-CN/ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"later": "稍后",
"applicationUpdate": "应用程序更新",
"applicationUpdateDesc": "新版本 {version} 下载完毕。请重新启动应用程序以应用更新。",
"restartToApplyUpdates": "请重新启动应用程序以应用更新",
"resetNow": "立即重置",
"resetDesc": "您确定吗?所有首选项都将恢复为原始默认值。此操作无法撤消。",
"requireRestartDescMas": "您需要退出,然后手动重新启动应用程序,此更改才能生效。",
Expand Down
40 changes: 37 additions & 3 deletions public/libs/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ const createMenu = require('./create-menu');
const { getLocale } = require('./locales');

global.updateSilent = true;
global.updateAvailable = false;

global.updaterObj = {};

autoUpdater.on('checking-for-update', () => {
global.updaterObj = {
status: 'checking-for-update',
};
createMenu();
});

autoUpdater.on('update-available', (info) => {
if (!global.updateSilent) {
Expand All @@ -22,6 +30,12 @@ autoUpdater.on('update-available', (info) => {
}

sendToAllWindows('log', info);

global.updaterObj = {
status: 'update-available',
info,
};
createMenu();
});

autoUpdater.on('update-not-available', (info) => {
Expand All @@ -38,6 +52,12 @@ autoUpdater.on('update-not-available', (info) => {
}

sendToAllWindows('log', info);

global.updaterObj = {
status: 'update-not-available',
info,
};
createMenu();
});

autoUpdater.on('error', (err) => {
Expand All @@ -54,11 +74,25 @@ autoUpdater.on('error', (err) => {
}

sendToAllWindows('log', err);
global.updaterObj = {
status: 'error',
info: err,
};
createMenu();
});

autoUpdater.on('update-downloaded', (info) => {
global.updateDownloaded = true;
autoUpdater.on('update-cancelled', () => {
global.updaterObj = {
status: 'update-cancelled',
};
createMenu();
});

autoUpdater.on('update-downloaded', (info) => {
global.updaterObj = {
status: 'update-downloaded',
info,
};
createMenu();

const dialogOpts = {
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3749,9 +3749,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000844, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001097:
version "1.0.30001100"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001100.tgz#2a58615e0c01cf716ab349b20ca4d86ef944aa4e"
integrity sha512-0eYdp1+wFCnMlCj2oudciuQn2B9xAFq3WpgpcBIZTxk/1HNA/O2YA7rpeYhnOqsqAJq1AHUgx6i1jtafg7m2zA==
version "1.0.30001104"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001104.tgz#4e3d5b3b1dd3c3529f10cb7f519c62ba3e579f5d"
integrity sha512-pkpCg7dmI/a7WcqM2yfdOiT4Xx5tzyoHAXWsX5/HxZ3TemwDZs0QXdqbE0UPLPVy/7BeK7693YfzfRYfu1YVpg==

capture-exit@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -4718,9 +4718,9 @@ data-urls@^1.0.0, data-urls@^1.1.0:
whatwg-url "^7.0.0"

date-fns@^2.0.1:
version "2.14.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.14.0.tgz#359a87a265bb34ef2e38f93ecf63ac453f9bc7ba"
integrity sha512-1zD+68jhFgDIM0rF05rcwYO8cExdNqxjq4xP1QKM60Q45mnO6zaMWB4tOzrIr4M4GSLntsKeE4c9Bdl2jhL/yw==
version "2.15.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.15.0.tgz#424de6b3778e4e69d3ff27046ec136af58ae5d5f"
integrity sha512-ZCPzAMJZn3rNUvvQIMlXhDr4A+Ar07eLeGsGREoWU19a3Pqf5oYa+ccd+B3F6XVtQY6HANMFdOQ8A+ipFnvJdQ==

debug@2.2.0:
version "2.2.0"
Expand Down Expand Up @@ -5215,9 +5215,9 @@ electron-settings@3.2.0:
jsonfile "^4.0.0"

electron-to-chromium@^1.3.378, electron-to-chromium@^1.3.47, electron-to-chromium@^1.3.488:
version "1.3.498"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.498.tgz#fd7188c8a49d6d0b5df1df55a1f1a4bf2c177457"
integrity sha512-W1hGwaQEU8j9su2jeAr3aabkPuuXw+j8t73eajGAkEJWbfWiwbxBwQN/8Qmv2qCy3uCDm2rOAaZneYQM8VGC4w==
version "1.3.501"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.501.tgz#faa17a2cb0105ee30d5e1ca87eae7d8e85dd3175"
integrity sha512-tyzuKaV2POw2mtqBBzQGNBojMZzH0MRu8bT8T/50x+hWeucyG/9pkgAATy+PcM2ySNM9+8eG2VllY9c6j4i+bg==

electron-updater@4.3.4:
version "4.3.4"
Expand Down Expand Up @@ -9524,9 +9524,9 @@ onetime@^5.1.0:
mimic-fn "^2.1.0"

open@^7.0.2:
version "7.0.4"
resolved "https://registry.yarnpkg.com/open/-/open-7.0.4.tgz#c28a9d315e5c98340bf979fdcb2e58664aa10d83"
integrity sha512-brSA+/yq+b08Hsr4c8fsEW2CRzk1BmfN3SAK/5VCHQ9bdoZJ4qa/+AfR0xHjlbbZUyPkUHs1b8x1RqdyZdkVqQ==
version "7.1.0"
resolved "https://registry.yarnpkg.com/open/-/open-7.1.0.tgz#68865f7d3cb238520fa1225a63cf28bcf8368a1c"
integrity sha512-lLPI5KgOwEYCDKXf4np7y1PBEkj7HYIyP2DY8mVDRnx0VIIu6bNrRB0R66TuO7Mack6EnTNLm4uvcl1UoklTpA==
dependencies:
is-docker "^2.0.0"
is-wsl "^2.1.1"
Expand Down Expand Up @@ -10002,9 +10002,9 @@ popper.js@1.16.1-lts:
integrity sha512-Kjw8nKRl1m+VrSFCoVGPph93W/qrSO7ZkqPpTf7F4bk/sqcfWK019dWBUpE/fBOsOQY1dks/Bmcbfn1heM/IsA==

portfinder@^1.0.25:
version "1.0.26"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.26.tgz#475658d56ca30bed72ac7f1378ed350bd1b64e70"
integrity sha512-Xi7mKxJHHMI3rIUrnm/jjUgwhbYMkp/XKEcZX3aG4BrumLpq3nmoQMX+ClYnDZnZ/New7IatC1no5RX0zo1vXQ==
version "1.0.27"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.27.tgz#a41333c116b5e5f3d380f9745ac2f35084c4c758"
integrity sha512-bJ3U3MThKnyJ9Dx1Idtm5pQmxXqw08+XOHhi/Lie8OF1OlhVaBFhsntAIhkZYjfDcCzszSr0w1yCbccThhzgxQ==
dependencies:
async "^2.6.2"
debug "^3.1.1"
Expand Down

0 comments on commit 1716790

Please sign in to comment.