updateChecker.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. const _ = global._;
  2. const Windows = require('./windows');
  3. const Settings = require('./settings');
  4. const log = require('./utils/logger').create('updateChecker');
  5. const got = require('got');
  6. const semver = require('semver');
  7. /**
  8. * Check for updates to the app.
  9. * @return {[type]} [description]
  10. */
  11. const check = (exports.check = () => {
  12. log.info('Check for update...');
  13. let str = null;
  14. switch (
  15. Settings.uiMode // eslint-disable-line default-case
  16. ) {
  17. case 'mist':
  18. str = 'mist';
  19. break;
  20. case 'wallet':
  21. str = 'wallet';
  22. break;
  23. }
  24. return got('https://api.github.com/repos/ethereum/mist/releases/latest', {
  25. timeout: 30000,
  26. json: true
  27. })
  28. .then(res => {
  29. const release = res.body;
  30. if (!release) {
  31. log.debug('No releases available to check against.');
  32. return;
  33. }
  34. if (semver.gt(release.tag_name, Settings.appVersion)) {
  35. log.info(
  36. `App (${Settings.appVersion}) is out of date. New ${
  37. release.tag_name
  38. } found.`
  39. );
  40. return {
  41. name: release.name,
  42. version: release.tag_name,
  43. url: release.html_url
  44. };
  45. }
  46. log.info('App is up-to-date.');
  47. })
  48. .catch(err => {
  49. log.error('Error checking for update', err);
  50. });
  51. });
  52. function showWindow(options) {
  53. log.debug('Show update checker window');
  54. return Windows.createPopup('updateAvailable', options);
  55. }
  56. exports.run = () => {
  57. check()
  58. .then(update => {
  59. if (update) {
  60. showWindow({
  61. sendData: {
  62. uiAction_checkUpdateDone: update
  63. }
  64. });
  65. }
  66. store.dispatch({ type: '[MAIN]:UPDATE_CHECKER:FINISHED' });
  67. })
  68. .catch(err => {
  69. log.error(err);
  70. });
  71. };
  72. exports.runVisibly = () => {
  73. const wnd = showWindow({
  74. sendData: 'uiAction_checkUpdateInProgress'
  75. });
  76. wnd.on('ready', () => {
  77. check()
  78. .then(update => {
  79. wnd.send({
  80. uiAction_checkUpdateDone: update
  81. });
  82. })
  83. .catch(err => {
  84. log.error(err);
  85. wnd.send('uiAction_checkUpdateDone');
  86. });
  87. });
  88. };