Typescriptify the main process code (6/N)

Summary: Enabled TypeScript compiler checks for "static" folder

Reviewed By: passy

Differential Revision: D20066491

fbshipit-source-id: e797c734718561c63571ca71fc0dc3f0c99cbcbb
This commit is contained in:
Anton Nikolaev
2020-02-24 19:01:37 -08:00
committed by Facebook Github Bot
parent a1260a9789
commit 8e7ca24e72
2 changed files with 39 additions and 37 deletions

View File

@@ -8,7 +8,7 @@
*/ */
const [s, ns] = process.hrtime(); const [s, ns] = process.hrtime();
let launchStartTime = s * 1e3 + ns / 1e6; let launchStartTime: number | undefined = s * 1e3 + ns / 1e6;
import {app, BrowserWindow, ipcMain, Notification} from 'electron'; import {app, BrowserWindow, ipcMain, Notification} from 'electron';
import path from 'path'; import path from 'path';
@@ -19,8 +19,8 @@ import {exec} from 'child_process';
const compilePlugins = require('./compilePlugins'); const compilePlugins = require('./compilePlugins');
import setup from './setup'; import setup from './setup';
const delegateToLauncher = require('./launcher'); const delegateToLauncher = require('./launcher');
const expandTilde = require('expand-tilde'); import expandTilde from 'expand-tilde';
const yargs = require('yargs'); import yargs from 'yargs';
const VERSION: string = (global as any).__VERSION__; const VERSION: string = (global as any).__VERSION__;
@@ -47,28 +47,30 @@ if (process.platform === 'darwin') {
const argv = yargs const argv = yargs
.usage('$0 [args]') .usage('$0 [args]')
.option('file', { .options({
describe: 'Define a file to open on startup.', file: {
type: 'string', describe: 'Define a file to open on startup.',
}) type: 'string',
.option('url', { },
describe: 'Define a flipper:// URL to open on startup.', url: {
type: 'string', describe: 'Define a flipper:// URL to open on startup.',
}) type: 'string',
.option('updater', { },
default: true, updater: {
describe: 'Toggle the built-in update mechanism.', default: true,
type: 'boolean', describe: 'Toggle the built-in update mechanism.',
}) type: 'boolean',
.option('launcher', { },
default: true, launcher: {
describe: 'Toggle delegating to the update launcher on startup.', default: true,
type: 'boolean', describe: 'Toggle delegating to the update launcher on startup.',
}) type: 'boolean',
.option('launcher-msg', { },
describe: 'launcher-msg': {
'[Internal] Used to provide a user message from the launcher to the user.', describe:
type: 'string', '[Internal] Used to provide a user message from the launcher to the user.',
type: 'string',
},
}) })
.version(VERSION) .version(VERSION)
.help() .help()
@@ -78,7 +80,7 @@ const {config, configPath, flipperDir} = setup(argv);
const skipLoadingEmbeddedPlugins = process.env.FLIPPER_NO_EMBEDDED_PLUGINS; const skipLoadingEmbeddedPlugins = process.env.FLIPPER_NO_EMBEDDED_PLUGINS;
const pluginPaths = config.pluginPaths const pluginPaths = (config.pluginPaths ?? [])
.concat([ .concat([
path.join(configPath, '..', 'thirdparty'), path.join(configPath, '..', 'thirdparty'),
...(skipLoadingEmbeddedPlugins ...(skipLoadingEmbeddedPlugins
@@ -100,8 +102,8 @@ process.env.CONFIG = JSON.stringify({
let win: BrowserWindow; let win: BrowserWindow;
let appReady = false; let appReady = false;
let pluginsCompiled = false; let pluginsCompiled = false;
let deeplinkURL: string = argv.url; let deeplinkURL: string | undefined = argv.url;
let filePath: string = argv.file; let filePath: string | undefined = argv.file;
// tracking // tracking
setInterval(() => { setInterval(() => {
@@ -118,7 +120,7 @@ compilePlugins(
}, },
pluginPaths, pluginPaths,
path.join(flipperDir, 'plugins'), path.join(flipperDir, 'plugins'),
).then(dynamicPlugins => { ).then((dynamicPlugins: string[]) => {
ipcMain.on('get-dynamic-plugins', event => { ipcMain.on('get-dynamic-plugins', event => {
event.returnValue = dynamicPlugins; event.returnValue = dynamicPlugins;
}); });
@@ -169,14 +171,14 @@ app.on('will-finish-launching', () => {
argv.file = path; argv.file = path;
if (win) { if (win) {
win.webContents.send('open-flipper-file', filePath); win.webContents.send('open-flipper-file', filePath);
filePath = null; filePath = undefined;
} }
}); });
}); });
app.on('ready', () => { app.on('ready', () => {
// If we delegate to the launcher, shut down this instance of the app. // If we delegate to the launcher, shut down this instance of the app.
delegateToLauncher(argv).then(hasLauncherInvoked => { delegateToLauncher(argv).then((hasLauncherInvoked: boolean) => {
if (hasLauncherInvoked) { if (hasLauncherInvoked) {
app.quit(); app.quit();
return; return;
@@ -200,12 +202,12 @@ app.on('ready', () => {
ipcMain.on('componentDidMount', _event => { ipcMain.on('componentDidMount', _event => {
if (deeplinkURL) { if (deeplinkURL) {
win.webContents.send('flipper-protocol-handler', deeplinkURL); win.webContents.send('flipper-protocol-handler', deeplinkURL);
deeplinkURL = null; deeplinkURL = undefined;
} }
if (filePath) { if (filePath) {
// When flipper app is not running, the windows object might not exist in the callback of `open-file`, but after ``componentDidMount` it will definitely exist. // When flipper app is not running, the windows object might not exist in the callback of `open-file`, but after ``componentDidMount` it will definitely exist.
win.webContents.send('open-flipper-file', filePath); win.webContents.send('open-flipper-file', filePath);
filePath = null; filePath = undefined;
} }
}); });
@@ -214,7 +216,7 @@ ipcMain.on('getLaunchTime', event => {
event.sender.send('getLaunchTime', launchStartTime); event.sender.send('getLaunchTime', launchStartTime);
// set launchTime to null to only report it once, to prevents reporting wrong // set launchTime to null to only report it once, to prevents reporting wrong
// launch times for example after reloading the renderer process // launch times for example after reloading the renderer process
launchStartTime = null; launchStartTime = undefined;
} }
}); });
@@ -258,8 +260,8 @@ function tryCreateWindow() {
win = new BrowserWindow({ win = new BrowserWindow({
show: false, show: false,
title: 'Flipper', title: 'Flipper',
width: config.lastWindowPosition.width || 1400, width: config.lastWindowPosition?.width || 1400,
height: config.lastWindowPosition.height || 1000, height: config.lastWindowPosition?.height || 1000,
minWidth: 800, minWidth: 800,
minHeight: 600, minHeight: 600,
center: true, center: true,

View File

@@ -18,6 +18,6 @@
}, },
"strict": true "strict": true
}, },
"include": ["src/**/*", "types/*", "headless/*"], "include": ["src/**/*", "static/**/*", "types/*", "headless/*"],
"exclude": ["node_modules", "**/*.spec.ts"] "exclude": ["node_modules", "**/*.spec.ts"]
} }