Skip to content

Commit

Permalink
fix: error with check for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu committed Apr 4, 2024
1 parent 38ee53b commit 9e705ce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 25 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "y2mp3",
"appname": "y2mp3",
"productName": "y2mp3",
"version": "2.6.0",
"version": "2.6.1",
"main": "main.js",
"author": {
"name": "MosheF",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
30 changes: 26 additions & 4 deletions src/services/check-for-update.ts
Original file line number Diff line number Diff line change
@@ -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 = <T extends unknown>(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();
Expand Down
41 changes: 23 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 9e705ce

Please sign in to comment.