mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
add more logging
- activity detection - app cache - app menu - auto launch controller - child window handler
This commit is contained in:
parent
099235b424
commit
9e7be94851
@ -33,6 +33,7 @@ class ActivityDetection {
|
||||
*/
|
||||
private startActivityMonitor(): void {
|
||||
if (app.isReady()) {
|
||||
logger.info(`activity-detection: Starting activity monitor`);
|
||||
setInterval(() => (electron.powerMonitor as any).querySystemIdleTime(this.activity.bind(this)), this.idleThreshold);
|
||||
}
|
||||
}
|
||||
@ -54,7 +55,7 @@ class ActivityDetection {
|
||||
// activate func works normally
|
||||
windowHandler.setIsAutoReload(false);
|
||||
this.timer = undefined;
|
||||
logger.info(`activity-detection: activity occurred`);
|
||||
logger.info(`activity-detection: activity occurred, updating the client!`);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,6 +79,7 @@ class ActivityDetection {
|
||||
private sendActivity(idleTime: number): void {
|
||||
if (this.window && !this.window.isDestroyed()) {
|
||||
this.window.send('activity', idleTime || 1);
|
||||
logger.info(`activity-detection: Sending activity status to the client!`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { app, session } from 'electron';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {logger} from "../common/logger";
|
||||
|
||||
// Cache check file path
|
||||
const cacheCheckFilePath: string = path.join(app.getPath('userData'), 'CacheCheck');
|
||||
@ -12,14 +13,17 @@ const cacheCheckFilePath: string = path.join(app.getPath('userData'), 'CacheChec
|
||||
export const cleanUpAppCache = async (): Promise<void> => {
|
||||
if (fs.existsSync(cacheCheckFilePath)) {
|
||||
await fs.unlinkSync(cacheCheckFilePath);
|
||||
logger.info(`app-cache-handler: last exit was clean, deleted the app cache file`);
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => session.defaultSession ? session.defaultSession.clearCache(resolve) : null);
|
||||
logger.info(`app-cache-handler: we didn't have a clean exit last time, so, cleared the cache that may have been corrupted!`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new file cache file on app exit
|
||||
*/
|
||||
export const createAppCacheFile = (): void => {
|
||||
logger.info(`app-cache-handler: this is a clean exit, creating app cache file`);
|
||||
fs.writeFileSync(cacheCheckFilePath, '');
|
||||
};
|
||||
|
@ -85,7 +85,9 @@ export class AppMenu {
|
||||
.map((key) => this.menuList[ key ]);
|
||||
|
||||
this.menu = Menu.buildFromTemplate(template);
|
||||
logger.info(`app-menu: built menu from the provided template`);
|
||||
Menu.setApplicationMenu(this.menu);
|
||||
logger.info(`app-menu: set application menu`);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,6 +97,7 @@ export class AppMenu {
|
||||
*/
|
||||
public update(locale: LocaleType): void {
|
||||
if (this.locale !== locale) {
|
||||
logger.info(`app-menu: updating the menu for locale ${locale}`);
|
||||
this.buildMenu();
|
||||
this.locale = locale;
|
||||
}
|
||||
@ -107,7 +110,7 @@ export class AppMenu {
|
||||
*/
|
||||
public popupMenu(opts: Electron.PopupOptions): void {
|
||||
if (!this.menu) {
|
||||
logger.error(`app-menu: tried popup menu, but failed menu not defined`);
|
||||
logger.error(`app-menu: tried popup menu, but failed, menu not defined`);
|
||||
return;
|
||||
}
|
||||
this.menu.popup(opts);
|
||||
@ -139,6 +142,7 @@ export class AppMenu {
|
||||
* Builds menu items for about symphony section
|
||||
*/
|
||||
private buildAboutMenu(): Electron.MenuItemConstructorOptions {
|
||||
logger.info(`app-menu: building about menu`);
|
||||
return {
|
||||
id: menuSections.about,
|
||||
label: app.getName(),
|
||||
@ -160,6 +164,7 @@ export class AppMenu {
|
||||
* Builds menu items for edit section
|
||||
*/
|
||||
private buildEditMenu(): Electron.MenuItemConstructorOptions {
|
||||
logger.info(`app-menu: building edit menu`);
|
||||
const menu = {
|
||||
label: i18n.t('Edit')(),
|
||||
submenu:
|
||||
@ -192,6 +197,7 @@ export class AppMenu {
|
||||
* Builds menu items for view section
|
||||
*/
|
||||
private buildViewMenu(): Electron.MenuItemConstructorOptions {
|
||||
logger.info(`app-menu: building view menu`);
|
||||
return {
|
||||
label: i18n.t('View')(),
|
||||
submenu: [ {
|
||||
@ -213,6 +219,7 @@ export class AppMenu {
|
||||
* Builds menu items for window section
|
||||
*/
|
||||
private buildWindowMenu(): Electron.MenuItemConstructorOptions {
|
||||
logger.info(`app-menu: building window menu`);
|
||||
const hamburgerMenuItem = isWindowsOS
|
||||
? {
|
||||
label: this.titleBarStyle === TitleBarStyles.NATIVE
|
||||
@ -313,6 +320,7 @@ export class AppMenu {
|
||||
* Builds menu items for help section
|
||||
*/
|
||||
private buildHelpMenu(): Electron.MenuItemConstructorOptions {
|
||||
logger.info(`app-menu: building help menu`);
|
||||
return {
|
||||
label: i18n.t('Help')(),
|
||||
role: 'help',
|
||||
@ -375,6 +383,7 @@ export class AppMenu {
|
||||
* @return {Object}.accelerator keyboard shortcuts and modifiers
|
||||
*/
|
||||
private assignRoleOrLabel({ role, label }: MenuItemConstructorOptions): MenuItemConstructorOptions {
|
||||
logger.info(`app-menu: assigning role & label respectively for ${role} & ${label}`);
|
||||
if (isMac) {
|
||||
return label ? { role, label } : { role };
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ class AutoLaunchController {
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public enableAutoLaunch(): void {
|
||||
logger.info(`Enabling auto launch!`);
|
||||
app.setLoginItemSettings({ openAtLogin: true, path: props.path });
|
||||
logger.info(`auto-launch-controller: Enabled auto launch!`);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,8 +37,8 @@ class AutoLaunchController {
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
public disableAutoLaunch(): void {
|
||||
logger.info(`Disabling auto launch!`);
|
||||
app.setLoginItemSettings({ openAtLogin: false, path: props.path });
|
||||
logger.info(`auto-launch-controller: Disabled auto launch!`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
injectStyles,
|
||||
preventWindowNavigation,
|
||||
} from './window-utils';
|
||||
import {logger} from "../common/logger";
|
||||
|
||||
const DEFAULT_POP_OUT_WIDTH = 300;
|
||||
const DEFAULT_POP_OUT_HEIGHT = 600;
|
||||
@ -31,25 +32,33 @@ const getParsedUrl = (configURL: string): Url => {
|
||||
const parsedUrl = parse(configURL);
|
||||
|
||||
if (!parsedUrl.protocol || parsedUrl.protocol !== 'https') {
|
||||
logger.info(`child-window-handler: The url ${configURL} doesn't have a valid protocol or is not https, so, adding https!`);
|
||||
parsedUrl.protocol = 'https:';
|
||||
parsedUrl.slashes = true;
|
||||
}
|
||||
return parse(format(parsedUrl));
|
||||
const finalParsedUrl = parse(format(parsedUrl));
|
||||
logger.info(`child-window-handler: The original url ${configURL} is finally parsed as ${finalParsedUrl}`);
|
||||
return finalParsedUrl;
|
||||
};
|
||||
|
||||
export const handleChildWindow = (webContents: WebContents): void => {
|
||||
const childWindow = (event, newWinUrl, frameName, disposition, newWinOptions): void => {
|
||||
logger.info(`child-window-handler: trying to create new child window for url ${newWinUrl},
|
||||
frame ${frameName}, disposition ${disposition}`);
|
||||
const mainWindow = windowHandler.getMainWindow();
|
||||
if (!mainWindow || mainWindow.isDestroyed()) {
|
||||
logger.info(`child-window-handler: main window is not available / destroyed, not creating child window!`);
|
||||
return;
|
||||
}
|
||||
if (!windowHandler.url) {
|
||||
logger.info(`child-window-handler: we don't have a valid url, not creating child window!`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newWinOptions.webPreferences) {
|
||||
newWinOptions.webPreferences = {};
|
||||
}
|
||||
|
||||
Object.assign(newWinOptions.webPreferences, webContents);
|
||||
const newWinParsedUrl = getParsedUrl(newWinUrl);
|
||||
const mainWinParsedUrl = getParsedUrl(windowHandler.url);
|
||||
@ -61,27 +70,26 @@ export const handleChildWindow = (webContents: WebContents): void => {
|
||||
const dispositionWhitelist = ['new-window', 'foreground-tab'];
|
||||
|
||||
const fullMainUrl = `${mainWinParsedUrl.protocol}//${mainWinParsedUrl.host}/`;
|
||||
logger.info(`child-window-handler: full main url is ${fullMainUrl}!`);
|
||||
// If the main url and new window url are the same,
|
||||
// we open that in a browser rather than a separate window
|
||||
if (newWinUrl === fullMainUrl) {
|
||||
event.preventDefault();
|
||||
logger.info(`child-window-handler: the new window url ${newWinUrl} and the main url ${fullMainUrl}
|
||||
are the same, so, redirecting to be opened in the default browser!`);
|
||||
windowHandler.openUrlInDefaultBrowser(newWinUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
// only allow window.open to succeed is if coming from same hsot,
|
||||
// only allow window.open to succeed if it is coming from same host,
|
||||
// otherwise open in default browser.
|
||||
if ((newWinHost === mainWinHost
|
||||
|| newWinUrl === emptyUrlString
|
||||
|| (newWinHost
|
||||
&& mainWinHost
|
||||
&& newWinHost.indexOf(mainWinHost) !== -1
|
||||
&& frameName !== ''))
|
||||
if ((newWinHost === mainWinHost || newWinUrl === emptyUrlString ||
|
||||
(newWinHost && mainWinHost && newWinHost.indexOf(mainWinHost) !== -1 && frameName !== ''))
|
||||
&& dispositionWhitelist.includes(disposition)) {
|
||||
|
||||
const newWinKey = getGuid();
|
||||
if (!frameName) {
|
||||
// abort - no frame name provided.
|
||||
logger.info(`child-window-handler: frame name missing! not opening the url ${newWinUrl}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -97,7 +105,6 @@ export const handleChildWindow = (webContents: WebContents): void => {
|
||||
if (Number.isInteger(newX) && Number.isInteger(newY)) {
|
||||
const newWinRect = { x: newX, y: newY, width, height };
|
||||
const { x, y } = getBounds(newWinRect, DEFAULT_POP_OUT_WIDTH, DEFAULT_POP_OUT_HEIGHT);
|
||||
|
||||
newWinOptions.x = x;
|
||||
newWinOptions.y = y;
|
||||
} else {
|
||||
@ -129,6 +136,7 @@ export const handleChildWindow = (webContents: WebContents): void => {
|
||||
});
|
||||
|
||||
childWebContents.once('did-finish-load', async () => {
|
||||
logger.info(`child-window-handler: child window content loaded for url ${newWinUrl}!`);
|
||||
const browserWin: ICustomBrowserWindow = BrowserWindow.fromWebContents(childWebContents) as ICustomBrowserWindow;
|
||||
if (!browserWin) {
|
||||
return;
|
||||
@ -147,6 +155,7 @@ export const handleChildWindow = (webContents: WebContents): void => {
|
||||
await injectStyles(browserWin, false);
|
||||
browserWin.winName = frameName;
|
||||
browserWin.setAlwaysOnTop(mainWindow.isAlwaysOnTop());
|
||||
logger.info(`child-window-handler: setting always on top for child window? ${mainWindow.isAlwaysOnTop()}!`);
|
||||
|
||||
// prevents window from navigating
|
||||
preventWindowNavigation(browserWin, true);
|
||||
@ -155,6 +164,7 @@ export const handleChildWindow = (webContents: WebContents): void => {
|
||||
monitorWindowActions(browserWin);
|
||||
// Remove all attached event listeners
|
||||
browserWin.on('close', () => {
|
||||
logger.info(`child-window-handler: close event occurred for window with url ${newWinUrl}!`);
|
||||
removeWindowEventListener(browserWin);
|
||||
});
|
||||
|
||||
@ -173,6 +183,8 @@ export const handleChildWindow = (webContents: WebContents): void => {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.info(`child-window-handler: new window url is ${newWinUrl} which is not of the same host,
|
||||
so opening it in the default browser!`);
|
||||
event.preventDefault();
|
||||
windowHandler.openUrlInDefaultBrowser(newWinUrl);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user