Skip to content

Commit

Permalink
fix(pages): check update new version when click homePage component ev…
Browse files Browse the repository at this point in the history
…ery time. (#694)
  • Loading branch information
Cheerego7 committed Jun 2, 2021
1 parent 138615d commit a47b8b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
37 changes: 23 additions & 14 deletions desktop/renderer-app/src/pages/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { MainPageLayoutContainer } from "../../components/MainPageLayoutContaine
import { AppUpgradeModal } from "../../components/AppUpgradeModal";
import { useSafePromise } from "../../utils/hooks/lifecycle";
import { runtime } from "../../utils/runtime";
import { globalStore } from "../../stores/GlobalStore";
import { differenceInHours } from "date-fns";

export type HomePageProps = {};

Expand All @@ -29,21 +31,28 @@ export const HomePage = observer<HomePageProps>(function HomePage() {
}, [lastLocation]);

useEffect(() => {
sp(ipcSyncByApp("get-update-info"))
.then(data => {
console.log("[Auto Updater]: Get Update Info");
if (data.hasNewVersion) {
console.log(
`[Auto Updater]: Remote Version "${data.version}", Local Version "${runtime.appVersion}"`,
);
if (data.version !== runtime.appVersion) {
setNewVersion(data.version);
// check for updates only here
const checkUpdateVisible =
differenceInHours(new Date().getTime(), globalStore.checkNewVersionDate) >= 1;

if (checkUpdateVisible) {
sp(ipcSyncByApp("get-update-info"))
.then(data => {
console.log("[Auto Updater]: Get Update Info");
if (data.hasNewVersion) {
console.log(
`[Auto Updater]: Remote Version "${data.version}", Local Version "${runtime.appVersion}"`,
);
if (data.version !== runtime.appVersion) {
setNewVersion(data.version);
}
}
}
})
.catch(err => {
console.error("ipc failed", err);
});
})
.catch(err => {
console.error("ipc failed", err);
});
globalStore.updateCheckNewVersionDate();
}
}, [sp]);

return (
Expand Down
5 changes: 5 additions & 0 deletions desktop/renderer-app/src/stores/GlobalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class GlobalStore {
* Show tooltips for classroom record hints.
* Hide it permanently if user close the tooltip.
*/
public checkNewVersionDate: number = new Date().getTime();
public isShowRecordHintTips = true;
public userInfo: UserInfo | null = null;
public whiteboardRoomUUID: string | null = null;
Expand Down Expand Up @@ -61,6 +62,10 @@ export class GlobalStore {
}
};

public updateCheckNewVersionDate = (): void => {
this.checkNewVersionDate = new Date().getTime();
};

public hideRecordHintTips = (): void => {
this.isShowRecordHintTips = false;
};
Expand Down

0 comments on commit a47b8b3

Please sign in to comment.