Typescript:

Add code documentation
Add pre-commit hooks
This commit is contained in:
Kiran Niranjan 2018-10-29 10:49:56 +05:30
parent eb829e2c68
commit feac64ea62
5 changed files with 84 additions and 1 deletions

View File

@ -4,6 +4,9 @@ import { isDevEnv } from '../common/env';
import { getCommandLineArgs } from '../common/utils';
import { config, IConfig } from './config-handler';
/**
* Sets chrome flags
*/
export default function setChromeFlags() {
const { customFlags } = config.getGlobalConfigFields([ 'customFlags' ]) as IConfig;

View File

@ -126,6 +126,10 @@ class Config {
fs.writeFileSync(this.userConfigPath, JSON.stringify(this.userConfig), { encoding: 'utf8' });
}
/**
* Return true if the app is launched for the first time
* otherwise false
*/
public isFirstTimeLaunch(): boolean {
return this.isFirstTime;
}

View File

@ -2,7 +2,7 @@ import { app } from 'electron';
import { isDevEnv } from '../common/env';
import { logger } from '../common/logger';
import {getCommandLineArgs} from '../common/utils';
import { getCommandLineArgs } from '../common/utils';
import { cleanUpAppCache, createAppCacheFile } from './app-cache-handler';
import { autoLaunchInstance } from './auto-launch-controller';
import setChromeFlags from './chrome-flags';
@ -18,6 +18,9 @@ if (!singleInstanceLock) {
main();
}
/**
* Main function that init the application
*/
async function main() {
await app.whenReady();
createAppCacheFile();

View File

@ -7,6 +7,9 @@ import { config, IConfig } from './config-handler';
export class WindowHandler {
/**
* Main window opts
*/
private static getMainWindowOpts() {
return {
alwaysOnTop: false,
@ -24,6 +27,9 @@ export class WindowHandler {
};
}
/**
* Loading window opts
*/
private static getLoadingWindowOpts() {
return {
alwaysOnTop: false,
@ -39,6 +45,12 @@ export class WindowHandler {
};
}
/**
* Verifies if the url is valid and
* forcefully appends https if not present
*
* @param configURL {string}
*/
private static validateURL(configURL: string): string {
const parsedUrl = url.parse(configURL);
@ -68,6 +80,9 @@ export class WindowHandler {
}
}
/**
* Starting point of the app
*/
public createApplication() {
this.mainWindow = new BrowserWindow(this.windowOpts);
@ -83,6 +98,9 @@ export class WindowHandler {
return this.mainWindow;
}
/**
* Gets the main window
*/
public getMainWindow(): Electron.BrowserWindow | null {
return this.mainWindow;
}

View File

@ -53,30 +53,71 @@ export class Logger {
}
}
/**
* Log error
*
* @param message {string} - message to be logged
* @param data {object} - extra data that needs to be logged
*/
public error(message: string, data?: object): void {
this.log('error', message, data);
}
/**
* Log warn
*
* @param message {string} - message to be logged
* @param data {object} - extra data that needs to be logged
*/
public warn(message: string, data?: object): void {
this.log('warn', message, data);
}
/**
* Log info
*
* @param message {string} - message to be logged
* @param data {object} - extra data that needs to be logged
*/
public info(message: string, data?: object): void {
this.log('info', message, data);
}
/**
* Log verbose
*
* @param message {string} - message to be logged
* @param data {object} - extra data that needs to be logged
*/
public verbose(message: string, data?: object): void {
this.log('verbose', message, data);
}
/**
* Log debug
*
* @param message {string} - message to be logged
* @param data {object} - extra data that needs to be logged
*/
public debug(message: string, data?: object): void {
this.log('debug', message, data);
}
/**
* Log silly
*
* @param message {string} - message to be logged
* @param data {object} - extra data that needs to be logged
*/
public silly(message: string, data?: object): void {
this.log('silly', message, data);
}
/**
* Sets the renderer window for sending logs to the client
*
* @param window {WebContents} - renderer window
*/
public setLoggerWindow(window: Electron.WebContents): void {
this.loggerWindow = window;
@ -88,6 +129,13 @@ export class Logger {
}
}
/**
* Main instance of the logger method
*
* @param logLevel {LogLevel} - Different type of log levels
* @param message {string} - Log message
* @param data {object} - extra data to be logged
*/
private log(logLevel: LogLevel, message: string, data?: object): void {
message = formatString(message, data);
if (!isElectronQA) {
@ -104,6 +152,13 @@ export class Logger {
this.sendToCloud(this.formatLogMsg(logLevel, message));
}
/**
* Formats the logs in the format that required
* to send to the client
*
* @param level {LogLevel} - Different type of log levels
* @param details {any} - log format that required to send to client
*/
private formatLogMsg(level: LogLevel, details: any): ILogMsg {
return {
details,