@peers-app/peers-ui 0.26.0 → 0.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-updates/app-update-controls.d.ts +23 -0
- package/dist/app-updates/app-update-controls.js +40 -0
- package/dist/app-updates/app-updates-consumer.d.ts +41 -0
- package/dist/app-updates/app-updates-consumer.js +96 -0
- package/dist/app-updates/app-updates-consumer.test.d.ts +1 -0
- package/dist/app-updates/app-updates-consumer.test.js +56 -0
- package/dist/app-updates/app-updates-settings.d.ts +5 -0
- package/dist/app-updates/app-updates-settings.js +44 -0
- package/dist/app-updates/app-updates-settings.test.d.ts +1 -0
- package/dist/app-updates/app-updates-settings.test.js +93 -0
- package/dist/app-updates/remote-app-update-panel.d.ts +18 -0
- package/dist/app-updates/remote-app-update-panel.js +125 -0
- package/dist/app-updates/remote-app-update-panel.test.d.ts +1 -0
- package/dist/app-updates/remote-app-update-panel.test.js +165 -0
- package/dist/app-updates/use-app-update-status.d.ts +8 -0
- package/dist/app-updates/use-app-update-status.js +17 -0
- package/dist/screens/devices/devices-list.js +2 -1
- package/dist/screens/network-viewer/device-details-modal.js +2 -1
- package/dist/screens/settings/settings-page.js +5 -0
- package/dist/tabs-layout/network-status-indicator.d.ts +12 -0
- package/dist/tabs-layout/network-status-indicator.js +33 -5
- package/dist/tabs-layout/network-status-indicator.test.js +90 -0
- package/package.json +3 -3
- package/src/app-updates/app-update-controls.tsx +73 -0
- package/src/app-updates/app-updates-consumer.test.ts +83 -0
- package/src/app-updates/app-updates-consumer.ts +121 -0
- package/src/app-updates/app-updates-settings.test.tsx +109 -0
- package/src/app-updates/app-updates-settings.tsx +136 -0
- package/src/app-updates/remote-app-update-panel.test.tsx +205 -0
- package/src/app-updates/remote-app-update-panel.tsx +210 -0
- package/src/app-updates/use-app-update-status.ts +16 -0
- package/src/screens/devices/devices-list.tsx +4 -0
- package/src/screens/network-viewer/device-details-modal.tsx +6 -0
- package/src/screens/settings/settings-page.tsx +5 -0
- package/src/tabs-layout/network-status-indicator.test.tsx +119 -1
- package/src/tabs-layout/network-status-indicator.tsx +56 -5
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { IAppUpdateStatus } from "@peers-app/peers-sdk";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
describeAppUpdateStatus,
|
|
5
|
+
getAppUpdatesConsumer,
|
|
6
|
+
hasAppUpdate,
|
|
7
|
+
isAppRestarting,
|
|
8
|
+
} from "./app-updates-consumer";
|
|
9
|
+
|
|
10
|
+
/** Bootstrap Icons class used for "update available" everywhere in the shell. */
|
|
11
|
+
export const APP_UPDATE_ICON_CLASS = "bi-arrow-up-circle-fill";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Button that installs this device's available update and relaunches, or restarts it when
|
|
15
|
+
* there is nothing to install.
|
|
16
|
+
*
|
|
17
|
+
* @param props.status - This device's update status.
|
|
18
|
+
* @param props.className - Bootstrap button classes.
|
|
19
|
+
*/
|
|
20
|
+
export function UpdateAndRestartButton({
|
|
21
|
+
status,
|
|
22
|
+
className = "btn btn-sm btn-warning",
|
|
23
|
+
}: {
|
|
24
|
+
status: IAppUpdateStatus;
|
|
25
|
+
className?: string;
|
|
26
|
+
}) {
|
|
27
|
+
const [error, setError] = useState<string>();
|
|
28
|
+
const busy = isAppRestarting(status);
|
|
29
|
+
const label = hasAppUpdate(status) ? "Update & restart" : "Restart";
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<button
|
|
33
|
+
type="button"
|
|
34
|
+
className={className}
|
|
35
|
+
disabled={busy || !status.canRestart}
|
|
36
|
+
onClick={() => {
|
|
37
|
+
setError(undefined);
|
|
38
|
+
getAppUpdatesConsumer()
|
|
39
|
+
.then((appUpdates) => appUpdates.tools.installUpdateAndRestart())
|
|
40
|
+
.catch((err: unknown) => setError(err instanceof Error ? err.message : String(err)));
|
|
41
|
+
}}
|
|
42
|
+
>
|
|
43
|
+
<i className={`bi ${APP_UPDATE_ICON_CLASS} me-1`} aria-hidden="true" />
|
|
44
|
+
{busy ? describeAppUpdateStatus(status) : label}
|
|
45
|
+
</button>
|
|
46
|
+
{error && <div className="small text-danger mt-1">{error}</div>}
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Update section of the network status popover. Renders only while an update is available,
|
|
53
|
+
* downloading, ready, or installing.
|
|
54
|
+
*
|
|
55
|
+
* @param props.status - This device's update status.
|
|
56
|
+
*/
|
|
57
|
+
export function AppUpdatePopoverSection({ status }: { status: IAppUpdateStatus | undefined }) {
|
|
58
|
+
if (!status?.supported || !(hasAppUpdate(status) || isAppRestarting(status))) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return (
|
|
62
|
+
<div className="alert alert-warning py-2 px-2 small mb-3" data-testid="app-update-section">
|
|
63
|
+
<div className="mb-1">
|
|
64
|
+
<i className={`bi ${APP_UPDATE_ICON_CLASS} me-1`} aria-hidden="true" />
|
|
65
|
+
{describeAppUpdateStatus(status)}
|
|
66
|
+
</div>
|
|
67
|
+
{status.installOnQuitArmed && (
|
|
68
|
+
<div className="text-muted mb-2">Installs automatically the next time Peers restarts.</div>
|
|
69
|
+
)}
|
|
70
|
+
<UpdateAndRestartButton status={status} className="btn btn-sm btn-warning w-100" />
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { IAppUpdateStatus } from "@peers-app/peers-sdk";
|
|
2
|
+
import {
|
|
3
|
+
classifyAppUpdatesError,
|
|
4
|
+
describeAppUpdateStatus,
|
|
5
|
+
hasAppUpdate,
|
|
6
|
+
isAppRestarting,
|
|
7
|
+
} from "./app-updates-consumer";
|
|
8
|
+
|
|
9
|
+
function status(overrides: Partial<IAppUpdateStatus> = {}): IAppUpdateStatus {
|
|
10
|
+
return {
|
|
11
|
+
supported: true,
|
|
12
|
+
canRestart: true,
|
|
13
|
+
platform: "darwin",
|
|
14
|
+
currentVersion: "1.0.0",
|
|
15
|
+
state: "idle",
|
|
16
|
+
installOnRestart: true,
|
|
17
|
+
installOnQuitArmed: false,
|
|
18
|
+
remoteRestartAllowed: true,
|
|
19
|
+
...overrides,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("classifyAppUpdatesError", () => {
|
|
24
|
+
it.each([
|
|
25
|
+
["No contract provider registered for abc v1", "unavailable"],
|
|
26
|
+
["Provider p has no live resolver for abc v1", "unavailable"],
|
|
27
|
+
["This device cannot install updates or restart itself", "unavailable"],
|
|
28
|
+
["Permission denied: tool 'getStatus'.run on contract abc", "denied"],
|
|
29
|
+
["Device d is not connected", "unreachable"],
|
|
30
|
+
["Device d is not reachable through the peers mesh", "unreachable"],
|
|
31
|
+
["Remote contract call to d timed out after 30000ms", "unreachable"],
|
|
32
|
+
["Device d did not answer within 30000ms", "unreachable"],
|
|
33
|
+
["Something else", "failed"],
|
|
34
|
+
])("classifies %s as %s", (message, kind) => {
|
|
35
|
+
expect(classifyAppUpdatesError(new Error(message))).toBe(kind);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("status helpers", () => {
|
|
40
|
+
it("treats available, downloading, and downloaded as an available update", () => {
|
|
41
|
+
expect(hasAppUpdate(undefined)).toBe(false);
|
|
42
|
+
expect(hasAppUpdate(status({ state: "up-to-date" }))).toBe(false);
|
|
43
|
+
for (const state of ["available", "downloading", "downloaded"] as const) {
|
|
44
|
+
expect(hasAppUpdate(status({ state }))).toBe(true);
|
|
45
|
+
}
|
|
46
|
+
expect(isAppRestarting(status({ state: "installing" }))).toBe(true);
|
|
47
|
+
expect(isAppRestarting(status({ state: "downloaded" }))).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("keeps a known newer version as an update after a failed download", () => {
|
|
51
|
+
expect(hasAppUpdate(status({ state: "error", latestVersion: "1.1.0" }))).toBe(true);
|
|
52
|
+
expect(hasAppUpdate(status({ state: "error", downloadedVersion: "1.1.0" }))).toBe(true);
|
|
53
|
+
expect(hasAppUpdate(status({ state: "error", latestVersion: "1.0.0" }))).toBe(false);
|
|
54
|
+
expect(hasAppUpdate(status({ state: "error" }))).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("describes each state", () => {
|
|
58
|
+
expect(
|
|
59
|
+
describeAppUpdateStatus(
|
|
60
|
+
status({ state: "downloading", latestVersion: "1.2.0", downloadedVersion: "1.1.0" }),
|
|
61
|
+
),
|
|
62
|
+
).toBe("Downloading 1.2.0");
|
|
63
|
+
expect(
|
|
64
|
+
describeAppUpdateStatus(
|
|
65
|
+
status({ state: "downloading", latestVersion: "1.1.0", downloadPercent: 42 }),
|
|
66
|
+
),
|
|
67
|
+
).toBe("Downloading 1.1.0 (42%)");
|
|
68
|
+
expect(
|
|
69
|
+
describeAppUpdateStatus(status({ state: "downloaded", downloadedVersion: "1.1.0" })),
|
|
70
|
+
).toBe("Version 1.1.0 is ready to install");
|
|
71
|
+
expect(describeAppUpdateStatus(status({ state: "error", error: "offline" }))).toBe(
|
|
72
|
+
"Update problem: offline",
|
|
73
|
+
);
|
|
74
|
+
expect(
|
|
75
|
+
describeAppUpdateStatus(
|
|
76
|
+
status({ state: "error", latestVersion: "1.1.0", error: "download failed" }),
|
|
77
|
+
),
|
|
78
|
+
).toBe("Version 1.1.0 is available. Update problem: download failed");
|
|
79
|
+
expect(describeAppUpdateStatus(status({ supported: false }))).toBe(
|
|
80
|
+
"Updates are not available for this build",
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAppUpdatesContractDefinition,
|
|
3
|
+
hostContractConsumer,
|
|
4
|
+
type IAppUpdateStatus,
|
|
5
|
+
type IAppUpdatesConsumer,
|
|
6
|
+
isNewerVersion,
|
|
7
|
+
} from "@peers-app/peers-sdk";
|
|
8
|
+
|
|
9
|
+
/** Shared handle for System App Updates on the local host; stable for `useHostContract`. */
|
|
10
|
+
export const appUpdatesContract = hostContractConsumer<IAppUpdatesConsumer>(
|
|
11
|
+
getAppUpdatesContractDefinition(),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
/** Return the System App Updates consumer bound to the current local host transport. */
|
|
15
|
+
export function getAppUpdatesConsumer(): Promise<IAppUpdatesConsumer> {
|
|
16
|
+
return appUpdatesContract.get();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Why a call to another device's App Updates failed:
|
|
21
|
+
*
|
|
22
|
+
* - `unavailable` — the device cannot update or restart itself, or runs a build without App Updates.
|
|
23
|
+
* - `denied` — the device does not trust this user as `Self`, or does not allow remote restarts.
|
|
24
|
+
* - `unreachable` — the device is not connected or did not answer.
|
|
25
|
+
* - `failed` — anything else.
|
|
26
|
+
*/
|
|
27
|
+
export type AppUpdatesErrorKind = "unavailable" | "denied" | "unreachable" | "failed";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Classify an App Updates error so the UI can hide, disable, or explain the action.
|
|
31
|
+
*
|
|
32
|
+
* @param error - Error thrown by a relayed App Updates call.
|
|
33
|
+
*/
|
|
34
|
+
export function classifyAppUpdatesError(error: unknown): AppUpdatesErrorKind {
|
|
35
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
36
|
+
if (
|
|
37
|
+
/No contract provider registered|has no live resolver|cannot install updates or restart/i.test(
|
|
38
|
+
message,
|
|
39
|
+
)
|
|
40
|
+
) {
|
|
41
|
+
return "unavailable";
|
|
42
|
+
}
|
|
43
|
+
if (/Permission denied/i.test(message)) {
|
|
44
|
+
return "denied";
|
|
45
|
+
}
|
|
46
|
+
if (/not connected|not reachable|timed out|did not answer/i.test(message)) {
|
|
47
|
+
return "unreachable";
|
|
48
|
+
}
|
|
49
|
+
return "failed";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function knowsNewerVersion(status: IAppUpdateStatus): boolean {
|
|
53
|
+
return [status.latestVersion, status.downloadedVersion].some(
|
|
54
|
+
(version) => !!version && isNewerVersion(status.currentVersion, version),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether a newer version is available, downloading, or ready to install. A failed download
|
|
60
|
+
* or check still counts while a newer version is known: Update & restart retries it.
|
|
61
|
+
*
|
|
62
|
+
* @param status - Update status, or `undefined` while loading.
|
|
63
|
+
*/
|
|
64
|
+
export function hasAppUpdate(status: IAppUpdateStatus | undefined): boolean {
|
|
65
|
+
if (!status) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return (
|
|
69
|
+
status.state === "available" ||
|
|
70
|
+
status.state === "downloading" ||
|
|
71
|
+
status.state === "downloaded" ||
|
|
72
|
+
(status.state === "error" && knowsNewerVersion(status))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Whether the device is already installing an update or restarting.
|
|
78
|
+
*
|
|
79
|
+
* @param status - Update status, or `undefined` while loading.
|
|
80
|
+
*/
|
|
81
|
+
export function isAppRestarting(status: IAppUpdateStatus | undefined): boolean {
|
|
82
|
+
return status?.state === "installing" || status?.state === "restarting";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Version being downloaded, or the cached version being prepared for installation. */
|
|
86
|
+
export function getAppUpdateVersion(status: IAppUpdateStatus): string | undefined {
|
|
87
|
+
return status.state === "downloaded" || status.state === "installing"
|
|
88
|
+
? (status.downloadedVersion ?? status.latestVersion)
|
|
89
|
+
: (status.latestVersion ?? status.downloadedVersion);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* One-line, human-readable summary of an update status.
|
|
94
|
+
*
|
|
95
|
+
* @param status - Update status to describe.
|
|
96
|
+
*/
|
|
97
|
+
export function describeAppUpdateStatus(status: IAppUpdateStatus): string {
|
|
98
|
+
const version = getAppUpdateVersion(status);
|
|
99
|
+
switch (status.state) {
|
|
100
|
+
case "installing":
|
|
101
|
+
return version ? `Installing ${version}…` : "Installing update…";
|
|
102
|
+
case "restarting":
|
|
103
|
+
return "Restarting…";
|
|
104
|
+
case "downloaded":
|
|
105
|
+
return `Version ${version} is ready to install${status.error ? `. Update problem: ${status.error}` : ""}`;
|
|
106
|
+
case "downloading":
|
|
107
|
+
return `Downloading ${version}${status.downloadPercent != null ? ` (${status.downloadPercent}%)` : ""}`;
|
|
108
|
+
case "available":
|
|
109
|
+
return `Version ${version} is available`;
|
|
110
|
+
case "checking":
|
|
111
|
+
return "Checking for updates…";
|
|
112
|
+
case "up-to-date":
|
|
113
|
+
return "Up to date";
|
|
114
|
+
case "error":
|
|
115
|
+
return knowsNewerVersion(status)
|
|
116
|
+
? `Version ${version} is available. Update problem: ${status.error ?? "unknown error"}`
|
|
117
|
+
: `Update problem: ${status.error ?? "unknown error"}`;
|
|
118
|
+
default:
|
|
119
|
+
return status.supported ? "Not checked yet" : "Updates are not available for this build";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { IAppUpdateStatus } from "@peers-app/peers-sdk";
|
|
2
|
+
import { fireEvent, render, waitFor } from "@testing-library/react";
|
|
3
|
+
import { AppUpdatesSettings } from "./app-updates-settings";
|
|
4
|
+
|
|
5
|
+
let mockStatus: IAppUpdateStatus | undefined;
|
|
6
|
+
const checkForUpdates = jest.fn();
|
|
7
|
+
|
|
8
|
+
jest.mock("../components/tooltip", () => ({ Tooltip: () => null }));
|
|
9
|
+
jest.mock("./use-app-update-status", () => ({ useAppUpdateStatus: () => mockStatus }));
|
|
10
|
+
jest.mock("./app-updates-consumer", () => ({
|
|
11
|
+
...jest.requireActual("./app-updates-consumer"),
|
|
12
|
+
getAppUpdatesConsumer: () =>
|
|
13
|
+
Promise.resolve({ tools: { checkForUpdates: () => checkForUpdates() } }),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
function status(overrides: Partial<IAppUpdateStatus> = {}): IAppUpdateStatus {
|
|
17
|
+
return {
|
|
18
|
+
supported: true,
|
|
19
|
+
canRestart: true,
|
|
20
|
+
platform: "darwin",
|
|
21
|
+
currentVersion: "1.0.0",
|
|
22
|
+
latestVersion: "1.0.0",
|
|
23
|
+
state: "up-to-date",
|
|
24
|
+
installOnRestart: true,
|
|
25
|
+
installOnQuitArmed: false,
|
|
26
|
+
remoteRestartAllowed: true,
|
|
27
|
+
...overrides,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("AppUpdatesSettings", () => {
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
checkForUpdates.mockReset();
|
|
34
|
+
checkForUpdates.mockResolvedValue(status());
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("explains hosts that do not update themselves", () => {
|
|
38
|
+
mockStatus = status({ supported: false, canRestart: false });
|
|
39
|
+
const view = render(<AppUpdatesSettings />);
|
|
40
|
+
expect(view.container).toHaveTextContent("This device does not update itself");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("shows versions, both settings, and checks on demand", async () => {
|
|
44
|
+
mockStatus = status();
|
|
45
|
+
const view = render(<AppUpdatesSettings />);
|
|
46
|
+
expect(view.container).toHaveTextContent("Installed version1.0.0");
|
|
47
|
+
expect(view.getByLabelText("Install updates automatically when Peers restarts")).toBeTruthy();
|
|
48
|
+
expect(
|
|
49
|
+
view.getByLabelText("Allow my other devices to update and restart this device"),
|
|
50
|
+
).toBeTruthy();
|
|
51
|
+
expect(view.getByRole("button", { name: /^Restart$/ })).toBeTruthy();
|
|
52
|
+
|
|
53
|
+
fireEvent.click(view.getByRole("button", { name: "Check now" }));
|
|
54
|
+
await waitFor(() => expect(checkForUpdates).toHaveBeenCalledTimes(1));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("adds no note when the user opts out of a downloaded update", () => {
|
|
58
|
+
mockStatus = status({
|
|
59
|
+
state: "downloaded",
|
|
60
|
+
latestVersion: "1.1.0",
|
|
61
|
+
downloadedVersion: "1.1.0",
|
|
62
|
+
installOnRestart: false,
|
|
63
|
+
installOnQuitArmed: false,
|
|
64
|
+
});
|
|
65
|
+
const view = render(<AppUpdatesSettings />);
|
|
66
|
+
expect(view.container).not.toHaveTextContent("will still install");
|
|
67
|
+
expect(view.getByRole("button", { name: /Update & restart/ })).toBeTruthy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("notes when macOS accepted an update for an earlier Update & restart", () => {
|
|
71
|
+
mockStatus = status({
|
|
72
|
+
state: "downloaded",
|
|
73
|
+
latestVersion: "1.1.0",
|
|
74
|
+
downloadedVersion: "1.1.0",
|
|
75
|
+
installOnRestart: false,
|
|
76
|
+
installOnQuitArmed: true,
|
|
77
|
+
});
|
|
78
|
+
const view = render(<AppUpdatesSettings />);
|
|
79
|
+
expect(view.container).toHaveTextContent(
|
|
80
|
+
"macOS prepared version 1.1.0 for an earlier Update & restart",
|
|
81
|
+
);
|
|
82
|
+
expect(view.getByRole("button", { name: /Update & restart/ })).toBeTruthy();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("shows a failed check and lets the user retry", async () => {
|
|
86
|
+
mockStatus = status();
|
|
87
|
+
checkForUpdates.mockRejectedValueOnce(new Error("Host disconnected"));
|
|
88
|
+
const view = render(<AppUpdatesSettings />);
|
|
89
|
+
fireEvent.click(view.getByRole("button", { name: "Check now" }));
|
|
90
|
+
expect(await view.findByRole("alert")).toHaveTextContent("Host disconnected");
|
|
91
|
+
fireEvent.click(view.getByRole("button", { name: "Check now" }));
|
|
92
|
+
await waitFor(() => expect(checkForUpdates).toHaveBeenCalledTimes(2));
|
|
93
|
+
expect(view.queryByRole("alert")).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("shows feed errors while a downloaded update remains ready to install", () => {
|
|
97
|
+
mockStatus = status({
|
|
98
|
+
state: "downloaded",
|
|
99
|
+
latestVersion: "1.1.0",
|
|
100
|
+
downloadedVersion: "1.1.0",
|
|
101
|
+
error: "Feed unreachable",
|
|
102
|
+
});
|
|
103
|
+
const view = render(<AppUpdatesSettings />);
|
|
104
|
+
expect(view.container).toHaveTextContent(
|
|
105
|
+
"Version 1.1.0 is ready to install. Update problem: Feed unreachable",
|
|
106
|
+
);
|
|
107
|
+
expect(view.getByRole("button", { name: /Update & restart/ })).toBeEnabled();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
allowRemoteAppUpdateRestart,
|
|
3
|
+
type IAppUpdateStatus,
|
|
4
|
+
installAppUpdatesOnRestart,
|
|
5
|
+
} from "@peers-app/peers-sdk";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { Checkbox } from "../components/checkbox";
|
|
8
|
+
import { Tooltip } from "../components/tooltip";
|
|
9
|
+
import { UpdateAndRestartButton } from "./app-update-controls";
|
|
10
|
+
import {
|
|
11
|
+
describeAppUpdateStatus,
|
|
12
|
+
getAppUpdatesConsumer,
|
|
13
|
+
hasAppUpdate,
|
|
14
|
+
isAppRestarting,
|
|
15
|
+
} from "./app-updates-consumer";
|
|
16
|
+
import { useAppUpdateStatus } from "./use-app-update-status";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* macOS accepted the update for an Update & restart that timed out, and installs it when
|
|
20
|
+
* Peers quits; that cannot be withdrawn.
|
|
21
|
+
*/
|
|
22
|
+
function isPreparedDespiteOptOut(status: IAppUpdateStatus): boolean {
|
|
23
|
+
return status.platform === "darwin" && !status.installOnRestart && status.installOnQuitArmed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function SettingCheckbox({
|
|
27
|
+
id,
|
|
28
|
+
label,
|
|
29
|
+
checked,
|
|
30
|
+
help,
|
|
31
|
+
}: {
|
|
32
|
+
id: string;
|
|
33
|
+
label: string;
|
|
34
|
+
checked: typeof installAppUpdatesOnRestart;
|
|
35
|
+
help: string;
|
|
36
|
+
}) {
|
|
37
|
+
return (
|
|
38
|
+
<div className="form-check mb-2">
|
|
39
|
+
<Checkbox id={id} className="form-check-input" checked={checked} />
|
|
40
|
+
<label htmlFor={id} className="form-check-label small me-1">
|
|
41
|
+
{label}
|
|
42
|
+
</label>
|
|
43
|
+
<Tooltip markdownContent={help} />
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Settings tab for this device's application updates: version, check and install controls,
|
|
50
|
+
* and the two per-device update settings.
|
|
51
|
+
*/
|
|
52
|
+
export function AppUpdatesSettings() {
|
|
53
|
+
const status = useAppUpdateStatus();
|
|
54
|
+
const [checking, setChecking] = useState(false);
|
|
55
|
+
const [checkError, setCheckError] = useState<string>();
|
|
56
|
+
|
|
57
|
+
if (!status) {
|
|
58
|
+
return <p className="small text-muted">Loading update status…</p>;
|
|
59
|
+
}
|
|
60
|
+
if (!status.canRestart) {
|
|
61
|
+
return (
|
|
62
|
+
<p className="small text-muted">
|
|
63
|
+
This device does not update itself. Browser installs update when the page reloads.
|
|
64
|
+
</p>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
<h5 className="mb-3">Updates</h5>
|
|
70
|
+
<dl className="row small mb-2">
|
|
71
|
+
<dt className="col-4">Installed version</dt>
|
|
72
|
+
<dd className="col-8">{status.currentVersion}</dd>
|
|
73
|
+
{status.latestVersion && (
|
|
74
|
+
<>
|
|
75
|
+
<dt className="col-4">Latest version</dt>
|
|
76
|
+
<dd className="col-8">{status.latestVersion}</dd>
|
|
77
|
+
</>
|
|
78
|
+
)}
|
|
79
|
+
<dt className="col-4">Status</dt>
|
|
80
|
+
<dd className="col-8">{describeAppUpdateStatus(status)}</dd>
|
|
81
|
+
{status.lastCheckedAt != null && (
|
|
82
|
+
<>
|
|
83
|
+
<dt className="col-4">Last checked</dt>
|
|
84
|
+
<dd className="col-8">{new Date(status.lastCheckedAt).toLocaleString()}</dd>
|
|
85
|
+
</>
|
|
86
|
+
)}
|
|
87
|
+
</dl>
|
|
88
|
+
<div className="d-flex gap-2 mb-3">
|
|
89
|
+
<button
|
|
90
|
+
type="button"
|
|
91
|
+
className="btn btn-sm btn-outline-secondary"
|
|
92
|
+
disabled={!status.supported || checking || isAppRestarting(status)}
|
|
93
|
+
onClick={() => {
|
|
94
|
+
setChecking(true);
|
|
95
|
+
setCheckError(undefined);
|
|
96
|
+
getAppUpdatesConsumer()
|
|
97
|
+
.then((appUpdates) => appUpdates.tools.checkForUpdates())
|
|
98
|
+
.catch((err: unknown) =>
|
|
99
|
+
setCheckError(err instanceof Error ? err.message : String(err)),
|
|
100
|
+
)
|
|
101
|
+
.finally(() => setChecking(false));
|
|
102
|
+
}}
|
|
103
|
+
>
|
|
104
|
+
Check now
|
|
105
|
+
</button>
|
|
106
|
+
<UpdateAndRestartButton
|
|
107
|
+
status={status}
|
|
108
|
+
className={`btn btn-sm ${hasAppUpdate(status) ? "btn-warning" : "btn-outline-secondary"}`}
|
|
109
|
+
/>
|
|
110
|
+
</div>
|
|
111
|
+
{checkError && (
|
|
112
|
+
<p className="small text-danger" role="alert">
|
|
113
|
+
{checkError}
|
|
114
|
+
</p>
|
|
115
|
+
)}
|
|
116
|
+
<SettingCheckbox
|
|
117
|
+
id="installAppUpdatesOnRestart"
|
|
118
|
+
label="Install updates automatically when Peers restarts"
|
|
119
|
+
checked={installAppUpdatesOnRestart}
|
|
120
|
+
help="Updates always download in the background. When this is off, they install only when you choose **Update & restart** here or in the network status menu."
|
|
121
|
+
/>
|
|
122
|
+
{isPreparedDespiteOptOut(status) && (
|
|
123
|
+
<p className="small text-muted ms-4">
|
|
124
|
+
macOS prepared version {status.downloadedVersion} for an earlier Update & restart, so
|
|
125
|
+
it will still install when Peers quits. Later updates will wait for you.
|
|
126
|
+
</p>
|
|
127
|
+
)}
|
|
128
|
+
<SettingCheckbox
|
|
129
|
+
id="allowRemoteAppUpdateRestart"
|
|
130
|
+
label="Allow my other devices to update and restart this device"
|
|
131
|
+
checked={allowRemoteAppUpdateRestart}
|
|
132
|
+
help="Lets your other devices, and people you trust as yourself, run **Update & restart** on this device from Identity → Devices or the Network Viewer."
|
|
133
|
+
/>
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
}
|