2021-06-15 12:36:23 +02:00
|
|
|
import axios from 'axios';
|
2022-11-30 20:46:28 +00:00
|
|
|
import { useCreateNotification } from '../state/notification';
|
2021-06-15 12:36:23 +02:00
|
|
|
|
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'
|
|
|
|
);
|
2021-06-15 12:36:23 +02:00
|
|
|
|
2022-11-30 20:46:28 +00:00
|
|
|
const githubVersion = res.data
|
|
|
|
.split('\n')
|
|
|
|
.map((pair) => pair.split('='))[0][1];
|
2021-06-15 12:36:23 +02:00
|
|
|
|
2022-11-30 20:46:28 +00:00
|
|
|
if (githubVersion !== process.env.REACT_APP_VERSION) {
|
2021-10-05 16:31:56 +02:00
|
|
|
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) {
|
2021-10-05 16:31:56 +02:00
|
|
|
createNotification({
|
|
|
|
title: 'Info',
|
|
|
|
message: 'You are using the latest version!',
|
2022-11-30 20:46:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
2021-06-15 12:36:23 +02:00
|
|
|
}
|
2022-11-30 20:46:28 +00:00
|
|
|
};
|
2021-10-05 16:31:56 +02:00
|
|
|
};
|