1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 19:49:37 +02:00
flame/client/src/utility/checkVersion.ts

33 lines
948 B
TypeScript
Raw Normal View History

import axios from 'axios';
2022-11-30 20:46:28 +00:00
import { useCreateNotification } from '../state/notification';
2022-11-30 20:46:28 +00:00
export const useCheckVersion = (isForced: boolean = false) => {
const createNotification = useCreateNotification();
return async () => {
try {
const res = await axios.get<string>(
'https://raw.githubusercontent.com/GeorgeSG/flame/master/client/.env'
);
2022-11-30 20:46:28 +00:00
const githubVersion = res.data
.split('\n')
.map((pair) => pair.split('='))[0][1];
2022-11-30 20:46:28 +00:00
if (githubVersion !== process.env.REACT_APP_VERSION) {
createNotification({
title: 'Info',
message: 'New version is available!',
2022-11-30 20:46:28 +00:00
url: 'https://github.com/GeorgeSG/flame/blob/master/CHANGELOG.md',
});
} else if (isForced) {
createNotification({
title: 'Info',
message: 'You are using the latest version!',
2022-11-30 20:46:28 +00:00
});
}
} catch (err) {
console.log(err);
}
2022-11-30 20:46:28 +00:00
};
};