Skip to content

Commit bc554b6

Browse files
author
Alberto Iannaccone
committed
format document
1 parent 241fd2b commit bc554b6

File tree

1 file changed

+48
-24
lines changed

1 file changed

+48
-24
lines changed

Diff for: arduino-ide-extension/src/electron-main/theia/electron-main-application.ts

+48-24
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ import { TheiaBrowserWindowOptions } from '@theia/core/lib/electron-main/theia-e
3030
app.commandLine.appendSwitch('disable-http-cache');
3131

3232
interface WorkspaceOptions {
33-
file: string
34-
x: number
35-
y: number
36-
width: number
37-
height: number
38-
isMaximized: boolean
39-
isFullScreen: boolean
40-
time: number
33+
file: string;
34+
x: number;
35+
y: number;
36+
width: number;
37+
height: number;
38+
isMaximized: boolean;
39+
isFullScreen: boolean;
40+
time: number;
4141
}
4242

4343
const WORKSPACES = 'workspaces';
@@ -147,7 +147,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
147147
if (os.isOSX) {
148148
app.on('open-file', async (event, uri) => {
149149
event.preventDefault();
150-
if (uri.endsWith('.ino') && await fs.pathExists(uri)) {
150+
if (uri.endsWith('.ino') && (await fs.pathExists(uri))) {
151151
this.openFilePromise.reject();
152152
await this.openSketch(dirname(uri));
153153
}
@@ -159,10 +159,12 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
159159
}
160160

161161
protected async isValidSketchPath(uri: string): Promise<boolean | undefined> {
162-
return typeof uri === 'string' && await fs.pathExists(uri);
162+
return typeof uri === 'string' && (await fs.pathExists(uri));
163163
}
164164

165-
protected override async launch(params: ElectronMainExecutionParams): Promise<void> {
165+
protected override async launch(
166+
params: ElectronMainExecutionParams
167+
): Promise<void> {
166168
try {
167169
// When running on MacOS, we either have to wait until
168170
// 1. The `open-file` command has been received by the app, rejecting the promise
@@ -173,13 +175,14 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
173175
return;
174176
}
175177

176-
if (!os.isOSX && await this.launchFromArgs(params)) {
178+
if (!os.isOSX && (await this.launchFromArgs(params))) {
177179
// Application has received a file in its arguments and will skip the default application launch
178180
return;
179181
}
180182

181183
this.startup = true;
182-
const workspaces: WorkspaceOptions[] | undefined = this.electronStore.get(WORKSPACES);
184+
const workspaces: WorkspaceOptions[] | undefined =
185+
this.electronStore.get(WORKSPACES);
183186
let useDefault = true;
184187
if (workspaces && workspaces.length > 0) {
185188
console.log(
@@ -198,12 +201,17 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
198201
}
199202
}
200203

201-
protected async launchFromArgs(params: ElectronMainExecutionParams): Promise<boolean> {
204+
protected async launchFromArgs(
205+
params: ElectronMainExecutionParams
206+
): Promise<boolean> {
202207
// Copy to prevent manipulation of original array
203208
const argCopy = [...params.argv];
204209
let uri: string | undefined;
205210
for (const possibleUri of argCopy) {
206-
if (possibleUri.endsWith('.ino') && await this.isValidSketchPath(possibleUri)) {
211+
if (
212+
possibleUri.endsWith('.ino') &&
213+
(await this.isValidSketchPath(possibleUri))
214+
) {
207215
uri = possibleUri;
208216
break;
209217
}
@@ -215,7 +223,9 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
215223
return false;
216224
}
217225

218-
protected async openSketch(workspace: WorkspaceOptions | string): Promise<BrowserWindow> {
226+
protected async openSketch(
227+
workspace: WorkspaceOptions | string
228+
): Promise<BrowserWindow> {
219229
const options = await this.getLastWindowOptions();
220230
let file: string;
221231
if (typeof workspace === 'object') {
@@ -229,19 +239,26 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
229239
} else {
230240
file = workspace;
231241
}
232-
const [uri, electronWindow] = await Promise.all([this.createWindowUri(), this.createWindow(options)]);
242+
const [uri, electronWindow] = await Promise.all([
243+
this.createWindowUri(),
244+
this.createWindow(options),
245+
]);
233246
electronWindow.loadURL(uri.withFragment(encodeURI(file)).toString(true));
234247
return electronWindow;
235248
}
236249

237-
protected override avoidOverlap(options: TheiaBrowserWindowOptions): TheiaBrowserWindowOptions {
250+
protected override avoidOverlap(
251+
options: TheiaBrowserWindowOptions
252+
): TheiaBrowserWindowOptions {
238253
if (this.startup) {
239254
return options;
240255
}
241256
return super.avoidOverlap(options);
242257
}
243258

244-
protected override getTitleBarStyle(config: FrontendApplicationConfig): 'native' | 'custom' {
259+
protected override getTitleBarStyle(
260+
config: FrontendApplicationConfig
261+
): 'native' | 'custom' {
245262
return 'native';
246263
}
247264

@@ -255,8 +272,15 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
255272
});
256273
}
257274

258-
protected override async onSecondInstance(event: ElectronEvent, argv: string[], cwd: string): Promise<void> {
259-
if (!os.isOSX && await this.launchFromArgs({ cwd, argv, secondInstance: true })) {
275+
protected override async onSecondInstance(
276+
event: ElectronEvent,
277+
argv: string[],
278+
cwd: string
279+
): Promise<void> {
280+
if (
281+
!os.isOSX &&
282+
(await this.launchFromArgs({ cwd, argv, secondInstance: true }))
283+
) {
260284
// Application has received a file in its arguments
261285
return;
262286
}
@@ -268,7 +292,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
268292
*
269293
* @param options
270294
*/
271-
override async createWindow(
295+
override async createWindow(
272296
asyncOptions: MaybePromise<TheiaBrowserWindowOptions> = this.getDefaultTheiaWindowOptions()
273297
): Promise<BrowserWindow> {
274298
let options = await asyncOptions;
@@ -459,8 +483,8 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
459483
isMaximized: window.isMaximized(),
460484
isFullScreen: window.isFullScreen(),
461485
file: workspaceUri.fsPath,
462-
time: now
463-
})
486+
time: now,
487+
});
464488
}
465489
});
466490
}

0 commit comments

Comments
 (0)