Skip to content

Commit 7c81f45

Browse files
ChrisChris
authored andcommitted
feat(web): add remote sleep prevention setting
1 parent e52d224 commit 7c81f45

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
AuthStandardClientScopes,
2020
AuthTerminalOperateScope,
2121
type AuthClientSession,
22+
type ClientSettings,
2223
type AuthEnvironmentScope,
2324
type AuthPairingLink,
2425
type AdvertisedEndpoint,
@@ -37,6 +38,7 @@ import * as DateTime from "effect/DateTime";
3738
import * as Option from "effect/Option";
3839

3940
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
41+
import { useClientSettings, useUpdateClientSettings } from "../../hooks/useSettings";
4042
import { cn } from "../../lib/utils";
4143
import { formatElapsedDurationLabel, formatExpiresInLabel } from "../../timestampFormat";
4244
import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls";
@@ -1707,6 +1709,39 @@ function CloudLinkRow({ canManageRelay }: { readonly canManageRelay: boolean })
17071709
return hasCloudPublicConfig() ? <ConfiguredCloudLinkRow canManageRelay={canManageRelay} /> : null;
17081710
}
17091711

1712+
const selectPreventSleepForRemoteConnections = (settings: ClientSettings) =>
1713+
settings.preventSleepForRemoteConnections;
1714+
1715+
function DesktopSleepPreventionRow() {
1716+
const preventSleepForRemoteConnections = useClientSettings(
1717+
selectPreventSleepForRemoteConnections,
1718+
);
1719+
const updateClientSettings = useUpdateClientSettings();
1720+
1721+
return (
1722+
<SettingsRow
1723+
{...searchableSetting("prevent-automatic-sleep")}
1724+
description="Keep this computer available to remote clients by preventing automatic idle sleep while T3 Code runs. The display may turn off; closing a laptop lid can still sleep it."
1725+
status={
1726+
preventSleepForRemoteConnections ? null : (
1727+
<span className="block text-warning">
1728+
Remote connections can become unavailable when this computer sleeps.
1729+
</span>
1730+
)
1731+
}
1732+
control={
1733+
<Switch
1734+
checked={preventSleepForRemoteConnections}
1735+
onCheckedChange={(checked) =>
1736+
updateClientSettings({ preventSleepForRemoteConnections: Boolean(checked) })
1737+
}
1738+
aria-label="Prevent automatic sleep for remote connections"
1739+
/>
1740+
}
1741+
/>
1742+
);
1743+
}
1744+
17101745
function EmptyRemoteEnvironments({ cloudEnabled = true }: { readonly cloudEnabled?: boolean }) {
17111746
return (
17121747
<Empty className="min-h-52">
@@ -3062,6 +3097,7 @@ export function ConnectionsSettings() {
30623097
) : null}
30633098
{desktopBridge ? (
30643099
<>
3100+
<DesktopSleepPreventionRow />
30653101
{renderNetworkAccessRow()}
30663102
{renderEndpointRows("endpoint-rail")}
30673103
{renderTailscaleRow()}

‎apps/web/src/components/settings/settingsSearch.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ describe("searchSettings", () => {
6262

6363
it("hides desktop-only settings from browser search", () => {
6464
expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "quit-confirmation")).toBe(true);
65+
expect(SETTINGS_SEARCH_ITEMS.some((item) => item.id === "prevent-automatic-sleep")).toBe(true);
6566
expect(searchSettings("quit confirmation")).toEqual([]);
67+
expect(searchSettings("prevent automatic sleep")).toEqual([]);
6668
});
6769

6870
it("keeps catalog result ids unique", () => {
@@ -73,6 +75,10 @@ describe("searchSettings", () => {
7375
it("serves anchor props to panels from the catalog", () => {
7476
expect(searchableSetting("word-wrap")).toEqual({ id: "word-wrap", title: "Word wrap" });
7577
expect(searchableSetting("archive")).toEqual({ id: "archive", title: "Archived threads" });
78+
expect(searchableSetting("prevent-automatic-sleep")).toEqual({
79+
id: "prevent-automatic-sleep",
80+
title: "Prevent automatic sleep",
81+
});
7682
});
7783

7884
it("routes appearance settings to their current section", () => {

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ export const SETTINGS_SEARCH_ITEMS = [
237237
title: "Remote environments",
238238
to: "/settings/connections",
239239
},
240+
{
241+
id: "prevent-automatic-sleep",
242+
title: "Prevent automatic sleep",
243+
to: "/settings/connections",
244+
desktopOnly: true,
245+
},
240246
{
241247
id: "archive",
242248
title: "Archived threads",

‎docs/user/remote-access.md‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ That gives you:
3232
- transport security at the network layer
3333
- less exposure than opening the server to the public internet
3434

35+
## Keeping the Desktop Host Awake
36+
37+
In the desktop app, open **Settings** → **Connections** and turn on **Prevent automatic sleep**
38+
when this computer should remain available to remote clients. T3 Code then holds the operating
39+
system's native sleep-prevention assertion for as long as the desktop app is running. You do not
40+
need to run `caffeinate` or change the computer's system sleep schedule.
41+
42+
The display can still turn off. Manually choosing Sleep or closing a laptop lid can still put the
43+
computer to sleep, which makes its T3 Code environment unavailable until the computer wakes.
44+
3545
## Enabling Network Access
3646

3747
There are three ways to reach your server from another device: expose the desktop app's backend,
@@ -43,8 +53,9 @@ If you are already running the desktop app and want to make it reachable from ot
4353

4454
1. Open **Settings** → **Connections**.
4555
2. Under **This environment**, toggle **Network access** on. This will restart the app and run the backend on all network interfaces.
46-
3. The settings panel will show the default reachable endpoint, with a `+N` control when more endpoints are available. Expand it to inspect alternatives such as loopback, LAN, private-network, or HTTPS endpoints.
47-
4. Use **Create Link** to generate a pairing link you can share with another device.
56+
3. Turn on **Prevent automatic sleep** if this computer should stay reachable while unattended.
57+
4. The settings panel will show the default reachable endpoint, with a `+N` control when more endpoints are available. Expand it to inspect alternatives such as loopback, LAN, private-network, or HTTPS endpoints.
58+
5. Use **Create Link** to generate a pairing link you can share with another device.
4859

4960
The default endpoint controls the QR code and primary copy action for pairing links. You can change it from the expanded endpoint list. The preference is stored by endpoint type, so choosing the local LAN endpoint survives normal IP address changes when you move between networks.
5061

0 commit comments

Comments
 (0)