Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify auto check for updates #262

Merged
merged 3 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ function migrateData() {
})
});
},

3: configs => {
// Return current configs if checkUpdate and lastCheck do not exist
const { checkUpdate, lastCheck} = configs.general;
if ( checkUpdate === undefined || lastCheck === undefined ) {
return configs;
}
// Remove checkUpdate and lastCheck
return Object.assign({}, configs, {
general: omit(configs.general, ['checkUpdate', 'lastCheck'])
});
},
};
// Get the current Config
const configs = appConfig.getAll();
Expand Down
33 changes: 9 additions & 24 deletions app/components/settings/General.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ class General extends Component {
<div className="row">
<div className="col-md-6">
<div className="pageItem">
<label className="itemLabel">{t('settings:fields:autoCheckUpdate:name')}</label>
<label className="itemLabel">{t('settings:fields:language:name')}</label>
<select
name="checkUpdate"
value={this.state.checkUpdate}
name="language"
value={this.state.language}
onChange={this.handleInputChange}
>
<option value="daily">{t('settings:fields:autoCheckUpdate:daily')}</option>
<option value="weekly">{t('settings:fields:autoCheckUpdate:weekly')}</option>
<option value="de">{t('settings:fields:language:de', { lng: 'de' })}</option>
<option value="en">{t('settings:fields:language:en', { lng: 'en' })}</option>
<option value="fr">{t('settings:fields:language:fr', { lng: 'fr' })}</option>
<option value="id">{t('settings:fields:language:id', { lng: 'id' })}</option>
<option value="vi">{t('settings:fields:language:vi', { lng: 'vi' })}</option>
<option value="zh-CN">{t('settings:fields:language:zh-CN', { lng: 'zh-CN' })}</option>
</select>
</div>
</div>
Expand All @@ -87,25 +91,6 @@ class General extends Component {
</div>
</div>
</div>
<div className="row">
<div className="col-md-6">
<div className="pageItem">
<label className="itemLabel">{t('settings:fields:language:name')}</label>
<select
name="language"
value={this.state.language}
onChange={this.handleInputChange}
>
<option value="de">{t('settings:fields:language:de', { lng: 'de' })}</option>
<option value="en">{t('settings:fields:language:en', { lng: 'en' })}</option>
<option value="fr">{t('settings:fields:language:fr', { lng: 'fr' })}</option>
<option value="id">{t('settings:fields:language:id', { lng: 'id' })}</option>
<option value="vi">{t('settings:fields:language:vi', { lng: 'vi' })}</option>
<option value="zh-CN">{t('settings:fields:language:zh-CN', { lng: 'zh-CN' })}</option>
</select>
</div>
</div>
</div>
</div>
);
}
Expand Down
23 changes: 0 additions & 23 deletions main/auto-check-updates.js

This file was deleted.

39 changes: 20 additions & 19 deletions main/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@ const { autoUpdater } = require('electron-updater');
const appConfig = require('electron-settings');
const isDev = require('electron-is-dev');

// Set mainWindow
const mainWindowID = appConfig.get('mainWindowID');
const mainWindow = BrowserWindow.fromId(mainWindowID);

// Disable Auto Downloading update;
autoUpdater.autoDownload = false;

// Check for update silently
let silentMode = true;

// Set mainWindow
const mainWindowID = appConfig.get('mainWindowID');
const mainWindow = BrowserWindow.fromId(mainWindowID);

// Check for Updates
ipcMain.on('check-for-updates', (event) => {
if(!isDev) {
// Turn off silent mode
silentMode = false;
checkForUpdate();
}
// HANDLING IPC
// Check for updates manually
ipcMain.on('check-for-updates', event => {
// Turn off silent mode first
silentMode = false;
checkForUpdate();
});

// Start Download
ipcMain.on('update-download-started', () => {
autoUpdater.downloadUpdate();
});

// All AutoUpdater Events
// ====================================
// CHECKING FOR UPDATE EVENTS
// Checking for Update
autoUpdater.on('checking-for-update', () => {
// Only notice user when they checked manually
Expand Down Expand Up @@ -58,10 +56,11 @@ autoUpdater.on('error', error => {
errMessage = 'Unknown Error';
} else {
errMessage = error.message;
}
};
mainWindow.send('update-error', errMessage);
});

// DOWNLOADING UPDATE EVENTS
// Download Progress
autoUpdater.on('download-progress', progressObj => {
mainWindow.send('update-download-progress', progressObj.percent);
Expand All @@ -72,11 +71,13 @@ autoUpdater.on('update-downloaded', info => {
mainWindow.send('update-downloaded', info);
});

// Helper
// Main Function
function checkForUpdate() {
autoUpdater.checkForUpdates();
// Only check for update in Production
if (!isDev) {
autoUpdater.checkForUpdates();
}
}

module.exports = {
checkForUpdate,
};
// Check for update on Startup
checkForUpdate();