mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-06 17:08:32 +00:00
Use eslint&prettier for code linting&formatting
This commit is contained in:
committed by
Francesco Stasi
parent
2a3873a923
commit
0592199858
@@ -1,5 +1,10 @@
|
||||
import { inject, injectable } from 'inversify';
|
||||
import { app, BrowserWindow, BrowserWindowConstructorOptions, screen } from 'electron';
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
BrowserWindowConstructorOptions,
|
||||
screen,
|
||||
} from 'electron';
|
||||
import { fork } from 'child_process';
|
||||
import { AddressInfo } from 'net';
|
||||
import { join } from 'path';
|
||||
@@ -7,12 +12,14 @@ import { initSplashScreen } from '../splash/splash-screen';
|
||||
import { MaybePromise } from '@theia/core/lib/common/types';
|
||||
import { ElectronSecurityToken } from '@theia/core/lib/electron-common/electron-token';
|
||||
import { FrontendApplicationConfig } from '@theia/application-package/lib/application-props';
|
||||
import { ElectronMainApplication as TheiaElectronMainApplication, TheiaBrowserWindowOptions } from '@theia/core/lib/electron-main/electron-main-application';
|
||||
import {
|
||||
ElectronMainApplication as TheiaElectronMainApplication,
|
||||
TheiaBrowserWindowOptions,
|
||||
} from '@theia/core/lib/electron-main/electron-main-application';
|
||||
import { SplashServiceImpl } from '../splash/splash-service-impl';
|
||||
|
||||
@injectable()
|
||||
export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
|
||||
protected _windows: BrowserWindow[] = [];
|
||||
|
||||
@inject(SplashServiceImpl)
|
||||
@@ -31,17 +38,25 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
*
|
||||
* @param options
|
||||
*/
|
||||
async createWindow(asyncOptions: MaybePromise<TheiaBrowserWindowOptions> = this.getDefaultBrowserWindowOptions()): Promise<BrowserWindow> {
|
||||
async createWindow(
|
||||
asyncOptions: MaybePromise<TheiaBrowserWindowOptions> = this.getDefaultBrowserWindowOptions()
|
||||
): Promise<BrowserWindow> {
|
||||
const options = await asyncOptions;
|
||||
let electronWindow: BrowserWindow | undefined;
|
||||
if (this._windows.length) {
|
||||
electronWindow = new BrowserWindow(options);
|
||||
} else {
|
||||
const { bounds } = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
|
||||
const { bounds } = screen.getDisplayNearestPoint(
|
||||
screen.getCursorScreenPoint()
|
||||
);
|
||||
const splashHeight = 450;
|
||||
const splashWidth = 600;
|
||||
const splashY = Math.floor(bounds.y + (bounds.height - splashHeight) / 2);
|
||||
const splashX = Math.floor(bounds.x + (bounds.width - splashWidth) / 2);
|
||||
const splashY = Math.floor(
|
||||
bounds.y + (bounds.height - splashHeight) / 2
|
||||
);
|
||||
const splashX = Math.floor(
|
||||
bounds.x + (bounds.width - splashWidth) / 2
|
||||
);
|
||||
const splashScreenOpts: BrowserWindowConstructorOptions = {
|
||||
height: splashHeight,
|
||||
width: splashWidth,
|
||||
@@ -53,28 +68,43 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
minimizable: false,
|
||||
maximizable: false,
|
||||
hasShadow: false,
|
||||
resizable: false
|
||||
resizable: false,
|
||||
};
|
||||
electronWindow = initSplashScreen({
|
||||
windowOpts: options,
|
||||
templateUrl: join(__dirname, '..', '..', '..', 'src', 'electron-main', 'splash', 'static', 'splash.html'),
|
||||
delay: 0,
|
||||
minVisible: 2000,
|
||||
splashScreenOpts
|
||||
}, this.splashService.onCloseRequested);
|
||||
electronWindow = initSplashScreen(
|
||||
{
|
||||
windowOpts: options,
|
||||
templateUrl: join(
|
||||
__dirname,
|
||||
'..',
|
||||
'..',
|
||||
'..',
|
||||
'src',
|
||||
'electron-main',
|
||||
'splash',
|
||||
'static',
|
||||
'splash.html'
|
||||
),
|
||||
delay: 0,
|
||||
minVisible: 2000,
|
||||
splashScreenOpts,
|
||||
},
|
||||
this.splashService.onCloseRequested
|
||||
);
|
||||
}
|
||||
this._windows.push(electronWindow);
|
||||
electronWindow.on('closed', () => {
|
||||
if (electronWindow) {
|
||||
const index = this._windows.indexOf(electronWindow);
|
||||
if (index === -1) {
|
||||
console.warn(`Could not dispose browser window: '${electronWindow.title}'.`);
|
||||
console.warn(
|
||||
`Could not dispose browser window: '${electronWindow.title}'.`
|
||||
);
|
||||
} else {
|
||||
this._windows.splice(index, 1);
|
||||
electronWindow = undefined;
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
this.attachReadyToShow(electronWindow);
|
||||
this.attachSaveWindowState(electronWindow);
|
||||
this.attachGlobalShortcuts(electronWindow);
|
||||
@@ -88,14 +118,18 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
// We cannot use the `process.cwd()` as the application project path (the location of the `package.json` in other words)
|
||||
// in a bundled electron application because it depends on the way we start it. For instance, on OS X, these are a differences:
|
||||
// https://github.com/eclipse-theia/theia/issues/3297#issuecomment-439172274
|
||||
process.env.THEIA_APP_PROJECT_PATH = this.globals.THEIA_APP_PROJECT_PATH;
|
||||
process.env.THEIA_APP_PROJECT_PATH =
|
||||
this.globals.THEIA_APP_PROJECT_PATH;
|
||||
// Set the electron version for both the dev and the production mode. (https://github.com/eclipse-theia/theia/issues/3254)
|
||||
// Otherwise, the forked backend processes will not know that they're serving the electron frontend.
|
||||
process.env.THEIA_ELECTRON_VERSION = process.versions.electron;
|
||||
if (noBackendFork) {
|
||||
process.env[ElectronSecurityToken] = JSON.stringify(this.electronSecurityToken);
|
||||
process.env[ElectronSecurityToken] = JSON.stringify(
|
||||
this.electronSecurityToken
|
||||
);
|
||||
// The backend server main file is supposed to export a promise resolving with the port used by the http(s) server.
|
||||
const address: AddressInfo = await require(this.globals.THEIA_BACKEND_MAIN_PATH);
|
||||
const address: AddressInfo = await require(this.globals
|
||||
.THEIA_BACKEND_MAIN_PATH);
|
||||
return address.port;
|
||||
} else {
|
||||
let args = this.processArgv.getProcessArgvWithoutBin();
|
||||
@@ -105,12 +139,12 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
// https://stackoverflow.com/questions/10242115/os-x-strange-psn-command-line-parameter-when-launched-from-finder#comment102377986_10242200
|
||||
// macOS appends an extra `-psn_0_someNumber` arg if a file is opened from Finder after downloading from the Internet.
|
||||
// "AppName" is an app downloaded from the Internet. Are you sure you want to open it?
|
||||
args = args.filter(arg => !arg.startsWith('-psn'));
|
||||
args = args.filter((arg) => !arg.startsWith('-psn'));
|
||||
}
|
||||
const backendProcess = fork(
|
||||
this.globals.THEIA_BACKEND_MAIN_PATH,
|
||||
args,
|
||||
await this.getForkOptions(),
|
||||
await this.getForkOptions()
|
||||
);
|
||||
console.log(`Starting backend process. PID: ${backendProcess.pid}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -118,7 +152,7 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
backendProcess.on('message', (address: AddressInfo) => {
|
||||
resolve(address.port);
|
||||
});
|
||||
backendProcess.on('error', error => {
|
||||
backendProcess.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
app.on('quit', () => {
|
||||
@@ -128,7 +162,9 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
process.kill(backendProcess.pid);
|
||||
} catch (e) {
|
||||
if (e.code === 'ESRCH') {
|
||||
console.log('Could not terminate the backend process. It was not running.');
|
||||
console.log(
|
||||
'Could not terminate the backend process. It was not running.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
@@ -141,5 +177,4 @@ export class ElectronMainApplication extends TheiaElectronMainApplication {
|
||||
get windows(): BrowserWindow[] {
|
||||
return this._windows.slice();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user