()
| 36 | } |
| 37 | |
| 38 | export async function checkUpdater() { |
| 39 | let updateChannel = 'stable'; |
| 40 | |
| 41 | try { |
| 42 | const store = new Store(); |
| 43 | const settings = store.get('settings') || {}; |
| 44 | updateChannel = settings.updateChannel || 'stable'; |
| 45 | } catch (e) {} |
| 46 | |
| 47 | try { |
| 48 | const url = |
| 49 | updateChannel === 'stable' |
| 50 | ? 'https://gw.alipayobjects.com/os/LightProxy/release.json' |
| 51 | : 'https://gw.alipayobjects.com/os/LightProxy/beta-release.json'; |
| 52 | const res = await fetch(url); |
| 53 | const data = await res.json(); |
| 54 | logger.info('get update info', data); |
| 55 | |
| 56 | if (compareVersions(data.version, version) === 1) { |
| 57 | logger.info(`Version update: ${version} => ${data.version}`); |
| 58 | try { |
| 59 | fs.removeSync(LIGHTPROXY_UPDATE_DIR); |
| 60 | } catch (e) {} |
| 61 | fs.mkdirpSync(LIGHTPROXY_UPDATE_DIR); |
| 62 | |
| 63 | const dl = new DownloaderHelper( |
| 64 | SYSTEM_IS_MACOS ? data['asar_gzip'] : data['win_asar_gzip'], |
| 65 | LIGHTPROXY_UPDATE_DIR, |
| 66 | ); |
| 67 | |
| 68 | const dlPromise = new Promise((resolve, reject) => { |
| 69 | // @ts-ignore |
| 70 | dl.on('end', async downloadInfo => { |
| 71 | const complete = async () => { |
| 72 | logger.info('Download complete'); |
| 73 | const asarPath = downloadInfo.filePath.replace(/\.asar__gzip$/, '.asar'); |
| 74 | |
| 75 | if (fs.existsSync(asarPath)) { |
| 76 | try { |
| 77 | fs.removeSync(asarPath); |
| 78 | } catch (e) {} |
| 79 | } |
| 80 | const afterCompress = await ungzip(fs.readFileSync(downloadInfo.filePath)); |
| 81 | |
| 82 | process.noAsar = true; |
| 83 | fs.writeFileSync(asarPath, afterCompress); |
| 84 | process.noAsar = false; |
| 85 | |
| 86 | fs.writeFileSync( |
| 87 | LIGHTPROXY_UPDATE_CONFIG, |
| 88 | JSON.stringify({ |
| 89 | md5: SYSTEM_IS_MACOS ? data['md5'] : data['win_md5'], |
| 90 | path: asarPath, |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | writeUpdateFreashInfo(); |
| 95 | }; |
no test coverage detected