-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from RocketChat/feature/update
Auto update when new version is released
- Loading branch information
Showing
8 changed files
with
369 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"description": "Rocket.Chat Native Cross-Platform Desktop Application via Electron.", | ||
"version": "2.7.0-develop", | ||
"author": "Rocket.Chat Support <[email protected]>", | ||
"copyright": "© 2016, Rocket.Chat", | ||
"copyright": "© 2017, Rocket.Chat", | ||
"homepage": "https://rocket.chat", | ||
"license": "MIT", | ||
"main": "app/background.js", | ||
|
@@ -48,7 +48,15 @@ | |
"deb", | ||
"rpm" | ||
] | ||
}, | ||
"publish": [ | ||
{ | ||
"provider": "github", | ||
"owner": "RocketChat", | ||
"repo": "Rocket.Chat.Electron", | ||
"vPrefixedTagName": false | ||
} | ||
] | ||
}, | ||
"scripts": { | ||
"postinstall": "install-app-deps && electron-rebuild", | ||
|
@@ -64,6 +72,7 @@ | |
}, | ||
"dependencies": { | ||
"@paulcbetts/system-idle-time": "^1.0.4", | ||
"electron-updater": "^1.11.2", | ||
"fs-jetpack": "^0.13.3", | ||
"lodash": "^4.17.4", | ||
"spellchecker": "^3.3.1" | ||
|
@@ -72,8 +81,8 @@ | |
"chai": "^3.5.0", | ||
"electron": "^1.6.2", | ||
"electron-builder": "^16.8.2", | ||
"electron-rebuild": "^1.5.7", | ||
"electron-mocha": "^3.4.0", | ||
"electron-rebuild": "^1.5.7", | ||
"gulp": "^3.9.1", | ||
"gulp-batch": "^1.0.5", | ||
"gulp-less": "^3.3.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { app, ipcMain, BrowserWindow, dialog } from 'electron'; | ||
import { autoUpdater } from 'electron-updater'; | ||
import jetpack from 'fs-jetpack'; | ||
|
||
const userDataDir = jetpack.cwd(app.getPath('userData')); | ||
const updateStoreFile = 'update.json'; | ||
let checkForUpdatesEvent; | ||
|
||
autoUpdater.autoDownload = false; | ||
|
||
let updateFile = {}; | ||
try { | ||
updateFile = userDataDir.read(updateStoreFile, 'json') || {}; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
|
||
function updateDownloaded () { | ||
dialog.showMessageBox({ | ||
title: 'Update Ready to Install', | ||
message: 'Update has been downloaded', | ||
buttons: [ | ||
'Install Later', | ||
'Install Now' | ||
], | ||
defaultId: 1 | ||
}, (response) => { | ||
if (response === 0) { | ||
dialog.showMessageBox({ | ||
title: 'Installing Later', | ||
message: 'Update will be installed when you exit the app' | ||
}); | ||
} else { | ||
autoUpdater.quitAndInstall(); | ||
} | ||
}); | ||
} | ||
|
||
function updateAvailable ({version}) { | ||
if (checkForUpdatesEvent) { | ||
checkForUpdatesEvent.sender.send('update-result', true); | ||
} else if (updateFile.skip === version) { | ||
console.log(`Skipping version: ${version}`); | ||
return; | ||
} | ||
|
||
let window = new BrowserWindow({ | ||
title: 'Update Available', | ||
width: 600, | ||
height: 330, | ||
show : false, | ||
center: true, | ||
resizable: false, | ||
maximizable: false, | ||
minimizable: false | ||
}); | ||
|
||
window.loadURL(`file://${__dirname}/public/update.html`); | ||
window.setMenuBarVisibility(false); | ||
|
||
window.webContents.on('did-finish-load', () => { | ||
window.webContents.send('new-version', version); | ||
window.show(); | ||
}); | ||
|
||
ipcMain.once('update-response', (e, type) => { | ||
switch (type) { | ||
case 'skip': | ||
updateFile.skip = version; | ||
userDataDir.write(updateStoreFile, updateFile, { atomic: true }); | ||
dialog.showMessageBox({ | ||
title: 'Skip Update', | ||
message: 'We will notify you when the next update is available\n' + | ||
'If you change your mind you can check for updates from the About menu.' | ||
}, () => window.close()); | ||
break; | ||
case 'remind': | ||
dialog.showMessageBox({ | ||
title: 'Remind Later', | ||
message: 'We will remind you next time you start the app' | ||
}, () => window.close()); | ||
break; | ||
case 'update': | ||
dialog.showMessageBox({ | ||
title: 'Downloading Update', | ||
message: 'You will be notified when the update is ready to be installed' | ||
}, () => window.close()); | ||
autoUpdater.downloadUpdate(); | ||
break; | ||
} | ||
}); | ||
|
||
window.on('closed', () => { | ||
window = null; | ||
ipcMain.removeAllListeners('update-response'); | ||
}); | ||
} | ||
|
||
function checkForUpdates () { | ||
autoUpdater.on('update-available', updateAvailable); | ||
|
||
autoUpdater.on('download-progress', ({percent}) => { | ||
console.log(`Update progress: ${percent}`); | ||
}); | ||
|
||
autoUpdater.on('update-downloaded', updateDownloaded); | ||
|
||
// Event from about window | ||
ipcMain.on('check-for-updates', (e, autoUpdate) => { | ||
if (autoUpdate === true || autoUpdate === false) { | ||
updateFile.autoUpdate = autoUpdate; | ||
userDataDir.write(updateStoreFile, updateFile, { atomic: true }); | ||
} else if (autoUpdate === 'auto') { | ||
e.returnValue = updateFile.autoUpdate; | ||
} else { | ||
checkForUpdatesEvent = e; | ||
autoUpdater.checkForUpdates(); | ||
} | ||
}); | ||
|
||
if (updateFile.autoUpdate !== false) { | ||
autoUpdater.checkForUpdates(); | ||
} | ||
} | ||
|
||
export { | ||
checkForUpdates | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title></title> | ||
<meta charset="utf-8" /> | ||
<style> | ||
html { | ||
background-color: #ececec; | ||
font-family: helvetica; | ||
padding: 10px; | ||
} | ||
|
||
body { | ||
margin: 0px; | ||
text-align: center; | ||
} | ||
|
||
img { | ||
height: 60px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
table { | ||
margin: 0 auto; | ||
} | ||
|
||
.update { | ||
font-size: 15px; | ||
font-weight: bold; | ||
color: #fff; | ||
background-color: #13679a; | ||
border-width: 0; | ||
padding: 6px 8px; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
position: fixed; | ||
right: 10px; | ||
bottom: 5px; | ||
} | ||
|
||
.skip { | ||
position: fixed; | ||
left: 10px; | ||
} | ||
|
||
.remind { | ||
position: fixed; | ||
right: 150px; | ||
} | ||
|
||
.controls { | ||
font-size: 12px; | ||
position: fixed; | ||
bottom: 15px; | ||
} | ||
|
||
.controls a { | ||
text-decoration: none; | ||
} | ||
|
||
.old, .new { | ||
font-weight: bold; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h3>New Update is Available</h3> | ||
<hr /> | ||
<div style="text-align:center;"> | ||
<img src="images/icon.png"/> | ||
<p>A new version of the Rocket.Chat Desktop App is available!</p> | ||
<table> | ||
<tr> | ||
<td style="text-align:right;">Current Version:</td> | ||
<td class="old"></td> | ||
</tr> | ||
<tr> | ||
<td style="text-align:right;">New Version:</td> | ||
<td class="new"></td> | ||
</tr> | ||
</table> | ||
</div> | ||
<hr /> | ||
<p class="controls"> | ||
<a class="skip response" data-type="skip" href="#">Skip This Version</a> | ||
<a class="remind response" data-type="remind" href="#">Remind Me Later</a> | ||
<button class="update response" data-type="update">Install Update</button> | ||
</p> | ||
<script> | ||
const remote = require('electron').remote; | ||
require('electron').ipcRenderer.on('new-version', function(e, version) { | ||
document.querySelector('.old').innerHTML = remote.app.getVersion(); | ||
document.querySelector('.new').innerHTML = version; | ||
}); | ||
document.querySelectorAll('.response').forEach((item) => { | ||
item.onclick = function(e) { | ||
const type = e.target.getAttribute('data-type'); | ||
require('electron').ipcRenderer.send('update-response', type); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.