-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathenv.d.ts
212 lines (186 loc) · 6.37 KB
/
env.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
* @file Globals defined outside of TypeScript files.
* These are from variables defined at build time, environment variables,
* monkeypatching on `window` and generated code.
*/
/// <reference types="vite/client" />
import type * as saveAccessToken from 'enso-common/src/accessToken'
import type { $Config } from './src/config'
// =============
// === Types ===
// =============
/** Nested configuration options with `string` values. */
interface StringConfig {
[key: string]: StringConfig | string
}
/** The public interface exposed to `window` by the IDE. */
interface Enso {
readonly main: (inputConfig?: StringConfig) => Promise<void>
}
// ===================
// === Backend API ===
// ===================
/**
* `window.backendApi` is a context bridge to the main process, when we're running in an
* Electron context. It contains non-authentication-related functionality.
*/
interface BackendApi {
/** Return the ID of the new project. */
readonly importProjectFromPath: (
openedPath: string,
directory: string | null,
name: string,
) => Promise<ProjectInfo>
}
// ==========================
// === Authentication API ===
// ==========================
/**
* `window.authenticationApi` is a context bridge to the main process, when we're running in an
* Electron context.
*
* # Safety
*
* We're assuming that the main process has exposed the `authenticationApi` context bridge (see
* `lib/client/src/preload.ts` for details), and that it contains the functions defined in this
* interface. Our app can't function if these assumptions are not met, so we're disabling the
* TypeScript checks for this interface when we use it.
*/
interface AuthenticationApi {
/** Open a URL in the system browser. */
readonly openUrlInSystemBrowser: (url: string) => void
/**
* Set the callback to be called when the system browser redirects back to a URL in the app,
* via a deep link. See `setDeepLinkHandler` for details.
*/
readonly setDeepLinkHandler: (callback: (url: string) => void) => void
/** Saves the access token to a file. */
readonly saveAccessToken: (accessToken: saveAccessToken.AccessToken | null) => void
}
// ======================
// === Navigation API ===
// ======================
/**
* `window.navigationApi` is a context bridge to the main process, when we're running in an
* Electron context. It contains navigation-related functionality.
*/
interface NavigationApi {
/** Go back in the navigation history. */
readonly goBack: () => void
/** Go forward in the navigation history. */
readonly goForward: () => void
}
// ================
// === Menu API ===
// ================
/** `window.menuApi` exposes functionality related to the system menu. */
interface MenuApi {
/** Set the callback to be called when the "about" entry is clicked in the "help" menu. */
readonly setShowAboutModalHandler: (callback: () => void) => void
}
// ==================
// === System API ===
// ==================
/** `window.systemApi` exposes functionality related to the operating system. */
interface SystemApi {
readonly downloadURL: (url: string, headers?: Record<string, string>) => void
readonly showItemInFolder: (fullPath: string) => void
}
// ==============================
// === Project Management API ===
// ==============================
/** Metadata for a newly imported project. */
interface ProjectInfo {
readonly id: string
readonly name: string
readonly parentDirectory: string
}
/**
* `window.projectManagementApi` exposes functionality related to system events related to
* project management.
*/
interface ProjectManagementApi {
readonly setOpenProjectHandler: (handler: (projectInfo: ProjectInfo) => void) => void
}
// ========================
// === File Browser API ===
// ========================
/**
* `window.fileBrowserApi` is a context bridge to the main process, when we're running in an
* Electron context.
*
* # Safety
*
* We're assuming that the main process has exposed the `fileBrowserApi` context bridge (see
* `app/client/src/preload.ts` for details), and that it contains the functions defined in this
* interface.
*/
interface FileBrowserApi {
/**
* Select path for local file or directory using the system file browser.
* 'filePath' is same as 'file', but allows picking non-existing files.
*/
readonly openFileBrowser: (
kind: 'default' | 'directory' | 'file' | 'filePath',
defaultPath?: string,
) => Promise<string[] | undefined>
}
// ====================
// === Version Info ===
// ====================
/** Versions of the app, and selected software bundled with Electron. */
interface VersionInfo {
readonly version: string
readonly build: string
readonly electron: string
readonly chrome: string
}
// =====================================
// === Global namespace augmentation ===
// =====================================
// JSDocs here are intentionally empty as these interfaces originate from elsewhere.
declare global {
const $config: $Config
interface Window {
readonly backendApi?: BackendApi
readonly authenticationApi: AuthenticationApi
readonly navigationApi: NavigationApi
readonly menuApi: MenuApi
readonly systemApi?: SystemApi
readonly projectManagementApi?: ProjectManagementApi
readonly fileBrowserApi?: FileBrowserApi
readonly versionInfo?: VersionInfo
readonly mapBoxApiToken?: () => string
toggleDevtools: () => void
/**
* If set to `true`, animations will be disabled.
* Used by playwright tests to speed up execution.
*
* ATM only affects the framer-motion animations.
*/
readonly DISABLE_ANIMATIONS?: boolean
readonly featureFlags: FeatureFlags
readonly setFeatureFlags: (flags: Partial<FeatureFlags>) => void
/**
* Feature flags that override the default or stored feature flags.
* This is used by integration tests to set feature flags.
*/
readonly overrideFeatureFlags: Partial<FeatureFlags>
}
interface Document {
caretPositionFromPoint(x: number, y: number): { offsetNode: Node; offset: number } | null
}
interface LogEvent {
(message: string, projectId?: string | null, metadata?: object | null): void
}
}
// Add additional types for svg imports from `#/assets/*.svg`
declare module 'vite/client' {
declare module '#/assets/*.svg' {
/**
* @deprecated Prefer defined keys over importing from `#/assets/*.svg
*/
const src: string
export default src
}
}