Open History to see the last commit
1import * as Effect from "effect/Effect";
2
3import { receiveProviderAuthCallback, cancelProviderAuthCallback } from "./methods/providerAuth.ts";
4import * as DesktopIpc from "./DesktopIpc.ts";
5import * as DesktopShellEnvironment from "../shell/DesktopShellEnvironment.ts";
6import { installNotificationBadge } from "./methods/notificationBadge.ts";
7import { getClientSettings, setClientSettings } from "./methods/clientSettings.ts";
8import {
9 clearConnectionCatalog,
10 getConnectionCatalog,
11 setConnectionCatalog,
12} from "./methods/connectionCatalog.ts";
13import {
14 getLocalEnvironmentEnabled,
15 setLocalEnvironmentEnabled,
16} from "./methods/localEnvironment.ts";
17import {
18 getAdvertisedEndpoints,
19 getServerExposureState,
20 setServerExposureMode,
21 setTailscaleServeEnabled,
22} from "./methods/serverExposure.ts";
23import {
24 bootstrapSshBearerSession,
25 disconnectSshEnvironment,
26 discoverSshHosts,
27 ensureSshEnvironment,
28 fetchSshEnvironmentDescriptor,
29 fetchSshSessionState,
30 issueSshWebSocketTicket,
31 resolveSshHost,
32 resolveSshPasswordPrompt,
33} from "./methods/sshEnvironment.ts";
34import {
35 checkForUpdate,
36 downloadUpdate,
37 getUpdateState,
38 installUpdate,
39 setUpdateChannel,
40} from "./methods/updates.ts";
41import {
42 getAppBranding,
43 getLocalEnvironmentBootstraps,
44 getLocalEnvironmentBearerToken,
45 getSystemLocale,
46 getWindowFullscreenState,
47 openExternal,
48 openSystemSettings,
49 checkSystemPermission,
50 pasteAsText,
51 probeRemoteEditors,
52 pickFolder,
53 pickProjectFavicon,
54 pickThemeFiles,
55 setTheme,
56 showContextMenu,
57} from "./methods/window.ts";
58import {
59 acknowledgeSnapShot,
60 checkSnapShotShortcut,
61 dismissSnapShotAnimation,
62 getSnapShotState,
63 setupSnapShot,
64 previewSnapShotConfig,
65 applySnapShotConfig,
66 listPendingSnapShots,
67 readSnapShot,
68 requestSnapShotPermissions,
69 setSnapShotAnimationDestination,
70 setSnapShotShortcutSuppressed,
71} from "./methods/snapShot.ts";
72import * as PreviewIpc from "./methods/preview.ts";
73import * as AppActivationIpc from "./methods/appActivation.ts";
74import * as WebLinksIpc from "./methods/webLinks.ts";
75import {
76 completeLegacyLocalStorage,
77 takeLegacyLocalStorage,
78} from "./methods/legacyLocalStorage.ts";
79import { getWslState, setWslBackendEnabled, setWslDistro, setWslOnly } from "./methods/wsl.ts";
80import {
81 getCliCommandState,
82 installCliCommand,
83 uninstallCliCommand,
84} from "./methods/cliCommand.ts";
85
86export const installDesktopIpcHandlers = Effect.fn("desktop.ipc.installHandlers")(function* () {
87 const desktopIpc = yield* DesktopIpc.DesktopIpc;
88 const shellEnvironment = yield* DesktopShellEnvironment.DesktopShellEnvironment;
89 // Process-spawning handlers need the login environment before they run.
90 const ipc = {
91 handle: <E, R>(method: DesktopIpc.DesktopIpcMethod<E, R>) =>
92 desktopIpc.handle({
93 channel: method.channel,
94 handler: (raw, event) =>
95 shellEnvironment.installIntoProcess.pipe(
96 Effect.andThen(() => method.handler(raw, event)),
97 ),
98 }),
99 // For handlers that spawn nothing and read no login shell variables.
100 handleWithoutShell: desktopIpc.handle,
101 // For handlers that use safeStorage, which can need the shell's session bus.
102 handleSecretStorage: <E, R>(method: DesktopIpc.DesktopIpcMethod<E, R>) =>
103 desktopIpc.handle({
104 channel: method.channel,
105 handler: (raw, event) =>
106 shellEnvironment.secretStorageReady.pipe(
107 Effect.andThen(() => method.handler(raw, event)),
108 ),
109 }),
110 handleSync: desktopIpc.handleSync,
111 };
112 yield* installNotificationBadge();
113 yield* PreviewIpc.installPreviewEventForwarding();
114
115 yield* ipc.handle(AppActivationIpc.setReady);
116 yield* ipc.handle(AppActivationIpc.complete);
117 yield* ipc.handle(WebLinksIpc.setReady);
118
119 yield* ipc.handleSync(takeLegacyLocalStorage);
120 yield* ipc.handle(completeLegacyLocalStorage);
121 yield* ipc.handleSync(getAppBranding);
122 yield* ipc.handleSync(getSystemLocale);
123 yield* ipc.handleSync(getWindowFullscreenState);
124 yield* ipc.handleSync(getLocalEnvironmentBootstraps);
125 yield* ipc.handleSync(getLocalEnvironmentEnabled);
126 yield* ipc.handle(setLocalEnvironmentEnabled);
127 yield* ipc.handleWithoutShell(getLocalEnvironmentBearerToken);
128
129 yield* ipc.handleWithoutShell(getClientSettings);
130 yield* ipc.handleWithoutShell(setClientSettings);
131 yield* ipc.handleSecretStorage(getConnectionCatalog);
132 yield* ipc.handle(getSnapShotState);
133 yield* ipc.handle(setupSnapShot);
134 yield* ipc.handle(previewSnapShotConfig);
135 yield* ipc.handle(applySnapShotConfig);
136 yield* ipc.handle(requestSnapShotPermissions);
137 yield* ipc.handle(checkSnapShotShortcut);
138 yield* ipc.handle(setSnapShotShortcutSuppressed);
139 yield* ipc.handle(listPendingSnapShots);
140 yield* ipc.handle(readSnapShot);
141 yield* ipc.handle(setSnapShotAnimationDestination);
142 yield* ipc.handle(dismissSnapShotAnimation);
143 yield* ipc.handle(acknowledgeSnapShot);
144 yield* ipc.handleSecretStorage(setConnectionCatalog);
145 yield* ipc.handleSecretStorage(clearConnectionCatalog);
146
147 yield* ipc.handle(discoverSshHosts);
148 yield* ipc.handle(resolveSshHost);
149 yield* ipc.handle(ensureSshEnvironment);
150 yield* ipc.handle(disconnectSshEnvironment);
151 yield* ipc.handle(fetchSshEnvironmentDescriptor);
152 yield* ipc.handle(bootstrapSshBearerSession);
153 yield* ipc.handle(fetchSshSessionState);
154 yield* ipc.handle(issueSshWebSocketTicket);
155 yield* ipc.handle(resolveSshPasswordPrompt);
156
157 yield* ipc.handle(getServerExposureState);
158 yield* ipc.handle(setServerExposureMode);
159 yield* ipc.handle(setTailscaleServeEnabled);
160 yield* ipc.handle(getAdvertisedEndpoints);
161
162 yield* ipc.handle(getWslState);
163 yield* ipc.handle(setWslBackendEnabled);
164 yield* ipc.handle(setWslDistro);
165 yield* ipc.handle(setWslOnly);
166
167 yield* ipc.handle(pickFolder);
168 yield* ipc.handle(pickProjectFavicon);
169 yield* ipc.handle(pickThemeFiles);
170 yield* ipc.handleWithoutShell(setTheme);
171 yield* ipc.handleWithoutShell(showContextMenu);
172 yield* ipc.handle(openExternal);
173 yield* ipc.handle(receiveProviderAuthCallback);
174 yield* ipc.handle(cancelProviderAuthCallback);
175 yield* ipc.handle(openSystemSettings);
176 yield* ipc.handle(checkSystemPermission);
177 yield* ipc.handle(pasteAsText);
178 yield* ipc.handle(probeRemoteEditors);
179 yield* ipc.handle(getUpdateState);
180 yield* ipc.handle(setUpdateChannel);
181 yield* ipc.handle(downloadUpdate);
182 yield* ipc.handle(installUpdate);
183 yield* ipc.handle(checkForUpdate);
184 yield* ipc.handle(getCliCommandState);
185 yield* ipc.handle(installCliCommand);
186 yield* ipc.handle(uninstallCliCommand);
187 for (const previewMethod of PreviewIpc.methods) {
188 yield* ipc.handle(previewMethod);
189 }
190 yield* ipc.handle(PreviewIpc.listBrowserImportSources);
191 yield* ipc.handle(PreviewIpc.importBrowserCookies);
192});