Skip to content

Commit

Permalink
Added auto-update test
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrho committed Oct 24, 2024
1 parent 7bec178 commit 1dbcfe7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jccm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jccm",
"productName": "Juniper Cloud Connection Manager",
"description": "Juniper Cloud Connection Manager",
"version": "1.2.6",
"version": "1.2.7",
"main": ".webpack/main",
"scripts": {
"start": "pkill -9 node; nodemon --watch ./src --ext js,json --ignore ./src/Frontend/ --exec 'electron-forge start'",
Expand Down
35 changes: 32 additions & 3 deletions jccm/src/Frontend/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ import {
LeafThreeFilled,
PersonQuestionMarkFilled,
PersonQuestionMarkRegular,
QuestionCircleFilled,
QuestionCircleRegular,
InfoFilled,
InfoRegular,
BroomFilled,
BroomRegular,
ArrowClockwiseFilled,
ArrowClockwiseRegular,
NewFilled,
NewRegular,
ArrowResetFilled, ArrowResetRegular,
bundleIcon,
} from '@fluentui/react-icons';

Expand Down Expand Up @@ -54,6 +65,10 @@ const CloudAdd = bundleIcon(CloudAddFilled, CloudAddRegular);
const ArrowCircleRight = bundleIcon(ArrowCircleRightRegular, ArrowCircleRightRegular);
const LeafThree = bundleIcon(LeafThreeFilled, LeafThreeRegular);
const PersonQuestionMark = bundleIcon(PersonQuestionMarkFilled, PersonQuestionMarkRegular);
const AboutIcon = bundleIcon(InfoFilled, InfoRegular);
const ResetIcon = bundleIcon(ArrowResetFilled, ArrowResetRegular);
const RestartIcon = bundleIcon(ArrowClockwiseFilled, ArrowClockwiseRegular);
const CheckIcon = bundleIcon(NewFilled, NewRegular);

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

Expand Down Expand Up @@ -283,7 +298,10 @@ export const Main = () => {
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem onClick={() => setIsOpenAbout(true)}>
<MenuItem
// icon={<AboutIcon style={{ fontSize: '16px' }} />}
onClick={() => setIsOpenAbout(true)}
>
<Text style={{ fontSize: '12px' }}>About JCCM</Text>
</MenuItem>
{isAutoUpdateSupport && (
Expand All @@ -299,6 +317,11 @@ export const Main = () => {
</MenuItem>
) : (
<MenuItem
// icon={
// isCheckUpdatesDisabled ? null : (
// <CheckIcon style={{ fontSize: '16px' }} />
// )
// }
disabled={isCheckUpdatesDisabled}
onClick={() => setIsOpenCheckUpdates(true)}
>
Expand All @@ -312,12 +335,18 @@ export const Main = () => {
</>
)}
<MenuDivider />
<MenuItem onClick={() => setIsOpenResetAppData(true)}>
<MenuItem
// icon={<ResetIcon style={{ fontSize: '16px' }} />}
onClick={() => setIsOpenResetAppData(true)}
>
<Tooltip content={'This will clear all data and restart the app.'}>
<Text style={{ fontSize: 12 }}>Reset App Data</Text>
</Tooltip>
</MenuItem>
<MenuItem onClick={() => setIsOpenRestartApp(true)}>
<MenuItem
// icon={<RestartIcon style={{ fontSize: '16px' }} />}
onClick={() => setIsOpenRestartApp(true)}
>
<Text style={{ fontSize: '12px' }}>Restart</Text>
</MenuItem>
<MenuItem onClick={() => setIsOpenQuitApp(true)}>
Expand Down
22 changes: 14 additions & 8 deletions jccm/src/Frontend/MainEventProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const MainEventProcessor = () => {
const { cleanUpIsTesting, cleanUpDeviceNetworkCondition } = useStore();
const { resetDeviceNetworkConditionAll, resetIsTestingAll } = useStore();
const { setCheckingForUpdate, setUpdateDownloaded } = useStore();
const { setIsAutoUpdateSupport } = useStore();
const { isAutoUpdateSupport, setIsAutoUpdateSupport } = useStore();

const userRef = useRef(user);
const isUserLoggedInRef = useRef(isUserLoggedIn);
Expand All @@ -33,6 +33,11 @@ export const MainEventProcessor = () => {
const currentActiveThemeNameRef = useRef(currentActiveThemeName);

const [isFirstCheckIgnored, setIsFirstCheckIgnored] = useState(true);
const isFirstCheckIgnoredRef = useRef(isFirstCheckIgnored);

useEffect(() => {
isFirstCheckIgnoredRef.current = isFirstCheckIgnored;
}, [isFirstCheckIgnored]);

useEffect(() => {
// Set a 10-second timeout to allow update checks after the delay
Expand Down Expand Up @@ -266,18 +271,19 @@ export const MainEventProcessor = () => {
const handleCheckForUpdates = async () => {
console.log('Event: "check-for-updates"');

// If this is the first call and within 10 seconds, ignore it
if (isFirstCheckIgnored) {
if (isFirstCheckIgnoredRef.current) {
console.log('Skipping update check during initial 10 seconds.');
return;
}

try {
if (!isAutoUpdateSupport) {
console.warn('Auto-update not supported on this platform.');
return;
}
const isAutoUpdateSupported = useStore.getState().isAutoUpdateSupport;

if (!isAutoUpdateSupported) {
console.warn('Auto-update not supported on this platform.');
return;
}

try {
const result = await window.electronAPI.checkForUpdates();
console.log('check-for-updates result:', result);
setCheckingForUpdate(result);
Expand Down

0 comments on commit 1dbcfe7

Please sign in to comment.