-
Notifications
You must be signed in to change notification settings - Fork 716
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
Auto update when new version is released #411
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
90ee1e9
Initial changes for auto update
alexbrazier 6c19f85
Move publish options to correct location
alexbrazier 43ba28c
Improvements to auto updater
alexbrazier b962ca3
Add option to remind later and skip version in auto update
alexbrazier 1f98e61
Improve style of about and update page
alexbrazier be9f987
Temporarily always publish
alexbrazier c8e35f8
Add option to disable updates
alexbrazier 6151c58
Restore version
alexbrazier 95ec9a8
Merge branch 'develop' into feature/update
alexbrazier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "rocketchat", | ||
"productName": "Rocket.Chat+", | ||
"description": "Rocket.Chat Native Cross-Platform Desktop Application via Electron.", | ||
"version": "2.7.0-develop", | ||
"version": "2.5.0", | ||
"author": "Rocket.Chat Support <[email protected]>", | ||
"copyright": "© 2016, Rocket.Chat", | ||
"homepage": "https://rocket.chat", | ||
|
@@ -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,16 +72,17 @@ | |
}, | ||
"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" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"electron": "^1.6.2", | ||
"electron-builder": "^16.4.2", | ||
"electron-rebuild": "^1.5.7", | ||
"electron-builder": "^16.6.0", | ||
"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,117 @@ | ||
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; | ||
|
||
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 { | ||
try { | ||
const updateFile = userDataDir.read(updateStoreFile, 'json'); | ||
if (updateFile && updateFile.skip === version) { | ||
console.log(`Skipping version: ${version}`); | ||
return; | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
let window = new BrowserWindow({ | ||
width: 600, | ||
height: 350, | ||
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': | ||
userDataDir.write(updateStoreFile, {skip: version}, { 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) => { | ||
checkForUpdatesEvent = e; | ||
autoUpdater.checkForUpdates(); | ||
}); | ||
|
||
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,88 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title></title> | ||
<meta charset="utf-8" /> | ||
<style> | ||
html { | ||
background-color: #ececec; | ||
font-family: helvetica; | ||
padding: 10px; | ||
} | ||
|
||
body { | ||
margin: 0px; | ||
} | ||
|
||
img { | ||
height: 60px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.update { | ||
font-size: 15px; | ||
font-weight: bold; | ||
|
||
position: fixed; | ||
right: 10px; | ||
bottom: 10px; | ||
} | ||
|
||
.skip { | ||
position: fixed; | ||
left: 10px; | ||
} | ||
|
||
.remind { | ||
position: fixed; | ||
right: 150px; | ||
} | ||
|
||
.controls { | ||
font-size: 12px; | ||
position: fixed; | ||
bottom: 17px; | ||
} | ||
|
||
.controls a { | ||
text-decoration: none; | ||
} | ||
|
||
h3 { | ||
text-align: center; | ||
} | ||
|
||
.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> | ||
<p>Current Version: <span class="old"></span> New Version: <span class="new"></span></p> | ||
</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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to change this back, changed for testing purposes.