Skip to content

Commit ffb29ed

Browse files
committed
check for update every 2 days interval.
1 parent 0666145 commit ffb29ed

File tree

8 files changed

+47
-10
lines changed

8 files changed

+47
-10
lines changed

common_library/src/models/IConfigInfo.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import { BaseSchema } from "../schemas";
33

44
export interface IConfigInfo extends BaseSchema {
55
theme:EnumTheme;
6+
checkedForUpdateAt:string;
67
}

src/Startup.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { EnumTheme, IConfigInfo, MainEvents, RendererEvents } from "common_library";
22
import { app, BrowserWindow, Menu } from "electron";
3-
import { autoUpdater } from "electron-updater";
43
import * as path from "path";
54
import { DataManager } from "./businessClasses";
65
import { FileManager } from "./businessClasses/FileManager";
@@ -74,12 +73,22 @@ export class Startup{
7473
SavedData.data.configInfo = (await DB.config.getAll())[0];
7574
if(!SavedData.data.configInfo){
7675
const record={
77-
theme:EnumTheme.Dark,
7876
} as IConfigInfo;
7977
SavedData.data.configInfo= await DB.config.insertAndRemainOneAsync(record);
8078
}
79+
let isUpdated = false;
8180
if(!SavedData.data.configInfo.theme){
8281
SavedData.data.configInfo.theme = EnumTheme.Dark;
82+
isUpdated = true;
83+
}
84+
if(!SavedData.data.configInfo.checkedForUpdateAt){
85+
let lastChecked = new Date(2023,0,1).toISOString();
86+
SavedData.data.configInfo.checkedForUpdateAt = lastChecked;
87+
isUpdated = true;
88+
}
89+
90+
if(isUpdated){
91+
await DB.config.updateOneAsync(SavedData.data.configInfo);
8392
}
8493
}
8594

src/businessClasses/Updater.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class Updater{
4949
}
5050
private checkForUpdate(){
5151
// autoUpdater.checkForUpdatesAndNotify({title:"New version of LithiumGit downloaded",body:"LithiumGit will be updated on application exit."});
52-
autoUpdater.checkForUpdates().then(r=>{
52+
return autoUpdater.checkForUpdates().then(r=>{
5353
this.newVersion = r?.updateInfo?.version;
5454
});
5555
}
@@ -61,8 +61,8 @@ export class Updater{
6161

6262

6363
private handleCheckForUpdate(){
64-
ipcMain.handle(RendererEvents.checkForUpdate,(_e)=>{
65-
this.checkForUpdate();
64+
ipcMain.handle(RendererEvents.checkForUpdate, async (_e)=>{
65+
await this.checkForUpdate();
6666
})
6767
}
6868

src/db_service/BaseDB.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,10 @@ export class BaseDB<T extends BaseSchema>{
160160
updateOneAsync(record:T){
161161
return new Promise<number>((resolve,reject)=>{
162162
this.updateOne(record,(err,updateCount)=>{
163-
if(err) reject(err);
164-
resolve(updateCount);
163+
if(err)
164+
reject(err);
165+
else
166+
resolve(updateCount);
165167
})
166168
});
167169
}

ui/src/components/main/Main.tsx

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnumTheme, INotification, ISavedData, RendererEvents } from "common_library";
1+
import { EnumNotificationType, EnumTheme, ISavedData, RendererEvents } from "common_library";
22
import React from "react";
33
import { useEffect } from "react";
44
import {useDispatch,shallowEqual, batch} from "react-redux";
@@ -10,6 +10,7 @@ import { ModalData } from "../modals/ModalData";
1010
import { RepositorySelection } from "../repositorySelection";
1111
import { SelectedRepository } from "../selectedRepository";
1212
import { IpcUtils } from "../../lib/utils/IpcUtils";
13+
import { getStoreState } from "../../store";
1314

1415
interface IState{
1516
isLoading:boolean;
@@ -23,7 +24,8 @@ function MainComponent(){
2324
const dispatch = useDispatch();
2425
const store = useSelectorTyped(state=>({
2526
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,
2729
}),shallowEqual);
2830
const [state,setState] = useMultiState(initialState);
2931

@@ -53,6 +55,25 @@ function MainComponent(){
5355
loadNotifications();
5456
},[store.notificationLoadV])
5557

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+
5677
useEffect(()=>{
5778
registerIpcEvents();
5879
const savedData:ISavedData = window.ipcRenderer.sendSync(RendererEvents.getSaveData().channel);

ui/src/lib/utils/ReduxUtils.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { IStatus } from "common_library";
2-
import { ILoaderInfo } from "../../store/slices/UiSlice";
32

43
export class ReduxUtils{
54
static setStatus=(status:IStatus)=>{};

ui/src/store/slices/SavedDataSlice.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const initialState:ISavedData={
1717
createdAt: new Date().toISOString(),
1818
theme:EnumTheme.Light,
1919
updateAt:new Date().toISOString(),
20+
checkedForUpdateAt: new Date().toISOString(),
2021
}
2122
}
2223

ui/src/store/store.ts

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ export const ReduxStore = configureStore({
88
reducer: RootReducer,
99
devTools: process.env.NODE_ENV === 'development',
1010
});
11+
12+
export function getStoreState(){
13+
return ReduxStore.getState();
14+
}

0 commit comments

Comments
 (0)