@peers-app/peers-ui 0.27.2 → 0.27.4
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/screens/network-viewer/network-viewer-ipc.d.ts +3 -1
- package/dist/screens/network-viewer/network-viewer-ipc.js +6 -0
- package/dist/screens/network-viewer/sync-recovery.js +103 -1
- package/dist/screens/variables/variable-details.js +2 -1
- package/dist/tabs-layout/network-status-indicator.js +26 -12
- package/dist/tabs-layout/use-network-status.d.ts +6 -1
- package/dist/tabs-layout/use-network-status.js +27 -4
- package/package.json +9 -3
- package/.claude/settings.local.json +0 -34
- package/.github/README.md +0 -52
- package/.github/workflows/delete-all-artifacts.yml +0 -49
- package/.github/workflows/publish.yml +0 -51
- package/babel.config.js +0 -7
- package/biome.json +0 -198
- package/dist/app-updates/app-updates-consumer.test.d.ts +0 -1
- package/dist/app-updates/app-updates-consumer.test.js +0 -56
- package/dist/app-updates/app-updates-settings.test.d.ts +0 -1
- package/dist/app-updates/app-updates-settings.test.js +0 -93
- package/dist/app-updates/remote-app-update-panel.test.d.ts +0 -1
- package/dist/app-updates/remote-app-update-panel.test.js +0 -165
- package/dist/components/access-level-field.test.d.ts +0 -1
- package/dist/components/access-level-field.test.js +0 -28
- package/dist/components/message-logs/tool-access-approval-card.test.d.ts +0 -1
- package/dist/components/message-logs/tool-access-approval-card.test.js +0 -102
- package/dist/components/responsive-section-nav.test.d.ts +0 -1
- package/dist/components/responsive-section-nav.test.js +0 -45
- package/dist/globals-hash.test.d.ts +0 -1
- package/dist/globals-hash.test.js +0 -16
- package/dist/hooks/use-observable-state.test.d.ts +0 -1
- package/dist/hooks/use-observable-state.test.js +0 -64
- package/dist/hooks/use-observable.test.d.ts +0 -1
- package/dist/hooks/use-observable.test.js +0 -191
- package/dist/hooks/use-rows.test.d.ts +0 -1
- package/dist/hooks/use-rows.test.js +0 -175
- package/dist/hooks/use-tool.test.d.ts +0 -1
- package/dist/hooks/use-tool.test.js +0 -190
- package/dist/host-shell/host-shell-consumer.test.d.ts +0 -1
- package/dist/host-shell/host-shell-consumer.test.js +0 -28
- package/dist/root-layout/root-layout-host.test.d.ts +0 -1
- package/dist/root-layout/root-layout-host.test.js +0 -86
- package/dist/screens/account/account-screen.test.d.ts +0 -1
- package/dist/screens/account/account-screen.test.js +0 -51
- package/dist/screens/assistants/assistant-config.test.d.ts +0 -1
- package/dist/screens/assistants/assistant-config.test.js +0 -57
- package/dist/screens/contacts/contact-list.test.d.ts +0 -1
- package/dist/screens/contacts/contact-list.test.js +0 -48
- package/dist/screens/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/screens/device-pairing/device-pairing.test.js +0 -119
- package/dist/screens/devices/devices-list.test.d.ts +0 -1
- package/dist/screens/devices/devices-list.test.js +0 -53
- package/dist/screens/groups/group-list.test.d.ts +0 -1
- package/dist/screens/groups/group-list.test.js +0 -38
- package/dist/screens/identity/identity-routes.test.d.ts +0 -1
- package/dist/screens/identity/identity-routes.test.js +0 -51
- package/dist/screens/identity/identity-screen.test.d.ts +0 -1
- package/dist/screens/identity/identity-screen.test.js +0 -103
- package/dist/screens/invites/accept-invite.test.d.ts +0 -1
- package/dist/screens/invites/accept-invite.test.js +0 -103
- package/dist/screens/invites/activity-view.test.d.ts +0 -1
- package/dist/screens/invites/activity-view.test.js +0 -108
- package/dist/screens/invites/invite-classify.test.d.ts +0 -1
- package/dist/screens/invites/invite-classify.test.js +0 -115
- package/dist/screens/network-viewer/network-viewer-ipc.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer-ipc.test.js +0 -61
- package/dist/screens/network-viewer/network-viewer.section.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer.section.test.js +0 -63
- package/dist/screens/network-viewer/sync-recovery.test.d.ts +0 -1
- package/dist/screens/network-viewer/sync-recovery.test.js +0 -104
- package/dist/screens/packages/package-helpers.test.d.ts +0 -1
- package/dist/screens/packages/package-helpers.test.js +0 -53
- package/dist/screens/packages/package-runtime-status.test.d.ts +0 -1
- package/dist/screens/packages/package-runtime-status.test.js +0 -50
- package/dist/screens/packages/packages-ipc.test.d.ts +0 -1
- package/dist/screens/packages/packages-ipc.test.js +0 -43
- package/dist/screens/settings/settings-page.test.d.ts +0 -1
- package/dist/screens/settings/settings-page.test.js +0 -19
- package/dist/screens/tools/tool-access-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-access-ipc.test.js +0 -40
- package/dist/screens/tools/tool-catalog-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-catalog-ipc.test.js +0 -52
- package/dist/tabs-layout/network-status-indicator.test.d.ts +0 -1
- package/dist/tabs-layout/network-status-indicator.test.js +0 -665
- package/dist/tabs-layout/tabs-state.test.d.ts +0 -1
- package/dist/tabs-layout/tabs-state.test.js +0 -110
- package/dist/tabs-layout/use-network-status.test.d.ts +0 -1
- package/dist/tabs-layout/use-network-status.test.js +0 -45
- package/dist/ui-router/ui-loader.test.d.ts +0 -1
- package/dist/ui-router/ui-loader.test.js +0 -91
- package/jest.config.js +0 -25
- package/release-guard.js +0 -10
- package/src/app-updates/app-update-controls.tsx +0 -73
- package/src/app-updates/app-updates-consumer.test.ts +0 -83
- package/src/app-updates/app-updates-consumer.ts +0 -121
- package/src/app-updates/app-updates-settings.test.tsx +0 -109
- package/src/app-updates/app-updates-settings.tsx +0 -136
- package/src/app-updates/remote-app-update-panel.test.tsx +0 -205
- package/src/app-updates/remote-app-update-panel.tsx +0 -210
- package/src/app-updates/use-app-update-status.ts +0 -16
- package/src/command-palette/command-palette-ui.tsx +0 -564
- package/src/command-palette/command-palette.ts +0 -242
- package/src/components/access-level-field.test.tsx +0 -32
- package/src/components/access-level-field.tsx +0 -68
- package/src/components/checkbox.tsx +0 -25
- package/src/components/group-switcher.tsx +0 -526
- package/src/components/input-date.tsx +0 -29
- package/src/components/input-number.tsx +0 -83
- package/src/components/input.tsx +0 -25
- package/src/components/inverse-lazy-list.tsx +0 -107
- package/src/components/io-schema-values.tsx +0 -103
- package/src/components/io-schema.tsx +0 -259
- package/src/components/lazy-list.tsx +0 -115
- package/src/components/list-screen.tsx +0 -126
- package/src/components/loading-indicator.tsx +0 -7
- package/src/components/markdown-editor/autolink-plugin.tsx +0 -29
- package/src/components/markdown-editor/editor-inline.tsx +0 -9
- package/src/components/markdown-editor/editor.tsx +0 -158
- package/src/components/markdown-editor/markdown-plugin.tsx +0 -202
- package/src/components/markdown-editor/mention-node.ts +0 -204
- package/src/components/markdown-editor/mentions-plugin.tsx +0 -354
- package/src/components/markdown-editor/move-line-plugin.tsx +0 -186
- package/src/components/markdown-editor/select-line-boundary-plugin.tsx +0 -95
- package/src/components/markdown-editor/theme.ts +0 -46
- package/src/components/markdown-editor/toolbar.tsx +0 -269
- package/src/components/markdown-with-mentions.tsx +0 -198
- package/src/components/message-logs/message-logs.tsx +0 -523
- package/src/components/message-logs/tool-access-approval-card.test.tsx +0 -127
- package/src/components/message-logs/tool-access-approval-card.tsx +0 -178
- package/src/components/messages/avatar.tsx +0 -171
- package/src/components/messages/channel-message-list.tsx +0 -189
- package/src/components/messages/channel-view.tsx +0 -92
- package/src/components/messages/message-compose.tsx +0 -192
- package/src/components/messages/message-display.tsx +0 -231
- package/src/components/messages/thread-message-list.tsx +0 -135
- package/src/components/qr-scanner.tsx +0 -180
- package/src/components/responsive-section-nav.test.tsx +0 -88
- package/src/components/responsive-section-nav.tsx +0 -92
- package/src/components/router.tsx +0 -175
- package/src/components/save-button.tsx +0 -134
- package/src/components/sortable-list.tsx +0 -130
- package/src/components/tabs.tsx +0 -76
- package/src/components/tooltip.tsx +0 -43
- package/src/components/trust-level-badge.tsx +0 -44
- package/src/components/trust-level-dropdown.tsx +0 -136
- package/src/components/typeahead.tsx +0 -357
- package/src/globals-hash.test.ts +0 -19
- package/src/globals.tsx +0 -226
- package/src/hooks/index.ts +0 -8
- package/src/hooks/use-host-contract.ts +0 -75
- package/src/hooks/use-observable-state.test.tsx +0 -101
- package/src/hooks/use-observable-state.ts +0 -29
- package/src/hooks/use-observable.test.tsx +0 -258
- package/src/hooks/use-observable.ts +0 -67
- package/src/hooks/use-on-screen.ts +0 -24
- package/src/hooks/use-promise.ts +0 -34
- package/src/hooks/use-rows.test.tsx +0 -196
- package/src/hooks/use-rows.ts +0 -120
- package/src/hooks/use-subscription.ts +0 -24
- package/src/hooks/use-tool.test.tsx +0 -225
- package/src/hooks/use-tool.ts +0 -116
- package/src/host-shell/host-shell-consumer.test.ts +0 -32
- package/src/host-shell/host-shell-consumer.ts +0 -53
- package/src/index.tsx +0 -42
- package/src/mention-configs.ts +0 -185
- package/src/operator-console/operator-console-state.ts +0 -119
- package/src/operator-console/operator-console.tsx +0 -233
- package/src/peers-services-registration.ts +0 -6
- package/src/root-layout/global-overlays.ts +0 -50
- package/src/root-layout/layout-picker.tsx +0 -47
- package/src/root-layout/layouts/full-screen-layout.tsx +0 -144
- package/src/root-layout/layouts/tabs-with-console-layout.tsx +0 -260
- package/src/root-layout/root-layout-host.test.tsx +0 -108
- package/src/root-layout/root-layout-host.tsx +0 -147
- package/src/root-layout/root-layout-registry.ts +0 -51
- package/src/root-layout/root-layout-state.ts +0 -55
- package/src/root-layout/root-layout.ts +0 -32
- package/src/screens/account/account-screen.test.tsx +0 -65
- package/src/screens/account/account-screen.tsx +0 -942
- package/src/screens/assistants/assistant-config.test.tsx +0 -54
- package/src/screens/assistants/assistant-config.tsx +0 -121
- package/src/screens/assistants/assistant-details.tsx +0 -89
- package/src/screens/assistants/assistant-info.tsx +0 -66
- package/src/screens/assistants/assistant-list.tsx +0 -145
- package/src/screens/assistants/assistant-tools.tsx +0 -82
- package/src/screens/console-logs/console-logs-list.tsx +0 -374
- package/src/screens/console-logs/log-display.tsx +0 -137
- package/src/screens/console-logs/log-filters.tsx +0 -64
- package/src/screens/console-logs/mobile-log-card.tsx +0 -161
- package/src/screens/console-logs/resizable-table-header.tsx +0 -110
- package/src/screens/contacts/contact-details.tsx +0 -123
- package/src/screens/contacts/contact-list.test.tsx +0 -59
- package/src/screens/contacts/contact-list.tsx +0 -286
- package/src/screens/contacts/index.ts +0 -2
- package/src/screens/data-explorer/data-explorer.tsx +0 -633
- package/src/screens/data-explorer/index.ts +0 -6
- package/src/screens/data-explorer/query-executor.tsx +0 -520
- package/src/screens/device-pairing/device-pairing.test.tsx +0 -143
- package/src/screens/device-pairing/device-pairing.tsx +0 -461
- package/src/screens/device-pairing/identity-ipc.ts +0 -25
- package/src/screens/device-pairing/index.ts +0 -2
- package/src/screens/device-pairing/use-device-pairing-state.ts +0 -15
- package/src/screens/devices/devices-list.test.tsx +0 -68
- package/src/screens/devices/devices-list.tsx +0 -365
- package/src/screens/devices/index.ts +0 -1
- package/src/screens/groups/group-details.tsx +0 -160
- package/src/screens/groups/group-invite-panel.tsx +0 -311
- package/src/screens/groups/group-list.test.tsx +0 -44
- package/src/screens/groups/group-list.tsx +0 -317
- package/src/screens/groups/group-members.tsx +0 -343
- package/src/screens/groups/index.ts +0 -3
- package/src/screens/identity/identity-routes.test.ts +0 -70
- package/src/screens/identity/identity-routes.ts +0 -301
- package/src/screens/identity/identity-screen.test.tsx +0 -138
- package/src/screens/identity/identity-screen.tsx +0 -282
- package/src/screens/identity/index.ts +0 -2
- package/src/screens/identity/invite-contact-panel.tsx +0 -45
- package/src/screens/identity/profile-invite.tsx +0 -93
- package/src/screens/invites/accept-invite.test.tsx +0 -115
- package/src/screens/invites/accept-invite.tsx +0 -318
- package/src/screens/invites/activity-view.test.tsx +0 -127
- package/src/screens/invites/activity-view.tsx +0 -162
- package/src/screens/invites/index.ts +0 -6
- package/src/screens/invites/invite-capture.ts +0 -104
- package/src/screens/invites/invite-classify.test.ts +0 -129
- package/src/screens/invites/invite-share.tsx +0 -104
- package/src/screens/invites/invites-ipc.ts +0 -25
- package/src/screens/invites/pending-invites-list.tsx +0 -256
- package/src/screens/network-viewer/connection-troubleshooter.tsx +0 -395
- package/src/screens/network-viewer/cpu-usage-graph.tsx +0 -294
- package/src/screens/network-viewer/device-details-modal.tsx +0 -339
- package/src/screens/network-viewer/group-details-modal.tsx +0 -421
- package/src/screens/network-viewer/index.ts +0 -8
- package/src/screens/network-viewer/network-viewer-ipc.test.ts +0 -72
- package/src/screens/network-viewer/network-viewer-ipc.ts +0 -39
- package/src/screens/network-viewer/network-viewer-section.ts +0 -12
- package/src/screens/network-viewer/network-viewer.section.test.tsx +0 -68
- package/src/screens/network-viewer/network-viewer.tsx +0 -708
- package/src/screens/network-viewer/remote-logs-panel.tsx +0 -190
- package/src/screens/network-viewer/sync-recovery.test.tsx +0 -114
- package/src/screens/network-viewer/sync-recovery.tsx +0 -461
- package/src/screens/network-viewer/usage-graph.tsx +0 -455
- package/src/screens/packages/local-folder-grants-panel.tsx +0 -290
- package/src/screens/packages/local-folders-ipc.ts +0 -28
- package/src/screens/packages/package-details.tsx +0 -166
- package/src/screens/packages/package-helpers.test.ts +0 -57
- package/src/screens/packages/package-helpers.ts +0 -137
- package/src/screens/packages/package-info.tsx +0 -354
- package/src/screens/packages/package-list.tsx +0 -519
- package/src/screens/packages/package-network-panel.tsx +0 -82
- package/src/screens/packages/package-new-local.tsx +0 -100
- package/src/screens/packages/package-runtime-status.test.tsx +0 -58
- package/src/screens/packages/package-runtime-status.tsx +0 -68
- package/src/screens/packages/package-versions.tsx +0 -298
- package/src/screens/packages/packages-ipc.test.ts +0 -47
- package/src/screens/packages/packages-ipc.ts +0 -125
- package/src/screens/peer-types/peer-type-details.tsx +0 -172
- package/src/screens/peer-types/peer-type-list.tsx +0 -64
- package/src/screens/search/global-search.tsx +0 -406
- package/src/screens/settings/color-mode-dropdown.tsx +0 -82
- package/src/screens/settings/settings-page.test.tsx +0 -24
- package/src/screens/settings/settings-page.tsx +0 -426
- package/src/screens/setup-user.tsx +0 -355
- package/src/screens/tools/tool-access-ipc.test.ts +0 -55
- package/src/screens/tools/tool-access-ipc.ts +0 -27
- package/src/screens/tools/tool-catalog-ipc.test.ts +0 -52
- package/src/screens/tools/tool-catalog-ipc.ts +0 -51
- package/src/screens/tools/tool-details.tsx +0 -52
- package/src/screens/tools/tool-info.tsx +0 -45
- package/src/screens/tools/tool-list.tsx +0 -106
- package/src/screens/tools/tool-schema.tsx +0 -44
- package/src/screens/tools/tool-test-details.tsx +0 -89
- package/src/screens/tools/tool-test-list.tsx +0 -73
- package/src/screens/variables/variable-details.tsx +0 -289
- package/src/screens/variables/variable-list.tsx +0 -110
- package/src/screens/welcome-modal.tsx +0 -294
- package/src/screens/workflows/workflow-details.tsx +0 -115
- package/src/screens/workflows/workflow-info.tsx +0 -22
- package/src/screens/workflows/workflow-instructions.tsx +0 -134
- package/src/screens/workflows/workflow-list.tsx +0 -117
- package/src/setupTests.ts +0 -38
- package/src/system-apps/assistants.app.ts +0 -7
- package/src/system-apps/console-logs.app.ts +0 -7
- package/src/system-apps/data-explorer.app.ts +0 -8
- package/src/system-apps/identity.app.ts +0 -9
- package/src/system-apps/index.ts +0 -77
- package/src/system-apps/mobile-settings.app.ts +0 -7
- package/src/system-apps/network-viewer.app.ts +0 -8
- package/src/system-apps/packages.app.ts +0 -7
- package/src/system-apps/search.app.ts +0 -8
- package/src/system-apps/settings.app.ts +0 -7
- package/src/system-apps/threads.app.ts +0 -7
- package/src/system-apps/tools.app.ts +0 -7
- package/src/system-apps/types.app.ts +0 -7
- package/src/system-apps/variables.app.ts +0 -7
- package/src/system-apps/workflows.app.ts +0 -7
- package/src/tabs-layout/network-status-indicator.test.tsx +0 -799
- package/src/tabs-layout/network-status-indicator.tsx +0 -756
- package/src/tabs-layout/tabs-layout.tsx +0 -857
- package/src/tabs-layout/tabs-state.test.ts +0 -152
- package/src/tabs-layout/tabs-state.ts +0 -587
- package/src/tabs-layout/use-network-status.test.tsx +0 -58
- package/src/tabs-layout/use-network-status.ts +0 -68
- package/src/ui-defaults/index.ts +0 -2
- package/src/ui-defaults/list-screen.tsx +0 -94
- package/src/ui-defaults/markdown-field.tsx +0 -87
- package/src/ui-router/routes-loader.ts +0 -193
- package/src/ui-router/ui-loader.test.tsx +0 -108
- package/src/ui-router/ui-loader.tsx +0 -606
- package/src/utils.ts +0 -95
- package/tsconfig.json +0 -18
|
@@ -1,109 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,136 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import type { IAppUpdateStatus } from "@peers-app/peers-sdk";
|
|
2
|
-
import { act, fireEvent, render, waitFor } from "@testing-library/react";
|
|
3
|
-
import { REMOTE_UPDATE_POLL_MS, RemoteAppUpdatePanel } from "./remote-app-update-panel";
|
|
4
|
-
|
|
5
|
-
const getDeviceUpdateStatus = jest.fn();
|
|
6
|
-
const installUpdateAndRestartOnDevice = jest.fn();
|
|
7
|
-
|
|
8
|
-
jest.mock("./app-updates-consumer", () => ({
|
|
9
|
-
...jest.requireActual("./app-updates-consumer"),
|
|
10
|
-
getAppUpdatesConsumer: () =>
|
|
11
|
-
Promise.resolve({
|
|
12
|
-
tools: {
|
|
13
|
-
getDeviceUpdateStatus: (...args: unknown[]) => getDeviceUpdateStatus(...args),
|
|
14
|
-
installUpdateAndRestartOnDevice: (...args: unknown[]) =>
|
|
15
|
-
installUpdateAndRestartOnDevice(...args),
|
|
16
|
-
},
|
|
17
|
-
}),
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
function remoteStatus(overrides: Partial<IAppUpdateStatus> = {}): IAppUpdateStatus {
|
|
21
|
-
return {
|
|
22
|
-
supported: true,
|
|
23
|
-
canRestart: true,
|
|
24
|
-
platform: "win32",
|
|
25
|
-
currentVersion: "1.0.0",
|
|
26
|
-
latestVersion: "1.1.0",
|
|
27
|
-
downloadedVersion: "1.1.0",
|
|
28
|
-
state: "downloaded",
|
|
29
|
-
installOnRestart: true,
|
|
30
|
-
installOnQuitArmed: true,
|
|
31
|
-
remoteRestartAllowed: true,
|
|
32
|
-
...overrides,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
describe("RemoteAppUpdatePanel", () => {
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
getDeviceUpdateStatus.mockReset();
|
|
39
|
-
installUpdateAndRestartOnDevice.mockReset();
|
|
40
|
-
installUpdateAndRestartOnDevice.mockResolvedValue({ action: "installing" });
|
|
41
|
-
jest.spyOn(window, "confirm").mockReturnValue(true);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
jest.restoreAllMocks();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("updates the other device after confirmation", async () => {
|
|
49
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus());
|
|
50
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" deviceName="Desktop" />);
|
|
51
|
-
|
|
52
|
-
const button = await view.findByRole("button", { name: /Update & restart/ });
|
|
53
|
-
expect(view.getByTestId("remote-app-update")).toHaveTextContent(
|
|
54
|
-
"Version 1.0.0 · Version 1.1.0 is ready to install",
|
|
55
|
-
);
|
|
56
|
-
expect(getDeviceUpdateStatus).toHaveBeenCalledWith({ deviceId: "desktop" });
|
|
57
|
-
|
|
58
|
-
fireEvent.click(button);
|
|
59
|
-
expect(window.confirm).toHaveBeenCalledWith("Update Desktop to 1.1.0 and restart it?");
|
|
60
|
-
await waitFor(() =>
|
|
61
|
-
expect(installUpdateAndRestartOnDevice).toHaveBeenCalledWith({ deviceId: "desktop" }),
|
|
62
|
-
);
|
|
63
|
-
await view.findByText("Request sent");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("offers a plain restart when the device is up to date", async () => {
|
|
67
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus({ state: "up-to-date" }));
|
|
68
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
69
|
-
fireEvent.click(await view.findByRole("button", { name: /^Restart$/ }));
|
|
70
|
-
expect(window.confirm).toHaveBeenCalledWith(
|
|
71
|
-
"Restart desktop? It will check for an update first.",
|
|
72
|
-
);
|
|
73
|
-
await waitFor(() => expect(installUpdateAndRestartOnDevice).toHaveBeenCalled());
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("does nothing when the confirmation is declined", async () => {
|
|
77
|
-
(window.confirm as jest.Mock).mockReturnValue(false);
|
|
78
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus());
|
|
79
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
80
|
-
fireEvent.click(await view.findByRole("button", { name: /Update & restart/ }));
|
|
81
|
-
expect(installUpdateAndRestartOnDevice).not.toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("explains why the action is disabled", async () => {
|
|
85
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus({ remoteRestartAllowed: false }));
|
|
86
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
87
|
-
expect(await view.findByRole("button", { name: /Update & restart/ })).toBeDisabled();
|
|
88
|
-
expect(view.getByTestId("remote-app-update")).toHaveTextContent(
|
|
89
|
-
"does not allow remote restarts",
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus({ installNeedsElevation: true }));
|
|
93
|
-
const elevated = render(<RemoteAppUpdatePanel deviceId="linux-box" />);
|
|
94
|
-
await waitFor(() =>
|
|
95
|
-
expect(elevated.getAllByRole("button", { name: /Update & restart/ })[1]).toBeDisabled(),
|
|
96
|
-
);
|
|
97
|
-
expect(elevated.getAllByTestId("remote-app-update")[1]).toHaveTextContent(
|
|
98
|
-
"administrator password",
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it.each([
|
|
103
|
-
[
|
|
104
|
-
"a device that cannot restart itself",
|
|
105
|
-
() => Promise.resolve(remoteStatus({ canRestart: false })),
|
|
106
|
-
],
|
|
107
|
-
[
|
|
108
|
-
"a device that does not trust this user",
|
|
109
|
-
() =>
|
|
110
|
-
Promise.reject(new Error("Permission denied: tool 'getUpdateStatus'.run on contract x")),
|
|
111
|
-
],
|
|
112
|
-
[
|
|
113
|
-
"a build without App Updates",
|
|
114
|
-
() => Promise.reject(new Error("No contract provider registered for x v1")),
|
|
115
|
-
],
|
|
116
|
-
])("renders nothing for %s", async (_label, result) => {
|
|
117
|
-
getDeviceUpdateStatus.mockImplementation(result);
|
|
118
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
119
|
-
await waitFor(() => expect(view.queryByTestId("remote-app-update")).toBeNull());
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("reports an unreachable device", async () => {
|
|
123
|
-
getDeviceUpdateStatus.mockRejectedValue(new Error("Device desktop is not connected"));
|
|
124
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
125
|
-
await view.findByText("Not reachable: Device desktop is not connected");
|
|
126
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus());
|
|
127
|
-
fireEvent.click(view.getByRole("button", { name: "Retry" }));
|
|
128
|
-
await view.findByRole("button", { name: /Update & restart/ });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("clears the previous device's action while a new target loads", async () => {
|
|
132
|
-
getDeviceUpdateStatus.mockResolvedValueOnce(remoteStatus());
|
|
133
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
134
|
-
await view.findByRole("button", { name: /Update & restart/ });
|
|
135
|
-
let finish!: (status: IAppUpdateStatus) => void;
|
|
136
|
-
getDeviceUpdateStatus.mockImplementationOnce(
|
|
137
|
-
() =>
|
|
138
|
-
new Promise<IAppUpdateStatus>((resolve) => {
|
|
139
|
-
finish = resolve;
|
|
140
|
-
}),
|
|
141
|
-
);
|
|
142
|
-
view.rerender(<RemoteAppUpdatePanel deviceId="another-desktop" />);
|
|
143
|
-
expect(view.queryByRole("button", { name: /Update & restart/ })).toBeNull();
|
|
144
|
-
expect(view.getByText("Checking this device…")).toBeTruthy();
|
|
145
|
-
await act(async () => {
|
|
146
|
-
await Promise.resolve();
|
|
147
|
-
finish(remoteStatus({ remoteRestartAllowed: false }));
|
|
148
|
-
});
|
|
149
|
-
expect(view.getByRole("button", { name: /Update & restart/ })).toBeDisabled();
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("accepts slow poll responses without overlapping requests and cleans up timers", async () => {
|
|
153
|
-
jest.useFakeTimers();
|
|
154
|
-
try {
|
|
155
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus());
|
|
156
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
157
|
-
await act(async () => {});
|
|
158
|
-
let finish!: (status: IAppUpdateStatus) => void;
|
|
159
|
-
getDeviceUpdateStatus.mockImplementationOnce(
|
|
160
|
-
() =>
|
|
161
|
-
new Promise<IAppUpdateStatus>((resolve) => {
|
|
162
|
-
finish = resolve;
|
|
163
|
-
}),
|
|
164
|
-
);
|
|
165
|
-
fireEvent.click(view.getByRole("button", { name: /Update & restart/ }));
|
|
166
|
-
await act(async () => {});
|
|
167
|
-
await act(async () => {
|
|
168
|
-
jest.advanceTimersByTime(REMOTE_UPDATE_POLL_MS * 3);
|
|
169
|
-
});
|
|
170
|
-
expect(getDeviceUpdateStatus).toHaveBeenCalledTimes(2);
|
|
171
|
-
await act(async () => {
|
|
172
|
-
finish(remoteStatus({ currentVersion: "1.1.0", state: "up-to-date" }));
|
|
173
|
-
});
|
|
174
|
-
expect(view.getByText("Version 1.1.0 · Up to date")).toBeTruthy();
|
|
175
|
-
await act(async () => {
|
|
176
|
-
jest.advanceTimersByTime(REMOTE_UPDATE_POLL_MS);
|
|
177
|
-
});
|
|
178
|
-
expect(getDeviceUpdateStatus).toHaveBeenCalledTimes(3);
|
|
179
|
-
view.unmount();
|
|
180
|
-
expect(jest.getTimerCount()).toBe(0);
|
|
181
|
-
} finally {
|
|
182
|
-
jest.useRealTimers();
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("confirms the newer downloading version instead of the older cached version", async () => {
|
|
187
|
-
getDeviceUpdateStatus.mockResolvedValue(
|
|
188
|
-
remoteStatus({ state: "downloading", latestVersion: "1.2.0", downloadedVersion: "1.1.0" }),
|
|
189
|
-
);
|
|
190
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" deviceName="Desktop" />);
|
|
191
|
-
fireEvent.click(await view.findByRole("button", { name: /Update & restart/ }));
|
|
192
|
-
expect(window.confirm).toHaveBeenCalledWith("Update Desktop to 1.2.0 and restart it?");
|
|
193
|
-
await view.findByText("Request sent");
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("shows a failed request", async () => {
|
|
197
|
-
getDeviceUpdateStatus.mockResolvedValue(remoteStatus());
|
|
198
|
-
installUpdateAndRestartOnDevice.mockRejectedValue(
|
|
199
|
-
new Error("Permission denied: this device does not allow other devices to update"),
|
|
200
|
-
);
|
|
201
|
-
const view = render(<RemoteAppUpdatePanel deviceId="desktop" />);
|
|
202
|
-
fireEvent.click(await view.findByRole("button", { name: /Update & restart/ }));
|
|
203
|
-
await view.findByText(/does not allow other devices to update/);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import type { IAppUpdateStatus } from "@peers-app/peers-sdk";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import { APP_UPDATE_ICON_CLASS } from "./app-update-controls";
|
|
4
|
-
import {
|
|
5
|
-
classifyAppUpdatesError,
|
|
6
|
-
describeAppUpdateStatus,
|
|
7
|
-
getAppUpdatesConsumer,
|
|
8
|
-
getAppUpdateVersion,
|
|
9
|
-
hasAppUpdate,
|
|
10
|
-
isAppRestarting,
|
|
11
|
-
} from "./app-updates-consumer";
|
|
12
|
-
|
|
13
|
-
/** How often the panel refreshes the target's status after an update or restart request. */
|
|
14
|
-
export const REMOTE_UPDATE_POLL_MS = 5_000;
|
|
15
|
-
/** How long the panel keeps refreshing after a request. */
|
|
16
|
-
export const REMOTE_UPDATE_POLL_DURATION_MS = 3 * 60_000;
|
|
17
|
-
|
|
18
|
-
type RemoteUpdateState =
|
|
19
|
-
| { kind: "loading" }
|
|
20
|
-
| { kind: "hidden" }
|
|
21
|
-
| { kind: "unreachable"; message: string }
|
|
22
|
-
| { kind: "error"; message: string }
|
|
23
|
-
| { kind: "ready"; status: IAppUpdateStatus };
|
|
24
|
-
|
|
25
|
-
function errorMessage(error: unknown): string {
|
|
26
|
-
return error instanceof Error ? error.message : String(error);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function disabledReason(status: IAppUpdateStatus): string | undefined {
|
|
30
|
-
if (!status.remoteRestartAllowed) {
|
|
31
|
-
return "This device does not allow remote restarts. Turn on “Allow my other devices to update and restart this device” in its Settings → Updates.";
|
|
32
|
-
}
|
|
33
|
-
if (status.installNeedsElevation) {
|
|
34
|
-
return "Installing updates on this device needs an administrator password, so update it at the device.";
|
|
35
|
-
}
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Card showing another device's app version with an **Update & restart** action.
|
|
41
|
-
*
|
|
42
|
-
* The local host relays both calls to the target, which requires that it trusts this user
|
|
43
|
-
* as `Self` and allows remote restarts. Renders nothing when the target cannot update or
|
|
44
|
-
* restart itself, runs a build without App Updates, or does not trust this user.
|
|
45
|
-
*
|
|
46
|
-
* @param props.deviceId - Target device.
|
|
47
|
-
* @param props.deviceName - Name used in the confirmation prompt.
|
|
48
|
-
*/
|
|
49
|
-
export function RemoteAppUpdatePanel({
|
|
50
|
-
deviceId,
|
|
51
|
-
deviceName,
|
|
52
|
-
}: {
|
|
53
|
-
deviceId: string;
|
|
54
|
-
deviceName?: string;
|
|
55
|
-
}) {
|
|
56
|
-
// Route changes must not keep another device's status, consent switch, or pending request.
|
|
57
|
-
return <DeviceAppUpdatePanel key={deviceId} deviceId={deviceId} deviceName={deviceName} />;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function DeviceAppUpdatePanel({ deviceId, deviceName }: { deviceId: string; deviceName?: string }) {
|
|
61
|
-
const [state, setState] = useState<RemoteUpdateState>({ kind: "loading" });
|
|
62
|
-
const [refreshKey, setRefreshKey] = useState(0);
|
|
63
|
-
const [requestedAt, setRequestedAt] = useState<number>();
|
|
64
|
-
const [requestError, setRequestError] = useState<string>();
|
|
65
|
-
const [sending, setSending] = useState(false);
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
let active = true;
|
|
69
|
-
let poll: ReturnType<typeof setTimeout> | undefined;
|
|
70
|
-
const load = () => {
|
|
71
|
-
void getAppUpdatesConsumer()
|
|
72
|
-
.then((appUpdates) => appUpdates.tools.getDeviceUpdateStatus({ deviceId }))
|
|
73
|
-
.then((status) => {
|
|
74
|
-
if (active) {
|
|
75
|
-
setState(status.canRestart ? { kind: "ready", status } : { kind: "hidden" });
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
.catch((error: unknown) => {
|
|
79
|
-
if (!active) return;
|
|
80
|
-
const kind = classifyAppUpdatesError(error);
|
|
81
|
-
if (kind === "unavailable" || kind === "denied") {
|
|
82
|
-
setState({ kind: "hidden" });
|
|
83
|
-
} else {
|
|
84
|
-
setState({
|
|
85
|
-
kind: kind === "unreachable" ? "unreachable" : "error",
|
|
86
|
-
message: errorMessage(error),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
.finally(() => {
|
|
91
|
-
// Wait for the preceding RPC: a slow target can take up to 30s to answer.
|
|
92
|
-
// An interval would overlap calls and discard every response as stale.
|
|
93
|
-
if (
|
|
94
|
-
active &&
|
|
95
|
-
requestedAt !== undefined &&
|
|
96
|
-
Date.now() - requestedAt < REMOTE_UPDATE_POLL_DURATION_MS
|
|
97
|
-
) {
|
|
98
|
-
poll = setTimeout(load, REMOTE_UPDATE_POLL_MS);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
load();
|
|
103
|
-
return () => {
|
|
104
|
-
active = false;
|
|
105
|
-
if (poll) clearTimeout(poll);
|
|
106
|
-
};
|
|
107
|
-
}, [deviceId, refreshKey, requestedAt]);
|
|
108
|
-
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
if (requestedAt === undefined) return;
|
|
111
|
-
const stop = setTimeout(() => setRequestedAt(undefined), REMOTE_UPDATE_POLL_DURATION_MS);
|
|
112
|
-
return () => {
|
|
113
|
-
clearTimeout(stop);
|
|
114
|
-
};
|
|
115
|
-
}, [requestedAt]);
|
|
116
|
-
|
|
117
|
-
if (state.kind === "hidden") {
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const requestUpdate = (status: IAppUpdateStatus) => {
|
|
122
|
-
const name = deviceName || deviceId;
|
|
123
|
-
const prompt = hasAppUpdate(status)
|
|
124
|
-
? `Update ${name} to ${getAppUpdateVersion(status)} and restart it?`
|
|
125
|
-
: `Restart ${name}? It will check for an update first.`;
|
|
126
|
-
if (!confirm(prompt)) return;
|
|
127
|
-
setSending(true);
|
|
128
|
-
setRequestError(undefined);
|
|
129
|
-
getAppUpdatesConsumer()
|
|
130
|
-
.then((appUpdates) => appUpdates.tools.installUpdateAndRestartOnDevice({ deviceId }))
|
|
131
|
-
.then(() => {
|
|
132
|
-
setRequestedAt(Date.now());
|
|
133
|
-
setRefreshKey((key) => key + 1);
|
|
134
|
-
})
|
|
135
|
-
.catch((error: unknown) => setRequestError(errorMessage(error)))
|
|
136
|
-
.finally(() => setSending(false));
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<div className="card mt-3" data-testid="remote-app-update">
|
|
141
|
-
<div className="card-body py-2 px-3 small">
|
|
142
|
-
<div className="fw-semibold mb-1">App version</div>
|
|
143
|
-
{state.kind === "loading" && <div className="text-muted">Checking this device…</div>}
|
|
144
|
-
{state.kind === "unreachable" && (
|
|
145
|
-
<div className="text-muted">
|
|
146
|
-
{requestedAt !== undefined ? "Restarting…" : `Not reachable: ${state.message}`}
|
|
147
|
-
</div>
|
|
148
|
-
)}
|
|
149
|
-
{state.kind === "error" && <div className="text-danger">{state.message}</div>}
|
|
150
|
-
{(state.kind === "unreachable" || state.kind === "error") && (
|
|
151
|
-
<button
|
|
152
|
-
type="button"
|
|
153
|
-
className="btn btn-sm btn-outline-secondary mt-2"
|
|
154
|
-
onClick={() => {
|
|
155
|
-
setState({ kind: "loading" });
|
|
156
|
-
setRefreshKey((key) => key + 1);
|
|
157
|
-
}}
|
|
158
|
-
>
|
|
159
|
-
Retry
|
|
160
|
-
</button>
|
|
161
|
-
)}
|
|
162
|
-
{state.kind === "ready" && (
|
|
163
|
-
<RemoteStatus
|
|
164
|
-
status={state.status}
|
|
165
|
-
sending={sending}
|
|
166
|
-
requested={requestedAt !== undefined}
|
|
167
|
-
onRequest={() => requestUpdate(state.status)}
|
|
168
|
-
/>
|
|
169
|
-
)}
|
|
170
|
-
{requestError && <div className="text-danger mt-1">{requestError}</div>}
|
|
171
|
-
</div>
|
|
172
|
-
</div>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function RemoteStatus({
|
|
177
|
-
status,
|
|
178
|
-
sending,
|
|
179
|
-
requested,
|
|
180
|
-
onRequest,
|
|
181
|
-
}: {
|
|
182
|
-
status: IAppUpdateStatus;
|
|
183
|
-
sending: boolean;
|
|
184
|
-
requested: boolean;
|
|
185
|
-
onRequest: () => void;
|
|
186
|
-
}) {
|
|
187
|
-
const reason = disabledReason(status);
|
|
188
|
-
const update = hasAppUpdate(status);
|
|
189
|
-
return (
|
|
190
|
-
<>
|
|
191
|
-
<div className="mb-2">
|
|
192
|
-
{status.currentVersion ? `Version ${status.currentVersion} · ` : ""}
|
|
193
|
-
{describeAppUpdateStatus(status)}
|
|
194
|
-
</div>
|
|
195
|
-
<button
|
|
196
|
-
type="button"
|
|
197
|
-
className={`btn btn-sm ${update ? "btn-warning" : "btn-outline-secondary"}`}
|
|
198
|
-
disabled={Boolean(reason) || sending || isAppRestarting(status)}
|
|
199
|
-
onClick={onRequest}
|
|
200
|
-
>
|
|
201
|
-
<i className={`bi ${APP_UPDATE_ICON_CLASS} me-1`} aria-hidden="true" />
|
|
202
|
-
{update ? "Update & restart" : "Restart"}
|
|
203
|
-
</button>
|
|
204
|
-
{requested && !isAppRestarting(status) && (
|
|
205
|
-
<span className="text-muted ms-2">Request sent</span>
|
|
206
|
-
)}
|
|
207
|
-
{reason && <div className="text-muted mt-1">{reason}</div>}
|
|
208
|
-
</>
|
|
209
|
-
);
|
|
210
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { IAppUpdateStatus } from "@peers-app/peers-sdk";
|
|
2
|
-
import { useObservable } from "../hooks";
|
|
3
|
-
import { useHostContract } from "../hooks/use-host-contract";
|
|
4
|
-
import { appUpdatesContract } from "./app-updates-consumer";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Subscribe to the local host's application update status.
|
|
8
|
-
*
|
|
9
|
-
* @returns The live status, or `undefined` while the host transport is down. Hosts that
|
|
10
|
-
* cannot update themselves (PWA, headless) report `supported: false`.
|
|
11
|
-
*/
|
|
12
|
-
export function useAppUpdateStatus(): IAppUpdateStatus | undefined {
|
|
13
|
-
const { consumer } = useHostContract(appUpdatesContract);
|
|
14
|
-
const [status] = useObservable<IAppUpdateStatus | undefined>(consumer?.observables.status);
|
|
15
|
-
return status;
|
|
16
|
-
}
|