UNPKG

11.1 kBTypeScriptView Raw
1import {
2 Clipboard,
3 CommandRegistry,
4 Config,
5 ContextMenuManager,
6 DeserializerManager,
7 Disposable,
8 GrammarRegistry,
9 HistoryManager,
10 KeymapManager,
11 MenuManager,
12 NotificationManager,
13 PackageManager,
14 Project,
15 StyleManager,
16 TextEditorRegistry,
17 ThemeManager,
18 TooltipManager,
19 ViewRegistry,
20 WindowLoadSettings,
21 Workspace,
22} from "../index";
23
24/**
25 * Atom global for dealing with packages, themes, menus, and the window.
26 * An instance of this class is always available as the atom global.
27 */
28export interface AtomEnvironment {
29 // Properties
30 /** A CommandRegistry instance. */
31 readonly commands: CommandRegistry;
32
33 /** A Config instance. */
34 readonly config: Config;
35
36 /** A Clipboard instance. */
37 readonly clipboard: Clipboard;
38
39 /** A ContextMenuManager instance. */
40 readonly contextMenu: ContextMenuManager;
41
42 /** A MenuManager instance. */
43 readonly menu: MenuManager;
44
45 /** A KeymapManager instance. */
46 readonly keymaps: KeymapManager;
47
48 /** A TooltipManager instance. */
49 readonly tooltips: TooltipManager;
50
51 /** A NotificationManager instance. */
52 readonly notifications: NotificationManager;
53
54 /** A Project instance. */
55 readonly project: Project;
56
57 /** A GrammarRegistry instance. */
58 readonly grammars: GrammarRegistry;
59
60 /** A HistoryManager instance. */
61 readonly history: HistoryManager;
62
63 /** A PackageManager instance. */
64 readonly packages: PackageManager;
65
66 /** A ThemeManager instance. */
67 readonly themes: ThemeManager;
68
69 /** A StyleManager instance. */
70 readonly styles: StyleManager;
71
72 /** A DeserializerManager instance. */
73 readonly deserializers: DeserializerManager;
74
75 /** A ViewRegistry instance. */
76 readonly views: ViewRegistry;
77
78 /** A Workspace instance. */
79 readonly workspace: Workspace;
80
81 /** A TextEditorRegistry instance. */
82 readonly textEditors: TextEditorRegistry;
83
84 // Event Subscription
85 /** Invoke the given callback whenever ::beep is called. */
86 onDidBeep(callback: () => void): Disposable;
87
88 /**
89 * Invoke the given callback when there is an unhandled error, but before
90 * the devtools pop open.
91 */
92 onWillThrowError(callback: (event: PreventableExceptionThrownEvent) => void): Disposable;
93
94 /** Invoke the given callback whenever there is an unhandled error. */
95 onDidThrowError(callback: (event: ExceptionThrownEvent) => void): Disposable;
96
97 /**
98 * Invoke the given callback as soon as the shell environment is loaded (or
99 * immediately if it was already loaded).
100 */
101 whenShellEnvironmentLoaded(callback: () => void): Disposable;
102
103 // Atom Details
104 /** Returns a boolean that is true if the current window is in development mode. */
105 inDevMode(): boolean;
106
107 /** Returns a boolean that is true if the current window is in safe mode. */
108 inSafeMode(): boolean;
109
110 /** Returns a boolean that is true if the current window is running specs. */
111 inSpecMode(): boolean;
112
113 /** Get the full name of this Atom release (e.g. "Atom", "Atom Beta") */
114 getAppName(): string;
115
116 /** Get the version of the Atom application. */
117 getVersion(): string;
118
119 /**
120 * Gets the release channel of the Atom application.
121 * Returns the release channel, which can be 'dev', 'nightly', 'beta', or 'stable'.
122 */
123 getReleaseChannel(): "dev" | "nightly" | "beta" | "stable";
124
125 /** Returns a boolean that is true if the current version is an official release. */
126 isReleasedVersion(): boolean;
127
128 /** Get the time taken to completely load the current window. */
129 getWindowLoadTime(): number;
130
131 /** Get the all the markers with the information about startup time. */
132 getStartupMarkers(): TimingMarker[];
133
134 /** Get the load settings for the current window. */
135 getLoadSettings(): WindowLoadSettings;
136
137 // Managing the Atom Window
138 /** Open a new Atom window using the given options. */
139 open(params?: {
140 pathsToOpen: readonly string[];
141 newWindow?: boolean | undefined;
142 devMode?: boolean | undefined;
143 safeMode?: boolean | undefined;
144 }): void;
145
146 /** Close the current window. */
147 close(): void;
148
149 /** Get the size of current window. */
150 getSize(): { width: number; height: number };
151
152 /** Set the size of current window. */
153 setSize(width: number, height: number): void;
154
155 /** Get the position of current window. */
156 getPosition(): { x: number; y: number };
157
158 /** Set the position of current window. */
159 setPosition(x: number, y: number): void;
160
161 /** Prompt the user to select one or more folders. */
162 pickFolder(callback: (paths: string[] | null) => void): void;
163
164 /** Get the current window. */
165 getCurrentWindow(): object;
166
167 /** Move current window to the center of the screen. */
168 center(): void;
169
170 /** Focus the current window. */
171 focus(): void;
172
173 /** Show the current window. */
174 show(): void;
175
176 /** Hide the current window. */
177 hide(): void;
178
179 /** Reload the current window. */
180 reload(): void;
181
182 /** Relaunch the entire application. */
183 restartApplication(): void;
184
185 /** Returns a boolean that is true if the current window is maximized. */
186 isMaximized(): boolean;
187
188 /** Returns a boolean that is true if the current window is in full screen mode. */
189 isFullScreen(): boolean;
190
191 /** Set the full screen state of the current window. */
192 setFullScreen(fullScreen: boolean): void;
193
194 /** Toggle the full screen state of the current window. */
195 toggleFullScreen(): void;
196
197 /**
198 * Restores the full screen and maximized state after the window has resized to prevent resize
199 * glitches.
200 */
201 displayWindow(): Promise<undefined>;
202
203 /** Get the dimensions of this window. */
204 getWindowDimensions(): { x: number; y: number; width: number; height: number };
205
206 /** Set the dimensions of the window. */
207 setWindowDimensions(
208 dimensions: {
209 x?: number | undefined;
210 y?: number | undefined;
211 width?: number | undefined;
212 height?: number | undefined;
213 },
214 ): Promise<object>;
215
216 // Messaging the User
217 /** Visually and audibly trigger a beep. */
218 beep(): void;
219
220 /**
221 * A flexible way to open a dialog akin to an alert dialog. If a callback
222 * is provided, then the confirmation will work asynchronously, which is
223 * recommended.
224 *
225 * If the dialog is closed (via `Esc` key or `X` in the top corner) without
226 * selecting a button the first button will be clicked unless a "Cancel" or "No"
227 * button is provided.
228 *
229 * Returns the chosen button index number if the buttons option was an array.
230 * @param response The index of the button that was clicked.
231 * @param checkboxChecked The checked state of the checkbox if `checkboxLabel` was set.
232 * Otherwise false.
233 */
234 confirm(options: ConfirmationOptions, callback: (response: number, checkboxChecked: boolean) => void): void;
235
236 /**
237 * A flexible way to open a dialog akin to an alert dialog. If a callback
238 * is provided, then the confirmation will work asynchronously, which is
239 * recommended.
240 *
241 * If the dialog is closed (via `Esc` key or `X` in the top corner) without
242 * selecting a button the first button will be clicked unless a "Cancel" or "No"
243 * button is provided.
244 *
245 * Returns the chosen button index number if the buttons option was an array.
246 */
247 confirm(
248 options: { message: string; detailedMessage?: string | undefined; buttons?: readonly string[] | undefined },
249 ): void;
250
251 /**
252 * A flexible way to open a dialog akin to an alert dialog. If a callback
253 * is provided, then the confirmation will work asynchronously, which is
254 * recommended.
255 *
256 * If the dialog is closed (via `Esc` key or `X` in the top corner) without
257 * selecting a button the first button will be clicked unless a "Cancel" or "No"
258 * button is provided.
259 *
260 * Returns the chosen button index number if the buttons option was an array.
261 */
262 confirm(options: {
263 message: string;
264 detailedMessage?: string | undefined;
265 buttons?: {
266 [key: string]: () => void;
267 } | undefined;
268 }): number;
269
270 // Managing the Dev Tools
271 /** Open the dev tools for the current window. */
272 openDevTools(): Promise<null>;
273
274 /** Toggle the visibility of the dev tools for the current window. */
275 toggleDevTools(): Promise<null>;
276
277 /** Execute code in dev tools. */
278 executeJavaScriptInDevTools(code: string): void;
279
280 /** Undocumented: get Atom config directory path */
281 getConfigDirPath(): string;
282}
283
284export interface ExceptionThrownEvent {
285 originalError: Error;
286 message: string;
287 url: string;
288 line: number;
289 column: number;
290}
291
292export interface PreventableExceptionThrownEvent extends ExceptionThrownEvent {
293 preventDefault(): void;
294}
295
296export interface ConfirmationOptions {
297 /** The type of the confirmation prompt. */
298 type?: "none" | "info" | "error" | "question" | "warning" | undefined;
299
300 /** The text for the buttons. */
301 buttons?: readonly string[] | undefined;
302
303 /** The index for the button to be selected by default in the prompt. */
304 defaultId?: number | undefined;
305
306 /** The title for the prompt. */
307 title?: string | undefined;
308
309 /** The content of the message box. */
310 message?: string | undefined;
311
312 /** Additional information regarding the message. */
313 detail?: string | undefined;
314
315 /** If provided, the message box will include a checkbox with the given label. */
316 checkboxLabel?: string | undefined;
317
318 /** Initial checked state of the checkbox. false by default. */
319 checkboxChecked?: boolean | undefined;
320
321 /** An Electron NativeImage to use as the prompt's icon. */
322 icon?: object | undefined;
323
324 /**
325 * The index of the button to be used to cancel the dialog, via the `Esc` key.
326 * By default this is assigned to the first button with "cancel" or "no" as the
327 * label. If no such labeled buttons exist and this option is not set, 0 will be
328 * used as the return value or callback response.
329 *
330 * This option is ignored on Windows.
331 */
332 cancelId?: number | undefined;
333
334 /**
335 * On Windows, Electron will try to figure out which one of the buttons are
336 * common buttons (like `Cancel` or `Yes`), and show the others as command links
337 * in the dialog. This can make the dialog appear in the style of modern Windows
338 * apps. If you don't like this behavior, you can set noLink to true.
339 */
340 noLink?: boolean | undefined;
341
342 /**
343 * Normalize the keyboard access keys across platforms.
344 * Atom defaults this to true.
345 */
346 normalizeAccessKeys?: boolean | undefined;
347}
348
349export interface TimingMarker {
350 label: string;
351 time: number;
352}