From c3f9226c9e4f896df0bfc9d76e0d44d0112772cf Mon Sep 17 00:00:00 2001 From: Mosh Feu Date: Thu, 4 Apr 2024 23:29:59 +0200 Subject: [PATCH] fix: error with check for updates (#135) --- package.json | 8 +++--- src/services/api.ts | 1 + src/services/check-for-update.ts | 30 ++++++++++++++++--- tsconfig.json | 3 +- yarn.lock | 49 ++++++++++++++++++-------------- 5 files changed, 60 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index db884ee..26f517e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "y2mp3", "appname": "y2mp3", "productName": "y2mp3", - "version": "2.6.0", + "version": "2.6.1", "main": "main.js", "author": { "name": "MosheF", @@ -37,10 +37,10 @@ "dependencies": { "@types/node": "12.12.21", "async": "^2.6.4", + "axios": "^1.6.8", "cheerio": "^1.0.0-rc.5", "classnames": "^2.2.6", "command-exists": "^1.2.8", - "electron-fetch": "^1.7.4", "electron-is-dev": "^1.0.1", "fix-path": "^2.1.0", "fluent-ffmpeg": "2.1.2", @@ -74,7 +74,7 @@ "autoprefixer": "^9.4.5", "coveralls": "^3.1.1", "css-loader": "^1.0.1", - "electron": "^17.2.0", + "electron": "^17.4.11", "electron-builder": "^23.6.0", "electron-icon-maker": "^0.0.5", "enzyme": "^3.11.0", @@ -90,7 +90,7 @@ "sinon": "^7.2.3", "style-loader": "^0.23.1", "ts-loader": "^9.2.6", - "typescript": "^4.0.5", + "typescript": "^5.4.4", "webpack": "^5.69.1", "webpack-cli": "^4.2.0" }, diff --git a/src/services/api.ts b/src/services/api.ts index 6764cff..4a09f4b 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -191,6 +191,7 @@ const downloadReducer = (action: StateChangeAction) => { new Notification('Download completed', { icon: './app-resources/logo-128.png', body: `The video "${videoTitle}" downloaded successfully`, + // @ts-ignore - no typings for Notification image: thumbnail, }); } diff --git a/src/services/check-for-update.ts b/src/services/check-for-update.ts index 67cb7ad..2d95766 100644 --- a/src/services/check-for-update.ts +++ b/src/services/check-for-update.ts @@ -1,14 +1,36 @@ -import fetch from 'electron-fetch'; import { ipcRenderer } from 'electron'; +import axios from 'axios'; import { showAppHasUpdate } from './modalsAndAlerts'; import store from '../mobx/store'; +const fetch = (url: string) => new Promise<{ + json: () => T, + text: () => string, +}>(async (resolve, reject) => { + try { + const request = await axios.request({ + url, + method: 'GET', + }); + if (request.status >= 200 && request.status < 300) { + resolve({ + json: () => request.data, + text: () => JSON.stringify(request.data), + }); + } else { + reject(request.statusText); + } + } catch (error) { + console.error(error); + reject(error); + } +}); export async function checkForUpdateAndNotify() { const currentVersion = await ipcRenderer.invoke('version'); - const latestVersion = await fetch('https://api.github.com/repos/moshfeu/y2mp3/releases/latest') - .then(data => data.json()) - .then(data => data.name.replace('v', '')); + const latestVersion = await fetch<{ name: string }>('https://api.github.com/repos/moshfeu/y2mp3/releases/latest') + .then(data => data.json()) + .then(data => data.name.replace('v', '')); if (currentVersion !== latestVersion) { store.hasUpdate = true; showAppHasUpdate(); diff --git a/tsconfig.json b/tsconfig.json index 5db652f..d609118 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,8 @@ "module": "CommonJS", "moduleResolution": "node", "jsx": "react", - "experimentalDecorators": true + "experimentalDecorators": true, + "skipLibCheck": true, }, "exclude": [ "node_modules" diff --git a/yarn.lock b/yarn.lock index bf81b9e..9ebd6df 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1936,6 +1936,15 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== +axios@^1.6.8: + version "1.6.8" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" + integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" @@ -3070,13 +3079,6 @@ electron-builder@^23.6.0: simple-update-notifier "^1.0.7" yargs "^17.5.1" -electron-fetch@^1.7.4: - version "1.7.4" - resolved "https://registry.yarnpkg.com/electron-fetch/-/electron-fetch-1.7.4.tgz#af975ab92a14798bfaa025f88dcd2e54a7b0b769" - integrity sha512-+fBLXEy4CJWQ5bz8dyaeSG1hD6JJ15kBZyj3eh24pIVrd3hLM47H/umffrdQfS6GZ0falF0g9JT9f3Rs6AVUhw== - dependencies: - encoding "^0.1.13" - electron-icon-maker@^0.0.5: version "0.0.5" resolved "https://registry.npmjs.org/electron-icon-maker/-/electron-icon-maker-0.0.5.tgz#8b24230df07de61292b7804311fa99e147c1d53d" @@ -3126,10 +3128,10 @@ electron-to-chromium@^1.3.896: resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.14.tgz#b0aa41fbfbf2eff8c2c6f7a871c03075250f8956" integrity sha512-RsGkAN9JEAYMObS72kzUsPPcPGMqX1rBqGuXi9aa4TBKLzICoLf+DAAtd0fVFzrniJqYzpby47gthCUoObfs0Q== -electron@^17.2.0: - version "17.2.0" - resolved "https://registry.yarnpkg.com/electron/-/electron-17.2.0.tgz#a5c42c16352ea968fcb5d1ce256bec51e7d140fe" - integrity sha512-eNXhPVEUofkgAeqRFvTizzYecoCMyS0Rar08WZHSAw9wjfZXawYMvTpjjjk9GiX9W/+Cjxua4YtGn5bOTabc0A== +electron@^17.4.11: + version "17.4.11" + resolved "https://registry.yarnpkg.com/electron/-/electron-17.4.11.tgz#82899a44336bf8f1af15c6312c7f51ae3f4a519b" + integrity sha512-mdSWM2iY/Bh5bKzd5drYS3mf8JWyR9P9UXZA2uLEZ+1fhgLEVkY9qu501QHoMsKlNwgn96EreQC+dfdQ75VTcA== dependencies: "@electron/get" "^1.13.0" "@types/node" "^14.6.2" @@ -3155,13 +3157,6 @@ encodeurl@^1.0.2: resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= -encoding@^0.1.13: - version "0.1.13" - resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.13.tgz#56574afdd791f54a8e9b2785c0582a2d26210fa9" - integrity sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A== - dependencies: - iconv-lite "^0.6.2" - end-of-stream@^1.1.0: version "1.4.4" resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" @@ -3614,6 +3609,11 @@ flush-promises@^1.0.2: resolved "https://registry.yarnpkg.com/flush-promises/-/flush-promises-1.0.2.tgz#4948fd58f15281fed79cbafc86293d5bb09b2ced" integrity sha512-G0sYfLQERwKz4+4iOZYQEZVpOt9zQrlItIxQAAYAWpfby3gbHrx0osCHz5RLl/XoXevXk0xoN4hDFky/VV9TrA== +follow-redirects@^1.15.6: + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + forever-agent@~0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" @@ -6212,6 +6212,11 @@ proto-list@~1.2.1: resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + pseudomap@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" @@ -7372,10 +7377,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" - integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== +typescript@^5.4.4: + version "5.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.4.tgz#eb2471e7b0a5f1377523700a21669dce30c2d952" + integrity sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw== typical@^5.0.0, typical@^5.2.0: version "5.2.0"