Fix auto-update dialog now that locale-loading has been changed

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-07-25 11:40:23 -07:00
parent b62fdd1b36
commit 8243f25e5a
No known key found for this signature in database
GPG key ID: A4931C09644C654B
2 changed files with 19 additions and 14 deletions

View file

@ -2,7 +2,6 @@ const autoUpdater = require('electron-updater').autoUpdater
const { dialog } = require('electron'); const { dialog } = require('electron');
const config = require('./config'); const config = require('./config');
const locale = require('./locale');
const windowState = require('./window_state'); const windowState = require('./window_state');
const hour = 60 * 60; const hour = 60 * 60;
@ -20,7 +19,7 @@ function checkForUpdates() {
} }
var showingDialog = false; var showingDialog = false;
function showUpdateDialog() { function showUpdateDialog(messages) {
if (showingDialog) { if (showingDialog) {
return; return;
} }
@ -29,12 +28,12 @@ function showUpdateDialog() {
const options = { const options = {
type: 'info', type: 'info',
buttons: [ buttons: [
locale.messages.autoUpdateRestartButtonLabel.message, messages.autoUpdateRestartButtonLabel.message,
locale.messages.autoUpdateLaterButtonLabel.message messages.autoUpdateLaterButtonLabel.message
], ],
title: locale.messages.autoUpdateNewVersionTitle.message, title: messages.autoUpdateNewVersionTitle.message,
message: locale.messages.autoUpdateNewVersionMessage.message, message: messages.autoUpdateNewVersionMessage.message,
detail: locale.messages.autoUpdateNewVersionInstructions.message, detail: messages.autoUpdateNewVersionInstructions.message,
defaultId: RESTART_BUTTON, defaultId: RESTART_BUTTON,
cancelId: LATER_BUTTON cancelId: LATER_BUTTON
} }
@ -53,12 +52,18 @@ function onError(error) {
console.log("Got an error while updating: ", error.stack); console.log("Got an error while updating: ", error.stack);
} }
function initialize() { function initialize(messages) {
if (!messages) {
throw new Error('auto-update initialize needs localized messages');
}
if (autoUpdateDisabled()) { if (autoUpdateDisabled()) {
return; return;
} }
autoUpdater.addListener('update-downloaded', showUpdateDialog); autoUpdater.addListener('update-downloaded', function() {
showUpdateDialog(messages);
});
autoUpdater.addListener('error', onError); autoUpdater.addListener('error', onError);
checkForUpdates(); checkForUpdates();

10
main.js
View file

@ -44,10 +44,6 @@ const loadLocale = require('./app/locale').load;
let locale; let locale;
function createWindow () { function createWindow () {
if (!locale) {
locale = loadLocale();
}
const windowOptions = Object.assign({ const windowOptions = Object.assign({
width: 800, width: 800,
height: 610, height: 610,
@ -159,7 +155,11 @@ function createWindow () {
app.on('ready', function() { app.on('ready', function() {
console.log('app ready'); console.log('app ready');
autoUpdate.initialize(); if (!locale) {
locale = loadLocale();
}
autoUpdate.initialize(locale.messages);
createWindow(); createWindow();