Updated version check.

This commit is contained in:
Mike Cao 2022-06-03 07:06:44 -07:00
parent a42ab8677c
commit 9dae76fbf3
2 changed files with 3 additions and 12 deletions

View File

@ -24,7 +24,6 @@ const Intl = ({ children }) => {
export default function App({ Component, pageProps }) { export default function App({ Component, pageProps }) {
const { basePath } = useRouter(); const { basePath } = useRouter();
const { dir } = useLocale(); const { dir } = useLocale();
const version = process.env.VERSION;
return ( return (
<Intl> <Intl>
@ -35,12 +34,6 @@ export default function App({ Component, pageProps }) {
<link rel="icon" type="image/png" sizes="16x16" href={`${basePath}/favicon-16x16.png`} /> <link rel="icon" type="image/png" sizes="16x16" href={`${basePath}/favicon-16x16.png`} />
<link rel="manifest" href={`${basePath}/site.webmanifest`} /> <link rel="manifest" href={`${basePath}/site.webmanifest`} />
<link rel="mask-icon" href={`${basePath}/safari-pinned-tab.svg`} color="#5bbad5" /> <link rel="mask-icon" href={`${basePath}/safari-pinned-tab.svg`} color="#5bbad5" />
<link
rel="preload"
href={`https://i.umami.is/icon.png?v=${version}`}
as="image"
type="image/png"
/>
<meta name="msapplication-TileColor" content="#da532c" /> <meta name="msapplication-TileColor" content="#da532c" />
<meta name="theme-color" content="#fafafa" media="(prefers-color-scheme: light)" /> <meta name="theme-color" content="#fafafa" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#2f2f2f" media="(prefers-color-scheme: dark)" /> <meta name="theme-color" content="#2f2f2f" media="(prefers-color-scheme: dark)" />

View File

@ -4,7 +4,7 @@ import semver from 'semver';
import { VERSION_CHECK } from 'lib/constants'; import { VERSION_CHECK } from 'lib/constants';
import { getItem } from 'lib/web'; import { getItem } from 'lib/web';
const REPO_URL = 'https://api.github.com/repos/mikecao/umami/releases/latest'; const REPO_URL = 'https://api.umami.is/v1/updates';
const initialState = { const initialState = {
current: process.env.VERSION, current: process.env.VERSION,
@ -20,7 +20,7 @@ export async function checkVersion() {
const data = await fetch(REPO_URL, { const data = await fetch(REPO_URL, {
method: 'get', method: 'get',
headers: { headers: {
Accept: 'application/vnd.github.v3+json', Accept: 'application/json',
}, },
}).then(res => { }).then(res => {
if (res.ok) { if (res.ok) {
@ -36,9 +36,7 @@ export async function checkVersion() {
store.setState( store.setState(
produce(state => { produce(state => {
const { tag_name } = data; const { latest } = data;
const latest = tag_name.startsWith('v') ? tag_name.slice(1) : tag_name;
const lastCheck = getItem(VERSION_CHECK); const lastCheck = getItem(VERSION_CHECK);
const hasUpdate = latest && semver.gt(latest, current) && lastCheck?.version !== latest; const hasUpdate = latest && semver.gt(latest, current) && lastCheck?.version !== latest;