@@ -3,11 +3,19 @@ import type { Release } from '@octokit/webhooks-types';
33import type { FC } from 'react' ;
44import { useEffect } from 'react' ;
55
6- import { setLatestRelease , setReleases } from '@/slices/github' ;
6+ import {
7+ setLatestAppRelease ,
8+ setLatestRelease ,
9+ setReleases ,
10+ } from '@/slices/github' ;
711
812import ago from '@/utils/ago' ;
913
10- import { GithubBaseConfig , useGithub } from '@/github/index' ;
14+ import {
15+ AppGithubBaseConfig ,
16+ OpenDTUGithubBaseConfig ,
17+ useGithub ,
18+ } from '@/github/index' ;
1119import { useAppDispatch , useAppSelector } from '@/store' ;
1220
1321const FetchHandler : FC = ( ) => {
@@ -26,6 +34,16 @@ const FetchHandler: FC = () => {
2634 : true ,
2735 ) ;
2836
37+ const latestAppReleaseRefetchOk = useAppSelector ( state =>
38+ state . github . latestAppRelease . lastUpdate
39+ ? ago ( state . github . latestAppRelease . lastUpdate ) > 1000 * 60 * 10 // 10 minutes
40+ : true ,
41+ ) ;
42+
43+ const enableAppUpdates = useAppSelector (
44+ state => ! ! state . settings . enableAppUpdates ,
45+ ) ;
46+
2947 const githubApi = useGithub ( ) ;
3048
3149 useEffect ( ( ) => {
@@ -38,7 +56,7 @@ const FetchHandler: FC = () => {
3856 if ( latestReleaseRefetchOk ) {
3957 const latestRelease = await githubApi . request (
4058 'GET /repos/{owner}/{repo}/releases/latest' ,
41- GithubBaseConfig ,
59+ OpenDTUGithubBaseConfig ,
4260 ) ;
4361
4462 dispatch ( setLatestRelease ( { latest : latestRelease . data as Release } ) ) ;
@@ -49,13 +67,24 @@ const FetchHandler: FC = () => {
4967 if ( allReleasesRefetchOk ) {
5068 const releases = await githubApi . request (
5169 'GET /repos/{owner}/{repo}/releases' ,
52- GithubBaseConfig ,
70+ OpenDTUGithubBaseConfig ,
5371 ) ;
5472
5573 dispatch ( setReleases ( { releases : releases . data as Release [ ] } ) ) ;
5674 } else {
5775 console . log ( 'SKIP allReleasesRefetchOk' ) ;
5876 }
77+
78+ if ( latestAppReleaseRefetchOk && enableAppUpdates ) {
79+ const appRelease = await githubApi . request (
80+ 'GET /repos/{owner}/{repo}/releases/latest' ,
81+ AppGithubBaseConfig ,
82+ ) ;
83+
84+ dispatch ( setLatestAppRelease ( { latest : appRelease . data as Release } ) ) ;
85+ } else {
86+ console . log ( 'SKIP latestAppReleaseRefetchOk' ) ;
87+ }
5988 } catch ( e ) {
6089 console . warn ( 'GITHUB FETCH ERROR' , e ) ;
6190 }
@@ -68,6 +97,8 @@ const FetchHandler: FC = () => {
6897 githubApi ,
6998 latestReleaseRefetchOk ,
7099 allReleasesRefetchOk ,
100+ latestAppReleaseRefetchOk ,
101+ enableAppUpdates ,
71102 ] ) ;
72103
73104 return null ;
0 commit comments