mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-17 00:08:01 +00:00
version check
This commit is contained in:
@@ -22,12 +22,13 @@ type SettingsModalProps = {
|
|||||||
export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
||||||
const { settings, setSettings, isPWA } = useGlobalSettings();
|
const { settings, setSettings, isPWA } = useGlobalSettings();
|
||||||
const [isLatestVersion, setIsLatestVersion] = useState(false);
|
const [isLatestVersion, setIsLatestVersion] = useState(false);
|
||||||
// latestVersion ref
|
|
||||||
const newVersion = useRef<string | undefined>(undefined);
|
const newVersion = useRef<string | undefined>(undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!isOpen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
async function checkIfLatestVersion() {
|
async function checkIfLatestVersion() {
|
||||||
console.log('checking latest version');
|
|
||||||
try {
|
try {
|
||||||
const result = await fetch(
|
const result = await fetch(
|
||||||
'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest',
|
'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest',
|
||||||
@@ -43,7 +44,6 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
|||||||
const data = await result.json();
|
const data = await result.json();
|
||||||
|
|
||||||
if (!data.name) {
|
if (!data.name) {
|
||||||
console.log('no version string found, result:', result);
|
|
||||||
setIsLatestVersion(false);
|
setIsLatestVersion(false);
|
||||||
newVersion.current = undefined;
|
newVersion.current = undefined;
|
||||||
return;
|
return;
|
||||||
@@ -51,21 +51,17 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
|||||||
|
|
||||||
/* @ts-expect-error is defined in vite.config.ts*/
|
/* @ts-expect-error is defined in vite.config.ts*/
|
||||||
if (data.name === APP_VERSION) {
|
if (data.name === APP_VERSION) {
|
||||||
console.log('latestVersion true');
|
|
||||||
|
|
||||||
newVersion.current = data.name;
|
newVersion.current = data.name;
|
||||||
setIsLatestVersion(true);
|
setIsLatestVersion(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('latestVersion false');
|
|
||||||
setIsLatestVersion(false);
|
setIsLatestVersion(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error getting latest version string', error);
|
console.error('error getting latest version string', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkIfLatestVersion();
|
checkIfLatestVersion();
|
||||||
}, []);
|
}, [isOpen]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={isOpen} onClose={closeModal}>
|
<Modal open={isOpen} onClose={closeModal}>
|
||||||
|
|||||||
Reference in New Issue
Block a user