From 4a7fe58fba40464dfab2e2e6463b178cb837d9ee Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Thu, 16 May 2019 19:00:00 +0530 Subject: [PATCH] add more logging to all the source files --- src/app/chrome-flags.ts | 73 +++++++++++++++++-------------- src/app/config-handler.ts | 19 +++++++- src/app/main.ts | 39 ++++++++++------- src/app/memory-monitor.ts | 9 ++-- src/app/protocol-handler.ts | 19 +++++--- src/app/reports-handler.ts | 10 ++++- src/app/screen-snippet-handler.ts | 15 +++++-- src/app/spell-check-handler.ts | 3 ++ src/app/window-actions.ts | 4 +- src/app/window-handler.ts | 22 +++++++++- src/app/window-utils.ts | 16 +++++-- src/common/animation-queue.ts | 2 +- src/common/whitelist-handler.ts | 2 +- 13 files changed, 159 insertions(+), 74 deletions(-) diff --git a/src/app/chrome-flags.ts b/src/app/chrome-flags.ts index 79ba61c5..563da14c 100644 --- a/src/app/chrome-flags.ts +++ b/src/app/chrome-flags.ts @@ -1,6 +1,5 @@ import { app } from 'electron'; - -import { isDevEnv } from '../common/env'; +import { logger } from '../common/logger'; import { getCommandLineArgs } from '../common/utils'; import { config, IConfig } from './config-handler'; @@ -8,6 +7,7 @@ import { config, IConfig } from './config-handler'; * Sets chrome flags */ export const setChromeFlags = () => { + logger.info(`chrome-flags: Checking if we need to set chrome flags!`); const { customFlags } = config.getGlobalConfigFields([ 'customFlags' ]) as IConfig; const configFlags: object = { @@ -23,44 +23,51 @@ export const setChromeFlags = () => { if (!Object.prototype.hasOwnProperty.call(configFlags, key)) { continue; } - if (key && configFlags[key]) { - app.commandLine.appendSwitch(key, configFlags[key]); + const val = configFlags[key]; + if (key && val) { + logger.info(`chrome-flags: Setting chrome flag for ${key} with value ${val}!`); + app.commandLine.appendSwitch(key, val); } } - if (isDevEnv) { - const chromeFlagsFromCmd = getCommandLineArgs(process.argv, '--chrome-flags=', false); - if (!chromeFlagsFromCmd) { + logger.info(`chrome-flags: Checking to see if we have any flags passsed from command line!`); + const chromeFlagsFromCmd = getCommandLineArgs(process.argv, '--chrome-flags=', false); + if (!chromeFlagsFromCmd) { + logger.info(`chrome-flags: No flags passed from command line, returning`); + return; + } + + const chromeFlagsArgs = chromeFlagsFromCmd.substr(15); + logger.info(`chrome-flags: Command line args passed as ${chromeFlagsArgs}`); + if (!chromeFlagsArgs) { + logger.info(`chrome-flags: Not a valid set of args passed through command line for setting chrome flags, returning`); + return; + } + + const flags = chromeFlagsArgs.split(','); + logger.info(`chrome-flags: Flags we have are ${flags}`); + if (!flags || !Array.isArray(flags)) { + logger.info(`chrome-flags: Empty set of flags passed! returning`); + return; + } + + for (const key in flags) { + + if (!Object.prototype.hasOwnProperty.call(flags, key)) { + continue; + } + + if (!flags[key]) { return; } - const chromeFlagsArgs = chromeFlagsFromCmd.substr(15); - if (!chromeFlagsArgs) { - return; - } + const flagArray = flags[key].split(':'); - const flags = chromeFlagsArgs.split(','); - if (!flags || !Array.isArray(flags)) { - return; - } - - for (const key in flags) { - - if (!Object.prototype.hasOwnProperty.call(flags, key)) { - continue; - } - - if (!flags[key]) { - return; - } - - const flagArray = flags[key].split(':'); - - if (flagArray && Array.isArray(flagArray) && flagArray.length > 0) { - const chromeFlagKey = flagArray[0]; - const chromeFlagValue = flagArray[1]; - app.commandLine.appendSwitch(chromeFlagKey, chromeFlagValue); - } + if (flagArray && Array.isArray(flagArray) && flagArray.length > 0) { + const chromeFlagKey = flagArray[0]; + const chromeFlagValue = flagArray[1]; + logger.info(`chrome-flags: Setting chrome flag from command line for key ${chromeFlagKey} and value ${chromeFlagValue}`); + app.commandLine.appendSwitch(chromeFlagKey, chromeFlagValue); } } }; diff --git a/src/app/config-handler.ts b/src/app/config-handler.ts index 17605793..c1aed928 100644 --- a/src/app/config-handler.ts +++ b/src/app/config-handler.ts @@ -106,6 +106,7 @@ class Config { * @param fields */ public getConfigFields(fields: string[]): IConfig { + logger.info(`config-handler: Trying to get config values for the fields ${fields}`); return { ...this.getGlobalConfigFields(fields), ...this.getUserConfigFields(fields) } as IConfig; } @@ -115,6 +116,7 @@ class Config { * @param fields {Array} */ public getUserConfigFields(fields: string[]): IConfig { + logger.info(`config-handler: Trying to get user config values for the fields ${fields}`); return pick(this.userConfig, fields) as IConfig; } @@ -124,6 +126,7 @@ class Config { * @param fields {Array} */ public getGlobalConfigFields(fields: string[]): IConfig { + logger.info(`config-handler: Trying to get global config values for the fields ${fields}`); return pick(this.globalConfig, fields) as IConfig; } @@ -133,12 +136,14 @@ class Config { * @param data {IConfig} */ public async updateUserConfig(data: Partial): Promise { + logger.info(`config-handler: updating user config values with the data ${data}`); this.userConfig = { ...this.userConfig, ...data }; try { await writeFile(this.userConfigPath, JSON.stringify(this.userConfig), { encoding: 'utf8' }); + logger.info(`config-handler: updated user config values with the data ${data}`); } catch (error) { logger.error(`config-handler: failed to update user config file with ${data}`, error); - dialog.showErrorBox('Error updating user config file', 'failed to write user config file with ${}'); + dialog.showErrorBox(`Update failed`, `Failed to update user config due to error: ${error}`); } } @@ -161,6 +166,7 @@ class Config { const filteredFields: IConfig = omit(this.userConfig, ignoreSettings) as IConfig; // update to the new build number filteredFields.buildNumber = buildNumber; + logger.info(`config-handler: setting first time launch for build ${buildNumber}`); return await this.updateUserConfig(filteredFields); } } @@ -173,11 +179,14 @@ class Config { private parseConfigData(data: string): object { let parsedData; if (!data) { + logger.error(`config-handler: unable to read config file`); throw new Error('unable to read user config file'); } try { parsedData = JSON.parse(data); + logger.info(`config-handler: parsed JSON file with data ${JSON.stringify(parsedData)}`); } catch (e) { + logger.error(`config-handler: parsing JSON file failed due to error ${e}`); throw new Error(e); } return parsedData; @@ -191,9 +200,11 @@ class Config { */ private async readUserConfig() { if (!fs.existsSync(this.userConfigPath)) { + logger.info(`config-handler: user config doesn't exist! will create new one and update config`); await this.updateUserConfig({ configVersion: app.getVersion().toString(), buildNumber } as IConfig); } this.userConfig = this.parseConfigData(fs.readFileSync(this.userConfigPath, 'utf8')); + logger.info(`config-handler: user config exists with data ${JSON.stringify(this.userConfig)}`); } /** @@ -201,24 +212,28 @@ class Config { */ private readGlobalConfig() { this.globalConfig = this.parseConfigData(fs.readFileSync(this.globalConfigPath, 'utf8')); + logger.info(`config-handler: global config exists with data ${JSON.stringify(this.globalConfig)}`); } /** * Verifies if the application is launched for the first time */ private async checkFirstTimeLaunch() { - logger.info('checking first launch'); + logger.info('config-handler: checking first time launch'); const configBuildNumber = this.userConfig && (this.userConfig as IConfig).buildNumber || null; if (!configBuildNumber) { + logger.info(`config-handler: there's no build number found, this is a first time launch`); this.isFirstTime = true; return; } if (configBuildNumber && typeof configBuildNumber === 'string' && configBuildNumber !== buildNumber) { + logger.info(`config-handler: build number found is of an older build, this is a first time launch`); this.isFirstTime = true; return; } + logger.info(`config-handler: build number is the same as the previous build, not a first time launch`); this.isFirstTime = false; } } diff --git a/src/app/main.ts b/src/app/main.ts index 1ef929bd..5f38f7dd 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -30,45 +30,43 @@ app.setAsDefaultProtocolClient('symphony'); */ const startApplication = async () => { await app.whenReady(); + logger.info(`main: app is ready, performing initial checks`); createAppCacheFile(); windowHandler.showLoadingScreen(); windowHandler.createApplication(); + logger.info(`main: created application`); if (config.isFirstTimeLaunch()) { - logger.info('first time launch'); + logger.info(`main: This is a first time launch! will update config and handle auto launch`); await config.setUpFirstTimeLaunch(); - - /** - * Enables or disables auto launch base on user settings - */ await autoLaunchInstance.handleAutoLaunch(); } - /** - * Sets chrome flags from global config - */ setChromeFlags(); }; // Handle multiple/single instances if (!allowMultiInstance) { - logger.info('Multiple instance not allowed requesting lock', { allowMultiInstance }); + logger.info('main: Multiple instances are not allowed, requesting lock', { allowMultiInstance }); const gotTheLock = app.requestSingleInstanceLock(); // quit if another instance is already running, ignore for dev env or if app was started with multiInstance flag if (!gotTheLock) { - logger.info('Got the lock hence closing the instance', { gotTheLock }); + logger.info(`main: got the lock hence closing the new instance`, { gotTheLock }); app.quit(); } else { - logger.info('Creating the first instance of the application'); + logger.info(`main: Creating the first instance of the application`); app.on('second-instance', (_event, argv) => { // Someone tried to run a second instance, we should focus our window. + logger.info(`main: We've got a second instance of the app, will check if it's allowed and exit if not`); const mainWindow = windowHandler.getMainWindow(); if (mainWindow && !mainWindow.isDestroyed()) { if (isMac) { + logger.info(`main: We are on mac, so, showing the existing window`); return mainWindow.show(); } if (mainWindow.isMinimized()) { + logger.info(`main: our main window is minimised, will restore it!`); mainWindow.restore(); } mainWindow.focus(); @@ -78,7 +76,7 @@ if (!allowMultiInstance) { startApplication(); } } else { - logger.info('Multiple instance allowed hence create application', { allowMultiInstance }); + logger.info(`main: multi instance allowed, creating second instance`, { allowMultiInstance }); startApplication(); } @@ -86,12 +84,18 @@ if (!allowMultiInstance) { * Is triggered when all the windows are closed * In which case we quit the app */ -app.on('window-all-closed', () => app.quit()); +app.on('window-all-closed', () => { + logger.info(`main: all windows are closed, quitting the app!`); + app.quit(); +}); /** * Creates a new empty cache file when the app is quit */ -app.on('quit', () => cleanUpAppCache()); +app.on('quit', () => { + logger.info(`main: quitting the app!`); + cleanUpAppCache(); +}); /** * Cleans up reference before quiting @@ -107,9 +111,11 @@ app.on('before-quit', () => windowHandler.willQuitApp = true); app.on('activate', () => { const mainWindow: ICustomBrowserWindow | null = windowHandler.getMainWindow(); if (!mainWindow || mainWindow.isDestroyed()) { + logger.info(`main: main window not existing or destroyed, creating a new instance of the main window!`); startApplication(); return; } + logger.info(`main: activating & showing main window now!`); mainWindow.show(); }); @@ -118,4 +124,7 @@ app.on('activate', () => { * * This event is emitted only on macOS at this moment */ -app.on('open-url', (_event, url) => protocolHandler.sendProtocol(url)); +app.on('open-url', (_event, url) => { + logger.info(`main: we got a protocol request with url ${url}! processing the request!`); + protocolHandler.sendProtocol(url); +}); diff --git a/src/app/memory-monitor.ts b/src/app/memory-monitor.ts index 81618208..30da96a5 100644 --- a/src/app/memory-monitor.ts +++ b/src/app/memory-monitor.ts @@ -30,6 +30,7 @@ class MemoryMonitor { */ public setMemoryInfo(memoryInfo: Electron.ProcessMemoryInfo): void { this.memoryInfo = memoryInfo; + logger.info(`memory-monitor: setting memory info to ${memoryInfo}`); this.validateMemory(); } @@ -40,15 +41,17 @@ class MemoryMonitor { */ public setMeetingStatus(isInMeeting: boolean): void { this.isInMeeting = isInMeeting; + logger.info(`memory-monitor: setting meeting status to ${isInMeeting}`); } /** * Validates the predefined conditions and refreshes the client */ private validateMemory(): void { + logger.info(`memory-monitor: validating memory refresh conditions`); const { memoryRefresh } = config.getConfigFields([ 'memoryRefresh' ]); if (!memoryRefresh) { - logger.info(`memory refresh is disabled`); + logger.info(`memory-monitor: memory refresh is disabled in the config, not going to refresh!`); return; } @@ -61,7 +64,7 @@ class MemoryMonitor { && idleTime > this.maxIdleTime && (workingSetSizeInMB > this.memoryThreshold)) ) { - logger.info(`Not Reloading the app as + logger.info(`memory-monitor: Not Reloading the app as application was refreshed less than a hour ago? ${this.canReload ? 'no' : 'yes'} memory consumption is ${(workingSetSizeInMB) || 'unknown'}mb is less than? ${this.memoryThreshold}mb system idle tick was ${idleTime}ms is less than? ${this.maxIdleTime}ms @@ -71,7 +74,7 @@ class MemoryMonitor { } const mainWindow = windowHandler.getMainWindow(); if (mainWindow && windowExists(mainWindow)) { - logger.info(`Reloading the app to optimize memory usage as + logger.info(`memory-monitor: Reloading the app to optimize memory usage as memory consumption is ${workingSetSizeInMB}mb is greater than? ${this.memoryThreshold}mb threshold system idle tick was ${idleTime}ms is greater than ${this.maxIdleTime}ms user was in a meeting? ${this.isInMeeting} diff --git a/src/app/protocol-handler.ts b/src/app/protocol-handler.ts index 8cfa4d56..1a0baed9 100644 --- a/src/app/protocol-handler.ts +++ b/src/app/protocol-handler.ts @@ -1,5 +1,6 @@ import { apiName } from '../common/api-interface'; import { isMac } from '../common/env'; +import { logger } from '../common/logger'; import { getCommandLineArgs } from '../common/utils'; import { activate } from './window-actions'; @@ -25,9 +26,10 @@ class ProtocolHandler { */ public setPreloadWebContents(webContents: Electron.WebContents): void { this.preloadWebContents = webContents; - // check for cashed protocol uri and process it + logger.info(`protocol handler: SFE is active and we have a valid protocol window with web contents!`); if (this.protocolUri) { this.sendProtocol(this.protocolUri); + logger.info(`protocol handler: we have a cached url ${this.protocolUri}, so, processed the request to SFE!`); this.protocolUri = null; } } @@ -35,12 +37,14 @@ class ProtocolHandler { /** * Sends the protocol uri to the web app to further process * - * @param uri {String} + * @param url {String} * @param isAppRunning {Boolean} - whether the application is running */ - public sendProtocol(uri: string, isAppRunning: boolean = true): void { + public sendProtocol(url: string, isAppRunning: boolean = true): void { + logger.info(`protocol handler: processing protocol request for the url ${url}!`); if (!this.preloadWebContents || !isAppRunning) { - this.protocolUri = uri; + logger.info(`protocol handler: app was started from the protocol request. Caching the URL ${url}!`); + this.protocolUri = url; return; } // This is needed for mac OS as it brings pop-outs to foreground @@ -49,8 +53,9 @@ class ProtocolHandler { activate(apiName.mainWindowName); } - if (ProtocolHandler.isValidProtocolUri(uri)) { - this.preloadWebContents.send('protocol-action', uri); + if (ProtocolHandler.isValidProtocolUri(url)) { + logger.info(`protocol handler: our protocol request is a valid url ${url}! sending request to SFE for further action!`); + this.preloadWebContents.send('protocol-action', url); } } @@ -60,8 +65,10 @@ class ProtocolHandler { * @param argv {String[]} - data received from process.argv */ public processArgv(argv?: string[]): void { + logger.info(`protocol handler: processing protocol args!`); const protocolUriFromArgv = getCommandLineArgs(argv || process.argv, protocol.SymphonyProtocol, false); if (protocolUriFromArgv) { + logger.info(`protocol handler: we have a protocol request for the url ${protocolUriFromArgv}!`); this.sendProtocol(protocolUriFromArgv, false); } } diff --git a/src/app/reports-handler.ts b/src/app/reports-handler.ts index b366fe85..e9c775a8 100644 --- a/src/app/reports-handler.ts +++ b/src/app/reports-handler.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import { isMac } from '../common/env'; import { i18n } from '../common/i18n'; +import { logger } from '../common/logger'; /** * Archives files in the source directory @@ -19,14 +20,17 @@ import { i18n } from '../common/i18n'; const generateArchiveForDirectory = (source: string, destination: string, fileExtensions: string[]): Promise => { return new Promise((resolve, reject) => { + logger.info(`reports-handler: generating archive for directory ${source}`); const output = fs.createWriteStream(destination); const archive = archiver('zip', { zlib: { level: 9 } }); output.on('close', () => { + logger.info(`reports-handler: generated archive for directory ${source}`); return resolve(); }); - archive.on('error', (err) => { + archive.on('error', (err: Error) => { + logger.error(`reports-handler: error archiving directory for ${source} with error ${err}`); return reject(err); }); @@ -69,8 +73,9 @@ export const exportLogs = (): void => { const focusedWindow = BrowserWindow.getFocusedWindow(); if (!fs.existsSync(source) && focusedWindow && !focusedWindow.isDestroyed()) { + logger.error(`reports-handler: Can't find any logs to share!`); dialog.showMessageBox(focusedWindow, { - message: i18n.t('No logs are available to share')(), + message: i18n.t(`Can't find any logs to share!`)(), title: i18n.t('Failed!')(), type: 'error', }); @@ -86,6 +91,7 @@ export const exportLogs = (): void => { }) .catch((err) => { if (focusedWindow && !focusedWindow.isDestroyed()) { + logger.error(`reports-handler: Can't share logs due to error ${err}`); dialog.showMessageBox(focusedWindow, { message: `${i18n.t('Unable to generate logs due to ')()} ${err}`, title: i18n.t('Failed!')(), diff --git a/src/app/screen-snippet-handler.ts b/src/app/screen-snippet-handler.ts index 92826543..e5f63dc6 100644 --- a/src/app/screen-snippet-handler.ts +++ b/src/app/screen-snippet-handler.ts @@ -38,26 +38,32 @@ class ScreenSnippet { * @param webContents {Electron.webContents} */ public async capture(webContents: Electron.webContents) { + logger.info(`screen-snippet-handler: Starting screen capture!`); this.outputFileName = path.join(this.tempDir, 'symphonyImage-' + Date.now() + '.jpg'); this.captureUtilArgs = isMac ? [ '-i', '-s', '-t', 'jpg', this.outputFileName ] : [ this.outputFileName, i18n.getLocale() ]; + logger.info(`screen-snippet-handler: Capturing snippet with file ${this.outputFileName} and args ${this.captureUtilArgs}!`); + const mainWindow = windowHandler.getMainWindow(); if (mainWindow) { this.isAlwaysOnTop = mainWindow.isAlwaysOnTop(); + logger.info(`screen-snippet-handler: Is main window always on top? ${this.isAlwaysOnTop}!`); updateAlwaysOnTop(false, false); } // only allow one screen capture at a time. if (this.child) { + logger.info(`screen-snippet-handler: Child screen capture exists, killing it and keeping only 1 instance!`); this.child.kill(); } try { await this.execCmd(this.captureUtil, this.captureUtilArgs); const { message, data, type }: IScreenSnippet = await this.convertFileToData(); + logger.info(`screen-snippet-handler: Snippet captured! Sending data to SFE`); webContents.send('screen-snippet-data', { message, data, type }); } catch (error) { - logger.error(`screen-snippet: screen snippet process was killed`, error); + logger.error(`screen-snippet-handler: screen capture failed with error: ${error}!`); } } @@ -105,10 +111,12 @@ class ScreenSnippet { private async convertFileToData(): Promise { try { if (!this.outputFileName) { + logger.info(`screen-snippet-handler: screen capture failed! output file doesn't exist!`); return { message: 'output file name is required', type: 'ERROR' }; } const data = await readFile(this.outputFileName); if (!data) { + logger.info(`screen-snippet-handler: screen capture failed! data doesn't exist!`); return { message: `no file data provided`, type: 'ERROR' }; } // convert binary data to base64 encoded string @@ -125,10 +133,9 @@ class ScreenSnippet { // remove tmp file (async) if (this.outputFileName) { fs.unlink(this.outputFileName, (removeErr) => { - // note: node complains if calling async - // func without callback. + logger.info(`screen-snippet-handler: cleaning up temp snippet file: ${this.outputFileName}!`); if (removeErr) { - logger.error(`ScreenSnippet: error removing temp snippet file: ${this.outputFileName}, err: ${removeErr}`); + logger.error(`screen-snippet-handler: error removing temp snippet file: ${this.outputFileName}, err: ${removeErr}`); } }); } diff --git a/src/app/spell-check-handler.ts b/src/app/spell-check-handler.ts index fac01601..468457cd 100644 --- a/src/app/spell-check-handler.ts +++ b/src/app/spell-check-handler.ts @@ -4,6 +4,7 @@ import * as path from 'path'; import { ContextMenuBuilder, DictionarySync, SpellCheckHandler } from 'electron-spellchecker'; import { isDevEnv, isMac } from '../common/env'; import { i18n, LocaleType } from '../common/i18n'; +import { logger } from '../common/logger'; export class SpellChecker { public locale: LocaleType = 'en-US'; @@ -42,6 +43,7 @@ export class SpellChecker { const contextMenuBuilder = new ContextMenuBuilder(this.spellCheckHandler, webContents, false, this.processMenu); contextMenuBuilder.setAlternateStringFormatter(this.getStringTable()); this.locale = i18n.getLocale(); + logger.info(`spell-check-handler: Building context menu with locale ${this.locale}!`); const contextMenuListener = (_event, info) => { if (this.locale !== i18n.getLocale()) { contextMenuBuilder.setAlternateStringFormatter(this.getStringTable()); @@ -52,6 +54,7 @@ export class SpellChecker { webContents.on('context-menu', contextMenuListener); webContents.once('destroyed', () => { + logger.info(`spell-check-handler: web contents destroyed, removing context menu listener!`); webContents.removeListener('context-menu', contextMenuListener); }); } diff --git a/src/app/window-actions.ts b/src/app/window-actions.ts index 0066050d..2961300a 100644 --- a/src/app/window-actions.ts +++ b/src/app/window-actions.ts @@ -1,7 +1,7 @@ import { BrowserWindow } from 'electron'; - import { apiName, IBoundsChange, KeyCodes } from '../common/api-interface'; import { isMac, isWindowsOS } from '../common/env'; +import { logger } from '../common/logger'; import { throttle } from '../common/utils'; import { config } from './config-handler'; import { ICustomBrowserWindow, windowHandler } from './window-handler'; @@ -95,6 +95,7 @@ export const activate = (windowName: string, shouldFocus: boolean = true): void * @param shouldActivateMainWindow */ export const updateAlwaysOnTop = (shouldSetAlwaysOnTop: boolean, shouldActivateMainWindow: boolean = true): void => { + logger.info(`window-actions: Should we set always on top? ${shouldSetAlwaysOnTop}!`); const browserWins: ICustomBrowserWindow[] = BrowserWindow.getAllWindows() as ICustomBrowserWindow[]; if (browserWins.length > 0) { browserWins @@ -107,6 +108,7 @@ export const updateAlwaysOnTop = (shouldSetAlwaysOnTop: boolean, shouldActivateM const mainWindow = windowHandler.getMainWindow(); if (mainWindow && mainWindow.winName && shouldActivateMainWindow) { activate(mainWindow.winName); + logger.info(`window-actions: activated main window!`); } } }; diff --git a/src/app/window-handler.ts b/src/app/window-handler.ts index 5617cb2e..2ddc6c75 100644 --- a/src/app/window-handler.ts +++ b/src/app/window-handler.ts @@ -225,7 +225,7 @@ export class WindowHandler { public createApplication() { this.spellchecker = new SpellChecker(); - logger.info(`initialized spellchecker module with locale ${this.spellchecker.locale}`); + logger.info(`window-handler: initialized spellchecker module with locale ${this.spellchecker.locale}`); // set window opts with additional config this.mainWindow = new BrowserWindow({ @@ -235,13 +235,16 @@ export class WindowHandler { const { isFullScreen, isMaximized } = this.config.mainWinPos ? this.config.mainWinPos : { isFullScreen: false, isMaximized: false }; if (isMaximized) { this.mainWindow.maximize(); + logger.info(`window-handler: window is maximized!`); } if (isFullScreen) { + logger.info(`window-handler: window is in full screen!`); this.mainWindow.setFullScreen(true); } // Event needed to hide native menu bar on Windows 10 as we use custom menu bar this.mainWindow.webContents.once('did-start-loading', () => { + logger.info(`window-handler: main window web contents started loading!`); if ((this.config.isCustomTitleBar || isWindowsOS) && this.mainWindow && windowExists(this.mainWindow)) { this.mainWindow.setMenuBarVisibility(false); } @@ -254,8 +257,10 @@ export class WindowHandler { // loads the main window with url from config/cmd line this.mainWindow.loadURL(this.url); this.mainWindow.webContents.on('did-finish-load', async () => { + logger.info(`window-handler: main window web contents finished loading!`); // early exit if the window has already been destroyed if (!this.mainWindow || !windowExists(this.mainWindow)) { + logger.info(`window-handler: main window web contents destroyed already! exiting`); return; } this.url = this.mainWindow.webContents.getURL(); @@ -277,7 +282,7 @@ export class WindowHandler { }); this.mainWindow.webContents.on('did-fail-load', (_event, errorCode, errorDesc, validatedURL) => { - logger.error(`Failed to load ${validatedURL}, with an error: ${errorCode}::${errorDesc}`); + logger.error(`window-handler: Failed to load ${validatedURL}, with an error: ${errorCode}::${errorDesc}`); this.loadFailError = errorDesc; }); @@ -301,8 +306,10 @@ export class WindowHandler { this.mainWindow.webContents.on('crashed', (_event: Event, killed: boolean) => { if (killed) { + logger.info(`window-handler: main window crashed (killed)!`); return; } + logger.info(`window-handler: main window crashed!`); electron.dialog.showMessageBox({ type: 'error', title: i18n.t('Renderer Process Crashed')(), @@ -323,6 +330,7 @@ export class WindowHandler { } if (this.willQuitApp) { + logger.info(`window-handler: app is quitting, destroying all windows!`); return this.destroyAllWindows(); } @@ -336,6 +344,7 @@ export class WindowHandler { }); this.mainWindow.once('closed', () => { + logger.info(`window-handler: main window closed, destroying all windows!`); this.destroyAllWindows(); }); @@ -369,8 +378,10 @@ export class WindowHandler { * all the HTML content have been injected */ public initMainWindow(): void { + logger.info(`window-handler: initializing main window!`); if (this.mainWindow && windowExists(this.mainWindow)) { if (!this.isOnline && this.loadingWindow && windowExists(this.loadingWindow)) { + logger.info(`window-handler: network is offline!`); this.loadingWindow.webContents.send('loading-screen-data', { error: 'NETWORK_OFFLINE' }); return; } @@ -378,6 +389,7 @@ export class WindowHandler { // close the loading window when // the main windows finished loading if (this.loadingWindow && windowExists(this.loadingWindow)) { + logger.info(`window-handler: closing loading window as the main window is now ready!`); this.loadingWindow.close(); } @@ -412,6 +424,7 @@ export class WindowHandler { * @param winKey {string} - Unique ID assigned to the window */ public closeWindow(windowType: WindowTypes, winKey?: string): void { + logger.info(`window-handler: closing window type ${windowType} with key ${winKey}!`); switch (windowType) { case 'screen-picker': if (this.screenPickerWindow && windowExists(this.screenPickerWindow)) { @@ -489,8 +502,10 @@ export class WindowHandler { return; } if (error) { + logger.info(`window-handler: loading screen failed ${error}!`); this.loadingWindow.webContents.send('loading-screen-data', { error }); } + logger.info(`window-handler: loading screen started ${error}!`); }); ipcMain.once('reload-symphony', () => { @@ -767,6 +782,7 @@ export class WindowHandler { public openUrlInDefaultBrowser(urlToOpen) { if (urlToOpen) { electron.shell.openExternal(urlToOpen); + logger.info(`window-handler: opened url ${urlToOpen} in the default browser!`); } } @@ -793,6 +809,7 @@ export class WindowHandler { * Registers keyboard shortcuts or devtools */ private registerGlobalShortcuts(): void { + logger.info(`window-handler: registering global shortcuts!`); globalShortcut.register(isMac ? 'Cmd+Alt+I' : 'Ctrl+Shift+I', this.onRegisterDevtools); app.on('browser-window-focus', () => { @@ -819,6 +836,7 @@ export class WindowHandler { return; } focusedWindow.webContents.closeDevTools(); + logger.info(`window-handler: dev tools disabled by admin, showing error dialog to user!`); electron.dialog.showMessageBox(focusedWindow, { type: 'warning', buttons: [ 'Ok' ], diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index 1def86a2..ca6df216 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -52,9 +52,11 @@ export const preventWindowNavigation = (browserWindow: BrowserWindow, isPopOutWi if (!browserWindow || !windowExists(browserWindow)) { return; } + logger.info(`window-utils: preventing window from navigating!`); const listener = (e: Electron.Event, winUrl: string) => { if (!winUrl.startsWith('http' || 'https')) { + logger.info(`window-utils: ${winUrl} doesn't start with http or https, so, not navigating!`); e.preventDefault(); return; } @@ -158,10 +160,12 @@ export const createComponentWindow = ( */ export const showBadgeCount = (count: number): void => { if (typeof count !== 'number') { - logger.warn(`badgeCount: invalid func arg, must be a number: ${count}`); + logger.warn(`window-utils: badgeCount: invalid func arg, must be a number: ${count}`); return; } + logger.info(`window-utils: updating barge count to ${count}!`); + if (isMac) { // too big of a number here and setBadgeCount crashes app.setBadgeCount(Math.min(1e8, count)); @@ -219,7 +223,7 @@ export const isValidWindow = (browserWin: Electron.BrowserWindow): boolean => { } if (!result) { - logger.warn('invalid window try to perform action, ignoring action'); + logger.warn('window-utils: invalid window try to perform action, ignoring action'); } return result; @@ -231,10 +235,12 @@ export const isValidWindow = (browserWin: Electron.BrowserWindow): boolean => { * @param locale {LocaleType} */ export const updateLocale = (locale: LocaleType): void => { + logger.info(`window-utils: updating locale to ${locale}!`); // sets the new locale i18n.setLocale(locale); const appMenu = windowHandler.appMenu; if (appMenu) { + logger.info(`window-utils: updating app menu with locale ${locale}!`); appMenu.update(locale); } }; @@ -454,8 +460,10 @@ export const isSymphonyReachable = (window: ICustomBrowserWindow | null) => { return; } const podUrl = `${protocol}//${hostname}`; + logger.info(`window-utils: checking to see if pod ${podUrl} is reachable!`); fetch(podUrl, { method: 'GET' }).then((rsp) => { if (rsp.status === 200 && windowHandler.isOnline) { + logger.info(`window-utils: pod ${podUrl} is reachable, loading main window!`); window.loadURL(podUrl); if (networkStatusCheckIntervalId) { clearInterval(networkStatusCheckIntervalId); @@ -463,9 +471,9 @@ export const isSymphonyReachable = (window: ICustomBrowserWindow | null) => { } return; } - logger.warn(`Symphony down! statusCode: ${rsp.status} is online: ${windowHandler.isOnline}`); + logger.warn(`window-utils: POD is down! statusCode: ${rsp.status}, is online: ${windowHandler.isOnline}`); }).catch((error) => { - logger.error(`Network status check: No active network connection ${error}`); + logger.error(`window-utils: Network status check: No active network connection ${error}`); }); }, networkStatusCheckInterval); }; diff --git a/src/common/animation-queue.ts b/src/common/animation-queue.ts index 384b8ff3..56ce2b5b 100644 --- a/src/common/animation-queue.ts +++ b/src/common/animation-queue.ts @@ -30,7 +30,7 @@ export class AnimationQueue { try { await object.func.apply(null, object.args); } catch (err) { - logger.error(`animationQueue: encountered an error: ${err} with stack trace: ${err.stack}`); + logger.error(`animation-queue: encountered an error: ${err} with stack trace: ${err.stack}`); } finally { if (this.queue.length > 0) { // Run next animation diff --git a/src/common/whitelist-handler.ts b/src/common/whitelist-handler.ts index 3a64917b..4653f118 100644 --- a/src/common/whitelist-handler.ts +++ b/src/common/whitelist-handler.ts @@ -57,7 +57,7 @@ export class WhitelistHandler { * returns true if hostName or domain present in the whitelist * * @param url {String} - url the electron is navigated to - * @param whitelistUrl {String} - coma separated whitelists + * @param whitelistUrl {String} - comma separated whitelists * * @returns {boolean} */