Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (data.type === 'quit') {
// 窗口设置了closeable为false后不能退出程序,手动再设置一下
mainWindow.setClosable(true)
app.quit()
// eslint-disable-next-line no-empty
} else if (data.type === 'searchKey') {
} else if (data.type === 'openStart') {
if (data.data) {
openAutoStart()
} else {
openDisStart()
}
} else if (data.type === 'newEmail') {
newEmail(data.data.data, data.data.telUser, {
version: autoUpdater.currentVersion,
emailType: data.data.emailType
}).then(() => {
event.sender.send('sendnewEmail', 'success', data.data.emailType)
}).catch((error) => {
event.sender.send('sendnewEmail', 'error', data.data.emailType, error)
})
} else if (data.type === 'check_newVersion') {
checkUpdater()
}
else if (data.type === 'setDefaultDownPath'){
mainWindow.setAlwaysOnTop(false)
dialog.showOpenDialog({
properties: ['openDirectory', 'createDirectory', 'promptToCreate'],
message: '选择要下载图片所在文件夹',
defaultPath: data.data },
(paths) => {
autoUpdater.on('update-available', (info) => {
dialog.showMessageBox({
type: 'info',
buttons: ['是', '否'],
title: '版本更新',
message: `当前版本:${autoUpdater.currentVersion}`,
detail: `检测到新版本:${info.version},是否升级?`,
// eslint-disable-next-line no-undef
icon: path.resolve(__static, './img/banben.png')
}, (response) => {
if (response === 0) {
autoUpdater.downloadUpdate()
} else if (response === 1) {
console.log('1')
}
})
log.info('检测到新版本', info)
})
autoUpdater.on('update-not-available', (info) => {
if (openAppFlag) {
openAppFlag = false
return
}
log.error('没有检测到新版本', info)
dialog.showMessageBox({
type: 'info',
buttons: ['关闭'],
title: '版本更新',
message: `当前版本:${autoUpdater.currentVersion}`,
detail: '当前已是最新版本,无需更新',
// eslint-disable-next-line no-undef
icon: path.resolve(__static, './img/banben.png')
})
})
// @flow
// app updater
import path from 'path'
import fs from 'fs'
import { autoUpdater as updater } from 'electron-updater'
import createLogger from './log'
import { getConfig } from './config'
import type { UpdateInfo } from '@opentrons/app/src/shell'
import type { Action, Dispatch, PlainError } from './types'
updater.logger = createLogger('update')
updater.autoDownload = false
export const CURRENT_VERSION: string = updater.currentVersion.version
export const CURRENT_RELEASE_NOTES: string = fs.readFileSync(
// NOTE: __dirname refers to output directory
path.join(__dirname, '../build/release-notes.md'),
'utf8'
)
export function registerUpdate(dispatch: Dispatch) {
return function handleAction(action: Action) {
switch (action.type) {
case 'shell:CHECK_UPDATE':
return checkUpdate(dispatch)
case 'shell:DOWNLOAD_UPDATE':
return downloadUpdate(dispatch)
case 'shell:APPLY_UPDATE':
storage.get('update_channel', (error, data) => {
const channel = data.channel || 'latest';
if (channel === 'latest') {
autoUpdater.allowPrerelease = false;
} else {
autoUpdater.allowPrerelease = true;
}
console.log(`Setting allowPrerelease to ${autoUpdater.allowPrerelease}`);
if (error) {
console.log(`Error found checking updates: ${error}`);
}
console.log(`Auto Updater is set to ${autoUpdater.channel}`);
console.log(`Current version of the app is ${autoUpdater.currentVersion}`);
autoUpdater.checkForUpdates();
});
}
},
{
role: 'help',
submenu: [
{
label: 'View GitHub',
click () { loadExternal('https://github.com/cronoh/nanovault') }
},
{
label: 'Submit Issue',
click () { loadExternal('https://github.com/cronoh/nanovault/issues/new') }
},
{type: 'separator'},
{
type: 'normal',
label: `NanoVault Version: ${autoUpdater.currentVersion}`,
},
{
label: 'View Latest Updates',
click () { loadExternal('https://github.com/cronoh/nanovault/releases') }
},
{type: 'separator'},
{
label: `Check for Updates...`,
click (menuItem, browserWindow) {
checkForUpdates();
}
},
]
}
];
public async loaderReady() {
if (!isProduction()) {
this.windowsHandler.sendToLoader('no-update-found');
return;
}
logger.info('Server', 'Checking for updates.');
autoUpdater.allowPrerelease = true;
autoUpdater.signals.progress((progress: ProgressInfo) => {
this.windowsHandler.sendToLoader('update-progress', Math.round(progress.percent));
});
autoUpdater.signals.updateDownloaded(() => {
autoUpdater.quitAndInstall(true, true);
});
try {
const lastUpdate: UpdateCheckResult = await autoUpdater.checkForUpdates();
if (compareVersion(lastUpdate.updateInfo.version, autoUpdater.currentVersion.version) === 1) {
logger.info('Server', `Update ${lastUpdate.updateInfo.version} found.`);
this.windowsHandler.sendToLoader('update-found', lastUpdate.updateInfo.version);
} else {
logger.info('Server', 'No updates found.');
this.windowsHandler.sendToLoader('no-update-found');
}
} catch (error) {
logger.info('Server', 'Internet is offline, aborting updates checking.');
this.windowsHandler.sendToLoader('no-update-found');
}
}
},
{
role: 'help',
submenu: [
{
label: 'View GitHub',
click () { loadExternal('https://github.com/cronoh/nanovault') }
},
{
label: 'Submit Issue',
click () { loadExternal('https://github.com/cronoh/nanovault/issues/new') }
},
{type: 'separator'},
{
type: 'normal',
label: `NanoVault Version: ${autoUpdater.currentVersion}`,
},
{
label: 'View Latest Updates',
click () { loadExternal('https://github.com/cronoh/nanovault/releases') }
},
{type: 'separator'},
{
label: `Check for Updates...`,
click (menuItem, browserWindow) {
checkForUpdates();
}
},
]
}
];
app.on('ready', async function() {
initAutoUpdate();
try {
const {versionInfo, updateInfo} = await autoUpdater.checkForUpdates();
if (semver.lt(autoUpdater.currentVersion.raw, updateInfo.version)) {
let changelogWin = await openChangelog(updateInfo.version);
changelogWin.on('closed', () => {
changelogWin = null;
});
const updateChoice = await dialog.showMessageBox(null, {
type: 'info',
title: 'Update Available',
message: `Version ${updateInfo.version} is now available.`,
buttons: ['Update', 'Later'],
cancelId: 1
});
if (changelogWin) {
changelogWin.close();
}