mirror of https://github.com/jetkvm/kvm.git
refactor: update version handling and simplify downgrade logic
This commit is contained in:
parent
1bca0c5e26
commit
882eb703c5
|
|
@ -204,6 +204,7 @@ export default function SettingsAdvancedRoute() {
|
||||||
setVersionUpdateLoading(true);
|
setVersionUpdateLoading(true);
|
||||||
versionInfo = await checkUpdateComponents({
|
versionInfo = await checkUpdateComponents({
|
||||||
components: components.join(","),
|
components: components.join(","),
|
||||||
|
// TODO: Rename to appTargetVersion and systemTargetVersion
|
||||||
app: appVersion,
|
app: appVersion,
|
||||||
system: systemVersion,
|
system: systemVersion,
|
||||||
}, devChannel);
|
}, devChannel);
|
||||||
|
|
@ -214,11 +215,6 @@ export default function SettingsAdvancedRoute() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!versionInfo) {
|
|
||||||
handleVersionUpdateError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pageParams = new URLSearchParams();
|
const pageParams = new URLSearchParams();
|
||||||
pageParams.set("downgrade", "true");
|
pageParams.set("downgrade", "true");
|
||||||
if (components.includes("app") && versionInfo.remote?.appVersion && versionInfo.appDowngradeAvailable) {
|
if (components.includes("app") && versionInfo.remote?.appVersion && versionInfo.appDowngradeAvailable) {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ export default function SettingsGeneralUpdateRoute() {
|
||||||
const { setModalView, otaState } = useUpdateStore();
|
const { setModalView, otaState } = useUpdateStore();
|
||||||
const { send } = useJsonRpc();
|
const { send } = useJsonRpc();
|
||||||
|
|
||||||
const downgrade = useMemo(() => searchParams.get("downgrade") === "true", [searchParams]);
|
|
||||||
const customAppVersion = useMemo(() => searchParams.get("app") || "", [searchParams]);
|
const customAppVersion = useMemo(() => searchParams.get("app") || "", [searchParams]);
|
||||||
const customSystemVersion = useMemo(() => searchParams.get("system") || "", [searchParams]);
|
const customSystemVersion = useMemo(() => searchParams.get("system") || "", [searchParams]);
|
||||||
const resetConfig = useMemo(() => searchParams.get("resetConfig") === "true", [searchParams]);
|
const resetConfig = useMemo(() => searchParams.get("resetConfig") === "true", [searchParams]);
|
||||||
|
|
@ -78,7 +77,6 @@ export default function SettingsGeneralUpdateRoute() {
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onConfirmUpdate={onConfirmUpdate}
|
onConfirmUpdate={onConfirmUpdate}
|
||||||
onConfirmDowngrade={onConfirmDowngrade}
|
onConfirmDowngrade={onConfirmDowngrade}
|
||||||
downgrade={downgrade}
|
|
||||||
customAppVersion={customAppVersion}
|
customAppVersion={customAppVersion}
|
||||||
customSystemVersion={customSystemVersion}
|
customSystemVersion={customSystemVersion}
|
||||||
/>;
|
/>;
|
||||||
|
|
@ -88,11 +86,9 @@ export function Dialog({
|
||||||
onClose,
|
onClose,
|
||||||
onConfirmUpdate,
|
onConfirmUpdate,
|
||||||
onConfirmDowngrade,
|
onConfirmDowngrade,
|
||||||
downgrade,
|
|
||||||
customAppVersion,
|
customAppVersion,
|
||||||
customSystemVersion,
|
customSystemVersion,
|
||||||
}: Readonly<{
|
}: Readonly<{
|
||||||
downgrade: boolean;
|
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onConfirmUpdate: () => void;
|
onConfirmUpdate: () => void;
|
||||||
onConfirmDowngrade: () => void;
|
onConfirmDowngrade: () => void;
|
||||||
|
|
@ -109,19 +105,19 @@ export function Dialog({
|
||||||
(versionInfo: SystemVersionInfo) => {
|
(versionInfo: SystemVersionInfo) => {
|
||||||
const hasUpdate =
|
const hasUpdate =
|
||||||
versionInfo?.systemUpdateAvailable || versionInfo?.appUpdateAvailable;
|
versionInfo?.systemUpdateAvailable || versionInfo?.appUpdateAvailable;
|
||||||
const hasDowngrade = customSystemVersion !== undefined || customAppVersion !== undefined;
|
const forceCustomUpdate = customSystemVersion !== undefined || customAppVersion !== undefined;
|
||||||
|
|
||||||
setVersionInfo(versionInfo);
|
setVersionInfo(versionInfo);
|
||||||
|
|
||||||
if (hasDowngrade && downgrade) {
|
if (forceCustomUpdate) {
|
||||||
setModalView("updateDowngradeAvailable");
|
setModalView("confirmCustomUpdate");
|
||||||
} else if (hasUpdate) {
|
} else if (hasUpdate) {
|
||||||
setModalView("updateAvailable");
|
setModalView("updateAvailable");
|
||||||
} else {
|
} else {
|
||||||
setModalView("upToDate");
|
setModalView("upToDate");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[setModalView, downgrade, customAppVersion, customSystemVersion],
|
[setModalView, customAppVersion, customSystemVersion],
|
||||||
);
|
);
|
||||||
|
|
||||||
const onCancelDowngrade = useCallback(() => {
|
const onCancelDowngrade = useCallback(() => {
|
||||||
|
|
@ -151,12 +147,12 @@ export function Dialog({
|
||||||
versionInfo={versionInfo!}
|
versionInfo={versionInfo!}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{modalView === "updateDowngradeAvailable" && (
|
{modalView === "confirmCustomUpdate" && (
|
||||||
<UpdateDowngradeAvailableState
|
<ConfirmCustomUpdate
|
||||||
appVersion={customAppVersion}
|
appVersion={customAppVersion}
|
||||||
systemVersion={customSystemVersion}
|
systemVersion={customSystemVersion}
|
||||||
onConfirmDowngrade={onConfirmDowngrade}
|
onConfirm={onConfirmDowngrade}
|
||||||
onCancelDowngrade={onCancelDowngrade}
|
onCancel={onCancelDowngrade}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -203,6 +199,7 @@ function LoadingState({
|
||||||
setProgressWidth("100%");
|
setProgressWidth("100%");
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
// TODO: CHECK FOR QUERY PARAMS
|
||||||
getVersionInfo()
|
getVersionInfo()
|
||||||
.then(async versionInfo => {
|
.then(async versionInfo => {
|
||||||
// Add a small delay to ensure it's not just flickering
|
// Add a small delay to ensure it's not just flickering
|
||||||
|
|
@ -471,20 +468,17 @@ function UpdateAvailableState({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function UpdateDowngradeAvailableState({
|
function ConfirmCustomUpdate({
|
||||||
appVersion,
|
appVersion,
|
||||||
systemVersion,
|
systemVersion,
|
||||||
onConfirmDowngrade,
|
onConfirm,
|
||||||
onCancelDowngrade,
|
onCancel,
|
||||||
}: {
|
}: {
|
||||||
appVersion?: string;
|
appVersion?: string;
|
||||||
systemVersion?: string;
|
systemVersion?: string;
|
||||||
onConfirmDowngrade: () => void;
|
onConfirm: () => void;
|
||||||
onCancelDowngrade: () => void;
|
onCancel: () => void;
|
||||||
}) {
|
}) {
|
||||||
const confirmDowngrade = useCallback(() => {
|
|
||||||
onConfirmDowngrade();
|
|
||||||
}, [onConfirmDowngrade]);
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-start justify-start space-y-4 text-left">
|
<div className="flex flex-col items-start justify-start space-y-4 text-left">
|
||||||
<div className="text-left">
|
<div className="text-left">
|
||||||
|
|
@ -508,8 +502,8 @@ function UpdateDowngradeAvailableState({
|
||||||
) : null}
|
) : null}
|
||||||
</p>
|
</p>
|
||||||
<div className="flex items-center justify-start gap-x-2">
|
<div className="flex items-center justify-start gap-x-2">
|
||||||
<Button size="SM" theme="primary" text={m.general_update_downgrade_button()} onClick={confirmDowngrade} />
|
<Button size="SM" theme="primary" text={m.general_update_downgrade_button()} onClick={onConfirm} />
|
||||||
<Button size="SM" theme="light" text={m.general_update_keep_current_button()} onClick={onCancelDowngrade} />
|
<Button size="SM" theme="light" text={m.general_update_keep_current_button()} onClick={onCancel} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue