Skip to content

Commit

Permalink
Improve detection of updated webUI version
Browse files Browse the repository at this point in the history
In case the webUI update status was reset from another device, other devices would not show an info that the webUI got updated
  • Loading branch information
schroda committed May 6, 2024
1 parent 63543a4 commit eb0ba0b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/components/util/WebUIUpdateChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export const WebUIUpdateChecker = () => {

const shouldCheckForUpdate = !isAutoUpdateEnabled && webUIInformAvailableUpdate;

const { data: aboutData } = requestManager.useGetAbout();
const { aboutWebUI } = aboutData ?? {};

const { data: webUIUpdateData, refetch: checkForUpdate } = requestManager.useCheckForWebUIUpdate({
notifyOnNetworkStatusChange: true,
fetchPolicy: 'cache-only',
Expand All @@ -63,6 +66,13 @@ export const WebUIUpdateChecker = () => {
? `https://github.com/Suwayomi/Suwayomi-WebUI/releases/tag/${updateStatus.info?.tag}`
: `https://github.com/Suwayomi/Suwayomi-WebUI/issues/749`;

const newVersion = aboutWebUI?.tag;
const isSameAsCurrent = !newVersion || webUIVersion === newVersion;

if (!isSameAsCurrent && !open) {
setOpen(true);
}

useEffect(() => {
const isError = webUIUpdateState === UpdateState.Error;
if (isError) {
Expand All @@ -85,6 +95,7 @@ export const WebUIUpdateChecker = () => {
if (!updateStatus.info) {
return;
}

requestManager.graphQLClient.client.cache.writeFragment({
fragment: ABOUT_WEBUI,
data: {
Expand All @@ -102,17 +113,6 @@ export const WebUIUpdateChecker = () => {
updateAvailable: false,
},
});

const newVersion = updateStatus.info.tag;
const isSameAsCurrent = webUIVersion === newVersion;

setWebUIVersion(newVersion);

if (isSameAsCurrent) {
return;
}

setOpen(true);
}, [webUIUpdateState]);

const isUpdateAvailable =
Expand Down Expand Up @@ -147,8 +147,7 @@ export const WebUIUpdateChecker = () => {
);
}

const handleUpdate = open && webUIUpdateState === UpdateState.Idle;
if (!handleUpdate) {
if (!open) {
return null;
}

Expand All @@ -168,6 +167,7 @@ export const WebUIUpdateChecker = () => {
</Button>
<Button
onClick={() => {
setWebUIVersion(newVersion);
setOpen(false);
window.location.reload();
}}
Expand Down

0 comments on commit eb0ba0b

Please sign in to comment.