{"_id":"@adouming/electron-asar-hot-updater","_rev":"1-8fca2f18309a7ed44e4ba4b119bba18d","name":"@adouming/electron-asar-hot-updater","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.3":{"name":"@adouming/electron-asar-hot-updater","version":"0.1.3","description":"Handles Electron app.asar updates.","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/yansenlei/electron-asar-hot-updater.git"},"keywords":["electron","asar","atom shell","update","updater"],"author":{"name":"leiyswork@gmail.com"},"license":"MIT","dependencies":{"adm-zip":"^0.4.11","electron-log":"^4.1.1","original-fs":"^1.0.0","request":"^2.87.0","@adouming/request-progress":"^3.0.1","semver-diff":"^3.0.0"},"gitHead":"5a1a08ad0f8565fe541f03ef07bf77ac18b1751d","bugs":{"url":"https://github.com/yansenlei/electron-asar-hot-updater/issues"},"homepage":"https://github.com/yansenlei/electron-asar-hot-updater#readme","_id":"@adouming/electron-asar-hot-updater@0.1.3","_nodeVersion":"16.13.2","_npmVersion":"8.3.2","dist":{"integrity":"sha512-m8AWAOfWj+A3+HptPpig30cOgVXVmVM2fXqQLohh+dLzR3Vi+/FO14XxWcqdz+yu8seOhkD5+TRFAeY+UKBUYg==","shasum":"7af12bff5162ac59732333d9c2be9a56ce155acc","tarball":"https://registry.npmjs.org/@adouming/electron-asar-hot-updater/-/electron-asar-hot-updater-0.1.3.tgz","fileCount":11,"unpackedSize":36273,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiD04uACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo5nxAAiNqV+l8jockVG0Sp5VZh3JqcO+OAcbJdRxoArAY8o8C0fd8J\r\n6/me2Ksgo7pFS5xT7jwPHz2NTGS6F2BytTtpGvTUbABOZAhli3pUy8kJnsDE\r\n9kORfFezXfGJ5kGF2l0JpmV96gERh/V3DyWK0K4Y8zNUSDsiGbk+b+bRTPfC\r\n4cP+plOkt5i9PknYiwYFIJDE41hV/HU94/xdpHl7VBRhVNOGnewSGMfqwJC5\r\ncP8Lghrmer0+gF9h5fEhRd7pg3WHI7UvxL8CRGvWS3KfbeekYXzm14t9OQBM\r\nP3aXSb+1RMCjLxud1O8tmmrtaSQxA2f+EIVc6w3XtIGmSCI9eF6Ws8DgmRqL\r\nSOfyudqkl8ALGdIaCvqCvyjJJ/c9jmAD1AYPniVTtKpB9xsk800DxCzO50Vr\r\nPUwqveZfvcLZ8/JVrkfTUkXuU+lgifRwBu7Us37+z1QusVT4cyOe3P7yO6w7\r\n/2IUyt6a+UnoJ2VDTTLv4iMSWEx/B1j6D7gXjI3FwH1eq/8/ubmmk3pxuIi0\r\nmzZ4rMvx/6KzxU2i4FJj0X1dprM2j/oX7QOY35E5JvpD5ve/GzMuOudp9I4c\r\n7vw/oOPWmWF9YJhMlVz+wi70Ne+PysQWaxBOpfnozE9XIKd4/Wan0TKNmTmH\r\nODfLUOSaPmMlX0J/7HpjNFUinOV82fu2kkQ=\r\n=DyHa\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDvhoFS37ODGKsZEB0V67O6lZT8J5iWQHJdCXnMoZxdYwIhAMUvIU0JGnbzBXQxO05D/q510s7u/4FJ21ws2qDENS10"}]},"_npmUser":{"name":"adouming","email":"156530445@qq.com"},"directories":{},"maintainers":[{"name":"adouming","email":"156530445@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/electron-asar-hot-updater_0.1.3_1645170222565_0.0052646494094794605"},"_hasShrinkwrap":false}},"time":{"created":"2022-02-18T07:43:42.500Z","0.1.3":"2022-02-18T07:43:42.718Z","modified":"2022-04-04T11:36:31.222Z"},"maintainers":[{"name":"adouming","email":"156530445@qq.com"}],"description":"Handles Electron app.asar updates.","homepage":"https://github.com/yansenlei/electron-asar-hot-updater#readme","keywords":["electron","asar","atom shell","update","updater"],"repository":{"type":"git","url":"git+https://github.com/yansenlei/electron-asar-hot-updater.git"},"author":{"name":"leiyswork@gmail.com"},"bugs":{"url":"https://github.com/yansenlei/electron-asar-hot-updater/issues"},"license":"MIT","readme":"# electron-asar-hot-updater\r\n\r\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fyansenlei%2Felectron-asar-hot-updater.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fyansenlei%2Felectron-asar-hot-updater?ref=badge_shield)\r\n[![npm version](https://badge.fury.io/js/electron-asar-hot-updater.svg)](https://badge.fury.io/js/electron-asar-hot-updater)\r\n\r\n[![NPM](https://nodei.co/npm/electron-asar-hot-updater.png)](https://nodei.co/npm/electron-asar-hot-updater/)\r\n\r\n[中文文档](README-CN.md) | English\r\n\r\n[Update demo](https://github.com/yansenlei/asar-update-project)\r\n\r\n## What it is\r\n> A NodeJs module for Electron, that handles app.asar updates. Reconstruction of `electron-asar-updater`\r\n\r\n## How it works (Read this first)\r\n* EAU (Electron Asar Updater) was built upon _Electron Application Updater_ to handle the process of updating the app.asar file inside an Electron app ; **it simply replaces the app.asar file (at /resources/) with the new one called \"update.asar\"!**\r\n* The check for \"updates\" must by triggered by the application. **EAU doesn't make any kind of periodic checks on its own**.\r\n* EAU talks to an API (let's call it so) to tell it if there is a new update.\r\n    * The API receives a request from EAU with the client's **current version of the application (must be specified inside the application package.json file)**.\r\n    * The API then responds with the new update, ... or simply *false* to abort.\r\n    * If there's an update available the API should respond with the *source* for this update **update.asar** file.\r\n    * EAU then downloads the .asar file, deletes the old app.asar and renames the update.asar to app.asar.\r\n\r\n## But why ? (use cases)\r\n* If you think these are too complicated to implement:\r\nhttps://www.npmjs.com/package/electron-updater\r\nhttp://electron.atom.io/docs/v0.33.0/api/auto-updater/\r\n* If you don't think it's reasonable to update the hole .app or .exe file (up to 100MB) when you're only changing one file (usually 40MB).\r\n* If you want to see `progress` when updating.\r\n* If you want to `check` the version on the `server side` or on the `client side`.\r\n* If you want to use `zip` to compress files, make your ASAR file smaller.\r\n\r\n---\r\n\r\n## Installation\r\n```bash\r\n$ npm install --save electron-asar-hot-updater\r\n```\r\nNow, inside the *main.js* file, call it like this:\r\n```js\r\nconst { app, dialog } = require('electron');\r\nconst EAU = require('electron-asar-hot-updater');\r\n\r\napp.on('ready', function () {\r\n  // Initiate the module\r\n  EAU.init({\r\n    'api': 'http://...', // The API EAU will talk to\r\n    'server': false, // Where to check. true: server side, false: client side, default: true.\r\n    'debug': false, // Default: false.\r\n    'headers': { Authorization: 'token' }, // Default: {}\r\n    'body': {\r\n      name: packageInfo.name,\r\n      current: packageInfo.version\r\n    }, // Default: name and the current version\r\n    'formatRes': function(res) { return res } // Optional,Format the EAU.check response body, exemple => {version: xx, asar: xx}\r\n  });\r\n\r\n  EAU.check(function (error, last, body) {\r\n    if (error) {\r\n      if (error === 'no_update_available') { return false; }\r\n      if (error === 'version_not_specified' && process.env.NODE_ENV === 'development') { return false } // Don't worry about this error when developing\r\n      dialog.showErrorBox('info', error)\r\n      return false\r\n    }\r\n\r\n    EAU.progress(function (state) {\r\n      // The state is an object that looks like this:\r\n      // {\r\n      //     percent: 0.5,               \r\n      //     speed: 554732,              \r\n      //     size: {\r\n      //         total: 90044871,        \r\n      //         transferred: 27610959   \r\n      //     },\r\n      //     time: {\r\n      //         elapsed: 36.235,        \r\n      //         remaining: 81.403       \r\n      //     }\r\n      // }\r\n    })\r\n\r\n    EAU.download(function (error) {\r\n      if (error) {\r\n        dialog.showErrorBox('info', error)\r\n        return false\r\n      }\r\n      // dialog.showErrorBox('info', 'App updated successfully! Restart it please.')\r\n      if (process.platform === 'darwin') {\r\n        app.relaunch()\r\n        app.quit()\r\n      } else {\r\n        app.quit()\r\n      }\r\n    })\r\n\r\n  })\r\n})\r\n```\r\n\r\n## The update server\r\nThe server can return the version details, for example\r\n```js\r\nconst express = require('express')\r\nvar bodyParser = require('body-parser');\r\nconst app = express()\r\n\r\napp.use(bodyParser.json());\r\napp.use(bodyParser.urlencoded({ extended: false }));\r\n\r\nvar desktop_app_version = '1.0.0';\r\nvar desktop_app_URL = 'http://127.0.0.1:8083/update.asar' // or ../update.zip\r\n\r\napp.post('/update', function (req, res) {\r\n  if(req.body && req.body.current != desktop_app_version){ // check for server side\r\n    res.write(JSON.stringify( {\"last\": desktop_app_version, \"source\": desktop_app_URL} ).replace(/[\\/]/g, '\\\\/') );\r\n  }else{\r\n    res.write(JSON.stringify( {\"last\": desktop_app_version} ).replace(/[\\/]/g, '\\\\/') );\r\n  }\r\n  res.end();\r\n});\r\n\r\napp.listen(3000)\r\nconsole.log('run port: 3000')\r\n```\r\nOr you can return version information for client to check\r\n```js\r\napp.post('/update', function (req, res) {\r\n  res.write(JSON.stringify( {\r\n    \"name\": \"app\",\r\n    \"version\": \"0.0.1\",\r\n    \"asar\": \"http://127.0.0.1:8083/update.asar\",\r\n    \"sha1\": \"203448645d8a32b9a08ca9a0eb88006f874d0c78\", // Optional, If set, verify `asar` file legitimacy\r\n    \"info\": \"1.fix bug\\n2.feat...\"\r\n  } ).replace(/[\\/]/g, '\\\\/') );\r\n  res.end();\r\n});\r\n```\r\nIf you use a zip file, the plug-in will unzip the file after downloading it, which will make your update file smaller, but you must make sure that `update.asar` is at the root of the zip package:\r\n```\r\n── update.zip\r\n   └── update.asar\r\n```\r\n\r\nNow uses a really dumb-but-simple .exe to update\r\n\r\nThis is to get around the fact that the prompt text from the timeout command was always being shown, even when redirecting to NUL\r\n\r\nThe updater.exe is a really simple C# console app, compiled with [Mono](http://www.mono-project.com).\r\n[Source code](./updater.cs). from [electron-asar-updater pull #2](https://github.com/whitesmith/electron-asar-updater/pull/2). If the user system version is win7, you may need to manually install [.Net framework](https://dotnet.microsoft.com/download/dotnet-framework) first.\r\n\r\n## License\r\n\r\n:smiley: if you have any comments or wish to contribute to this project, you are welcome to submit Issues or PR.\r\n\r\nMIT - [yansenlei](https://github.com/yansenlei)\r\n","readmeFilename":"README.md"}