Skip to content

Commit

Permalink
Use 'cli' updater instead of python-apt
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapona committed Aug 21, 2024
1 parent 9214fd4 commit c342863
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 771 deletions.
6 changes: 6 additions & 0 deletions frontend/src/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default [
rest.get("/further-url", (_, res, ctx) => {
return res(ctx.json({ url: "https://further.pi-top.com" }));
}),
rest.get("/available-space", (_, res, ctx) => {
return res(ctx.body("20378521600"));
}),
rest.get("/rover-controller-status", (_, res, ctx) => {
return res(ctx.json({ status: "inactive" }));
}),
Expand All @@ -48,6 +51,9 @@ export default [
rest.post("/rover-controller-stop", (_, res, ctx) => {
return res(ctx.body("OK"));
}),
rest.post("/restart-web-portal-service", (_, res, ctx) => {
return res(ctx.body("OK"));
}),
rest.get("/is-connected", (_, res, ctx) => {
return res(ctx.json({ connected: false }));
}),
Expand Down
24 changes: 6 additions & 18 deletions frontend/src/pages/upgradePage/UpgradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState, useEffect } from "react";
import { Line as ProgressBar } from "rc-progress";
import prettyBytes from "pretty-bytes";

import CheckBox from "../../components/atoms/checkBox/CheckBox";
import Layout from "../../components/layout/Layout";
import Spinner from "../../components/atoms/spinner/Spinner";

Expand All @@ -21,7 +20,7 @@ import UpgradeHistoryTextArea from "../../components/upgradeHistoryTextArea/Upgr

export enum ErrorMessage {
NoSpaceAvailable = "There's not enough space on the device to install updates. Please, free up space and try updating again.",
GenericError = "There was a problem during system update.\nIf this is the first time, please try again using the recommended method.\nIf you're experiencing repeated issues, try another method.",
GenericError = "There was a problem during system update.\nPlease try again later.\nIf you're experiencing repeated issues, contact pi-top support.",
CloseOtherWindow = "The OS Updater application is already running in another window.",
}

Expand All @@ -43,7 +42,7 @@ export type Props = {
onSkipClick?: () => void;
onBackClick?: () => void;
onStartUpgradeClick: () => void;
onRetry: (defaultBackend: boolean) => void;
onRetry: () => void;
isCompleted?: boolean;
message?: OSUpdaterMessage;
updateState: UpdateState;
Expand All @@ -70,9 +69,10 @@ export default ({
error,
}: Props) => {
const [isNewOsDialogActive, setIsNewOsDialogActive] = useState(false);
const [isUsingDefaultBackend, setIsUsingDefaultBackend] = useState(true);
const [isRetrying, setIsRetrying] = useState(false);

const displayProgressBar = false;

useEffect(() => {
setIsNewOsDialogActive(requireBurn || shouldBurn);
}, [requireBurn, shouldBurn]);
Expand Down Expand Up @@ -206,7 +206,7 @@ export default ({
const onNextButtonClick = () => {
if (hasError()) {
setIsRetrying(true);
onRetry(isUsingDefaultBackend);
onRetry();
} else if (updateState === UpdateState.WaitingForUserInput) {
onStartUpgradeClick();
} else {
Expand Down Expand Up @@ -260,18 +260,6 @@ export default ({
);
})}
</span>

{error !== ErrorType.UpdaterAlreadyRunning && (
<CheckBox
name="legacy-backend"
label="Use alternate update method"
checked={!isUsingDefaultBackend}
onChange={() =>
setIsUsingDefaultBackend(!isUsingDefaultBackend)
}
className={styles.checkbox}
/>
)}
</>
)}

Expand Down Expand Up @@ -306,7 +294,7 @@ export default ({
message?.type === OSUpdaterMessageType.UpdateSources) &&
updateState !== UpdateState.WaitingForServer &&
!hasError() &&
isUsingDefaultBackend && (
displayProgressBar && (
<div data-testid="progress" className={styles.progress}>
<ProgressBar
percent={message.payload.percent}
Expand Down
27 changes: 6 additions & 21 deletions frontend/src/pages/upgradePage/UpgradePageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export enum SocketMessage {
PREPARE_WEB_PORTAL_UPGRADE = "prepare_web_portal",
UPDATE_SOURCES = "update_sources",
START_UPGRADE = "start",
USE_DEFAULT_UPDATER = "default-updater-backend",
USE_LEGACY_UPDATER = "legacy-updater-backend",
GET_UPGRADE_SIZE = "size",
GET_STATE = "state",
}
Expand Down Expand Up @@ -196,14 +194,13 @@ export default ({ goToNextPage, goToPreviousPage, hideSkip, isCompleted, setEnab
}, [isOpen, state]); // eslint-disable-line react-hooks/exhaustive-deps

const doRetry = useCallback(
(defaultBackend: boolean) => {
socket.send(defaultBackend ? SocketMessage.USE_DEFAULT_UPDATER : SocketMessage.USE_LEGACY_UPDATER);
() => {
setError(ErrorType.None);
setUpdateSize({downloadSize: 0, requiredSpace: 0});
checkingWebPortalRef.current = true;
setState(UpdateState.UpdatingSources);
},
[socket],
[setError, setUpdateSize, setState],
)

useEffect(() => {
Expand Down Expand Up @@ -284,7 +281,6 @@ export default ({ goToNextPage, goToPreviousPage, hideSkip, isCompleted, setEnab
if (message.payload.busy) {
setState(UpdateState.Reattaching);
} else {
socket.send(SocketMessage.USE_DEFAULT_UPDATER);
setState(UpdateState.UpdatingSources);
}
}
Expand Down Expand Up @@ -361,18 +357,9 @@ export default ({ goToNextPage, goToPreviousPage, hideSkip, isCompleted, setEnab

return (
<UpgradePage
onNextClick={() => {
setEnableDisconnectedFromApDialog && setEnableDisconnectedFromApDialog(true);
goToNextPage && goToNextPage()
}}
onSkipClick={() => {
setEnableDisconnectedFromApDialog && setEnableDisconnectedFromApDialog(true);
goToNextPage && goToNextPage()
}}
onBackClick={() => {
setEnableDisconnectedFromApDialog && setEnableDisconnectedFromApDialog(true);
goToPreviousPage && goToPreviousPage()
}}
onNextClick={goToNextPage}
onSkipClick={goToNextPage}
onBackClick={goToPreviousPage}
hideSkip={hideSkip}
onStartUpgradeClick={() => {
if (isOpen) {
Expand All @@ -381,9 +368,7 @@ export default ({ goToNextPage, goToPreviousPage, hideSkip, isCompleted, setEnab
}
setError(ErrorType.GenericError);
}}
onRetry={(useDefaultBackend: boolean) => {
doRetry(useDefaultBackend)
}}
onRetry={doRetry}
isCompleted={isCompleted}
message={message}
updateState={state}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,10 @@ describe("UpgradePageContainer", () => {
expect(textAreaElement).toMatchSnapshot();
});

it("renders progress bar correctly", async () => {
const { findByTestId, queryByTestId } = mount();
it("doesn't render progress bar", async () => {
const { container: upgradePage } = mount();

await findByTestId("progress");
const progressBar = queryByTestId("progress");
expect(progressBar).toMatchSnapshot();
expect(upgradePage.querySelector(".progress")).not.toBeInTheDocument();
});

it("doesn't render the Skip button", async () => {
Expand Down Expand Up @@ -1011,14 +1009,12 @@ describe("UpgradePageContainer", () => {
await waitForInstallingPackages();
});

it("renders progress bar correctly", async () => {
it("doesn't render the progress bar", async () => {
const { getByText, waitForPreparation, container: upgradePage } = mount();
await waitForPreparation();
fireEvent.click(getByText("Update"));

await waitForElement(() => upgradePage.querySelector(".progress"));
const progressBar = upgradePage.querySelector(".progress");
expect(progressBar).toMatchSnapshot();
expect(upgradePage.querySelector(".progress")).not.toBeInTheDocument();
});

it("renders the textarea component", async () => {
Expand Down Expand Up @@ -1295,13 +1291,13 @@ describe("UpgradePageContainer", () => {
await waitForUpgradeFinish();
});

it("renders progress bar correctly", async () => {
it("doesn't render the progress bar", async () => {
const { getByText, waitForPreparation, waitForUpgradeFinish, container: upgradePage } = mount();
await waitForPreparation();
fireEvent.click(getByText("Update"));
await waitForUpgradeFinish();

expect(upgradePage.querySelector(".progress")).toMatchSnapshot();
expect(upgradePage.querySelector(".progress")).not.toBeInTheDocument();
});

it("renders the textarea component", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,6 @@ dpkg-exec: Running dpkg
</textarea>
`;

exports[`UpgradePageContainer when the system is being updated renders progress bar correctly 1`] = `
<div
class="progress"
data-testid="progress"
>
<svg
class="rc-progress-line "
preserveAspectRatio="none"
viewBox="0 0 100 2"
>
<path
class="rc-progress-line-trail"
d="M 1,1
L 99,1"
fill-opacity="0"
stroke="#D9D9D9"
stroke-linecap="round"
stroke-width="1"
/>
<path
class="rc-progress-line-path"
d="M 1,1
L 99,1"
fill-opacity="0"
stroke="#71c0b4"
stroke-linecap="round"
stroke-width="2"
style="stroke-dasharray: 50px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: .3s, .3s, .3s, .06s;"
/>
</svg>
</div>
`;

exports[`UpgradePageContainer when the system is being updated renders prompt correctly 1`] = `
<h1
class="prompt"
Expand Down Expand Up @@ -142,39 +109,6 @@ Finished upgrade
</textarea>
`;

exports[`UpgradePageContainer when the upgrade finishes renders progress bar correctly 1`] = `
<div
class="progress"
data-testid="progress"
>
<svg
class="rc-progress-line "
preserveAspectRatio="none"
viewBox="0 0 100 2"
>
<path
class="rc-progress-line-trail"
d="M 1,1
L 99,1"
fill-opacity="0"
stroke="#D9D9D9"
stroke-linecap="round"
stroke-width="1"
/>
<path
class="rc-progress-line-path"
d="M 1,1
L 99,1"
fill-opacity="0"
stroke="#71c0b4"
stroke-linecap="round"
stroke-width="2"
style="stroke-dasharray: 0px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: 0s, 0s;"
/>
</svg>
</div>
`;

exports[`UpgradePageContainer when the upgrade finishes renders prompt correctly 1`] = `
<h1
class="prompt"
Expand Down Expand Up @@ -863,39 +797,6 @@ Updating blah
</textarea>
`;

exports[`UpgradePageContainer while updating sources renders progress bar correctly 1`] = `
<div
class="progress"
data-testid="progress"
>
<svg
class="rc-progress-line "
preserveAspectRatio="none"
viewBox="0 0 100 2"
>
<path
class="rc-progress-line-trail"
d="M 1,1
L 99,1"
fill-opacity="0"
stroke="#D9D9D9"
stroke-linecap="round"
stroke-width="1"
/>
<path
class="rc-progress-line-path"
d="M 1,1
L 99,1"
fill-opacity="0"
stroke="#71c0b4"
stroke-linecap="round"
stroke-width="2"
style="stroke-dasharray: 50px, 100px; stroke-dashoffset: -0px; transition: stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear; transition-duration: .3s, .3s, .3s, .06s;"
/>
</svg>
</div>
`;

exports[`UpgradePageContainer while updating sources renders prompt correctly 1`] = `
<h1
class="prompt"
Expand Down
Loading

0 comments on commit c342863

Please sign in to comment.