mirror of
https://github.com/Vikeo/LifeTrinket.git
synced 2025-11-16 07:47:59 +00:00
check version
This commit is contained in:
2
.github/workflows/firebase-hosting-mege.yml
vendored
2
.github/workflows/firebase-hosting-mege.yml
vendored
@@ -18,3 +18,5 @@ jobs:
|
|||||||
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_LIFE_TRINKET }}'
|
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_LIFE_TRINKET }}'
|
||||||
channelId: live
|
channelId: live
|
||||||
projectId: life-trinket
|
projectId: life-trinket
|
||||||
|
- name: Set READ_ACCESS environment variable
|
||||||
|
run: echo "REPO_READ_ACCESS_TOKEN=${{ secrets.REPO_READ_ACCESS_TOKEN }}" >> $GITHUB_ENV
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "life-trinket",
|
"name": "life-trinket",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"type": "commonjs",
|
"type": "commonjs",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18",
|
"node": ">=18",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useGlobalSettings } from '../../Hooks/useGlobalSettings';
|
|||||||
import { ModalWrapper } from './InfoModal';
|
import { ModalWrapper } from './InfoModal';
|
||||||
import { Separator } from './Separator';
|
import { Separator } from './Separator';
|
||||||
import { Paragraph } from './TextComponents';
|
import { Paragraph } from './TextComponents';
|
||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
const SettingContainer = twc.div`w-full flex flex-col`;
|
const SettingContainer = twc.div`w-full flex flex-col`;
|
||||||
|
|
||||||
@@ -20,6 +21,43 @@ 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);
|
||||||
|
// latestVersion ref
|
||||||
|
const newVersion = useRef<string | undefined>(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function checkIfLatestVersion() {
|
||||||
|
console.log('checking latest version');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await fetch(
|
||||||
|
'https://api.github.com/repos/Vikeo/LifeTrinket/releases/latest',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${process.env.REPO_READ_ACCESS_TOKEN}`,
|
||||||
|
Accept: 'application/vnd.github+json',
|
||||||
|
'X-GitHub-Api-Version': '2022-11-28',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const data = await result.json();
|
||||||
|
|
||||||
|
/* @ts-expect-error is defined in vite.config.ts*/
|
||||||
|
if (data.name === APP_VERSION) {
|
||||||
|
console.log('latestVersion true');
|
||||||
|
|
||||||
|
newVersion.current = data.name;
|
||||||
|
setIsLatestVersion(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('latestVersion false');
|
||||||
|
setIsLatestVersion(false);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('error getting latest version string', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkIfLatestVersion();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={isOpen} onClose={closeModal}>
|
<Modal open={isOpen} onClose={closeModal}>
|
||||||
@@ -98,18 +136,36 @@ export const SettingsModal = ({ isOpen, closeModal }: SettingsModalProps) => {
|
|||||||
)}
|
)}
|
||||||
<Separator height="1px" />
|
<Separator height="1px" />
|
||||||
<SettingContainer>
|
<SettingContainer>
|
||||||
{/* @ts-expect-error is defined in vite.config.ts*/}
|
<Paragraph>
|
||||||
<Paragraph>Version: {APP_VERSION}</Paragraph>
|
{/* @ts-expect-error is defined in vite.config.ts*/}
|
||||||
|
Current version: {APP_VERSION}{' '}
|
||||||
|
{isLatestVersion && (
|
||||||
|
<span className="text-sm text-text-secondary">(latest)</span>
|
||||||
|
)}
|
||||||
|
</Paragraph>
|
||||||
|
{!isLatestVersion && (
|
||||||
|
<Paragraph className="text-text-secondary text-lg text-center">
|
||||||
|
New version ({newVersion.current}) is available!{' '}
|
||||||
|
</Paragraph>
|
||||||
|
)}
|
||||||
|
</SettingContainer>
|
||||||
|
{!isLatestVersion && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
style={{ marginTop: '0.25rem', marginBottom: '0.25rem' }}
|
||||||
onClick={() => window?.location?.reload()}
|
onClick={() => window?.location?.reload()}
|
||||||
>
|
>
|
||||||
Try to update version
|
<span>Update</span>
|
||||||
|
<span className="text-xs"> (reload app)</span>
|
||||||
</Button>
|
</Button>
|
||||||
</SettingContainer>
|
)}
|
||||||
<Separator height="1px" />
|
<Separator height="1px" />
|
||||||
|
|
||||||
<Button variant="contained" onClick={closeModal}>
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
onClick={closeModal}
|
||||||
|
style={{ marginTop: '0.25rem' }}
|
||||||
|
>
|
||||||
Save and Close
|
Save and Close
|
||||||
</Button>
|
</Button>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
Reference in New Issue
Block a user