1
- import { EnumTheme , INotification , ISavedData , RendererEvents } from "common_library" ;
1
+ import { EnumNotificationType , EnumTheme , ISavedData , RendererEvents } from "common_library" ;
2
2
import React from "react" ;
3
3
import { useEffect } from "react" ;
4
4
import { useDispatch , shallowEqual , batch } from "react-redux" ;
@@ -10,6 +10,7 @@ import { ModalData } from "../modals/ModalData";
10
10
import { RepositorySelection } from "../repositorySelection" ;
11
11
import { SelectedRepository } from "../selectedRepository" ;
12
12
import { IpcUtils } from "../../lib/utils/IpcUtils" ;
13
+ import { getStoreState } from "../../store" ;
13
14
14
15
interface IState {
15
16
isLoading :boolean ;
@@ -23,7 +24,8 @@ function MainComponent(){
23
24
const dispatch = useDispatch ( ) ;
24
25
const store = useSelectorTyped ( state => ( {
25
26
selectedRepo :state . savedData . recentRepositories . find ( x => x . isSelected ) ,
26
- notificationLoadV :state . ui . versions . notifications ,
27
+ notificationLoadV :state . ui . versions . notifications ,
28
+ appFocusV :state . ui . versions . appFocused ,
27
29
} ) , shallowEqual ) ;
28
30
const [ state , setState ] = useMultiState ( initialState ) ;
29
31
@@ -53,6 +55,25 @@ function MainComponent(){
53
55
loadNotifications ( ) ;
54
56
} , [ store . notificationLoadV ] )
55
57
58
+ useEffect ( ( ) => {
59
+ const notification = getStoreState ( ) . ui . notifications . find ( _ => _ . type === EnumNotificationType . UpdateAvailable ) ;
60
+ if ( notification )
61
+ return ;
62
+ const checkInterValMinute = 2 * 24 * 60 ;
63
+ const now = new Date ( ) ;
64
+ const config = getStoreState ( ) . savedData . configInfo ;
65
+ const lastChecked = config . checkedForUpdateAt ;
66
+ const nextCheckDate = new Date ( lastChecked ) ;
67
+ nextCheckDate . setMinutes ( nextCheckDate . getMinutes ( ) + checkInterValMinute ) ;
68
+ console . log ( now . toISOString ( ) , nextCheckDate . toISOString ( ) ) ;
69
+ if ( nextCheckDate < now ) {
70
+ console . log ( "checking for update." ) ;
71
+ IpcUtils . checkForUpdate ( ) . then ( r => {
72
+ dispatch ( ActionSavedData . updateConfig ( { ...config , checkedForUpdateAt : now . toISOString ( ) } ) ) ;
73
+ } ) ;
74
+ }
75
+ } , [ store . appFocusV ] )
76
+
56
77
useEffect ( ( ) => {
57
78
registerIpcEvents ( ) ;
58
79
const savedData :ISavedData = window . ipcRenderer . sendSync ( RendererEvents . getSaveData ( ) . channel ) ;
0 commit comments