main.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <link rel="stylesheet" href="./node_modules/element-ui/lib/theme-default/index.css" />
  6. <style type="text/css">
  7. body {
  8. width: 100%;
  9. height: 100%;
  10. margin: 0;
  11. }
  12. #buttons {
  13. margin: 8px;
  14. }
  15. #progress {
  16. margin: 8px;
  17. }
  18. </style>
  19. <script type="text/javascript" src="./node_modules/vue/dist/vue.js"></script>
  20. <script type="text/javascript" src="./node_modules/element-ui/lib/index.js"></script>
  21. </head>
  22. <body>
  23. <div id="root">
  24. <div id="buttons">
  25. <el-button :loading="checking" @click="checkForUpdates">Check for updates</el-button>
  26. </div>
  27. <div id="progress" v-if="downloading">
  28. <el-progress :text-inside="true" :stroke-width="18" :percentage="progress"></el-progress>
  29. </div>
  30. </div>
  31. <script type="text/javascript">
  32. const { NsisCompatUpdater } = require('nsis-compat-updater');
  33. document.title = `${ nw.App.manifest.name } - ${ nw.App.manifest.version }`;
  34. const app = new Vue({
  35. el: '#root',
  36. data: function() {
  37. return {
  38. checking: false,
  39. downloading: false,
  40. progress: 0,
  41. };
  42. },
  43. methods: {
  44. checkForUpdates() {
  45. const updater = new NsisCompatUpdater('http://127.0.0.1:8080/versions.nsis.json', nw.App.manifest.version, 'x86');
  46. this.checking = true;
  47. updater.checkForUpdates()
  48. .then((version) => {
  49. this.checking = false;
  50. if(version) {
  51. return this.$confirm(`New version of ${ version.version } is available, download now?`)
  52. .then((confirm) => {
  53. if(confirm) {
  54. this.downloading = true;
  55. this.progress = 0;
  56. const handleDownloadProgress = (state) => {
  57. this.percentage = state.percentage;
  58. };
  59. updater.onDownloadProgress.subscribe(handleDownloadProgress);
  60. return updater.downloadUpdate(version.version)
  61. .then((path) => {
  62. updater.onDownloadProgress.unsubscribe(handleDownloadProgress);
  63. this.downloading = false;
  64. this.progress = 0;
  65. return this.$confirm(`New version of ${ version.version } is downloaded, install now?`)
  66. .then((confirm) => {
  67. if(confirm) {
  68. return updater.quitAndInstall(path);
  69. }
  70. else {
  71. this.$message(`Installing cancelled.`);
  72. }
  73. });
  74. })
  75. .catch((err) => {
  76. updater.onDownloadProgress.unsubscribe(handleDownloadProgress);
  77. this.downloading = false;
  78. this.progress = 0;
  79. throw err;
  80. });
  81. }
  82. else {
  83. this.$message(`Downloading cancelled.`);
  84. }
  85. });
  86. }
  87. else {
  88. return this.$alert(`No new version available, the current version is ${ nw.App.manifest.version }.`);
  89. }
  90. })
  91. .catch((err) => {
  92. this.checking = false;
  93. this.$message.error(err.toString());
  94. });
  95. },
  96. },
  97. });
  98. </script>
  99. </body>
  100. </html>