SDA-1651 - Temporarily disable AOT when screen snippet is open (#842)

This commit is contained in:
Kiran Niranjan 2020-01-08 17:18:03 +05:30 committed by Vishwas Shashidhar
parent 43472b0c95
commit a9fc026df9
4 changed files with 22 additions and 9 deletions

View File

@ -224,12 +224,9 @@ describe('app menu', () => {
});
it('should update `alwaysOnTop` value when click is triggered', async () => {
const spyConfig = jest.spyOn(config, updateUserFnLabel);
const expectedValue = { alwaysOnTop: true };
const menuItem = findMenuItemBuildWindowMenu('Always on Top');
await menuItem.click(item);
expect(updateAlwaysOnTop).toBeCalledWith(true, true);
expect(spyConfig).lastCalledWith(expectedValue);
});
it('should update `minimizeOnClose` value when click is triggered', async () => {

View File

@ -281,8 +281,7 @@ export class AppMenu {
checked: isAlwaysOnTop,
click: async (item) => {
isAlwaysOnTop = item.checked;
updateAlwaysOnTop(item.checked, true);
await config.updateUserConfig({ alwaysOnTop: item.checked });
await updateAlwaysOnTop(item.checked, true);
this.sendAnalytics(AnalyticsElements.MENU, MenuActionTypes.ALWAYS_ON_TOP, item.checked);
},
label: i18n.t('Always on Top')(),

View File

@ -6,9 +6,11 @@ import * as path from 'path';
import { ChildProcess, ExecException, execFile } from 'child_process';
import * as util from 'util';
import { IScreenSnippet } from '../common/api-interface';
import { isDevEnv, isLinux, isMac } from '../common/env';
import { isDevEnv, isLinux, isMac, isWindowsOS } from '../common/env';
import { i18n } from '../common/i18n';
import { logger } from '../common/logger';
import { updateAlwaysOnTop } from './window-actions';
import { windowHandler } from './window-handler';
import { windowExists } from './window-utils';
const readFile = util.promisify(fs.readFile);
@ -20,6 +22,7 @@ class ScreenSnippet {
private captureUtilArgs: ReadonlyArray<string> | undefined;
private child: ChildProcess | undefined;
private focusedWindow: BrowserWindow | null = null;
private shouldUpdateAlwaysOnTop: boolean = false;
constructor() {
this.tempDir = os.tmpdir();
@ -40,6 +43,13 @@ class ScreenSnippet {
* @param webContents {Electron.webContents}
*/
public async capture(webContents: Electron.webContents) {
const mainWindow = windowHandler.getMainWindow();
if (mainWindow && windowExists(mainWindow) && isWindowsOS) {
this.shouldUpdateAlwaysOnTop = mainWindow.isAlwaysOnTop();
if (this.shouldUpdateAlwaysOnTop) {
await updateAlwaysOnTop(false, false);
}
}
logger.info(`screen-snippet-handler: Starting screen capture!`);
this.outputFileName = path.join(this.tempDir, 'symphonyImage-' + Date.now() + '.png');
this.captureUtilArgs = isMac
@ -62,15 +72,21 @@ class ScreenSnippet {
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 });
if (this.shouldUpdateAlwaysOnTop) {
await updateAlwaysOnTop(true, false);
this.shouldUpdateAlwaysOnTop = false;
}
} catch (error) {
if (this.shouldUpdateAlwaysOnTop) {
await updateAlwaysOnTop(true, false);
this.shouldUpdateAlwaysOnTop = false;
}
logger.error(`screen-snippet-handler: screen capture failed with error: ${error}!`);
}
}
/**
* Cancels a screen capture and closes the snippet window
*
* @param webContents {Electron.webContents}
*/
public async cancelCapture() {
logger.info(`screen-snippet-handler: Cancel screen capture!`);

View File

@ -136,9 +136,10 @@ export const activate = (windowName: string, shouldFocus: boolean = true): void
* @param shouldSetAlwaysOnTop
* @param shouldActivateMainWindow
*/
export const updateAlwaysOnTop = (shouldSetAlwaysOnTop: boolean, shouldActivateMainWindow: boolean = true): void => {
export const updateAlwaysOnTop = async (shouldSetAlwaysOnTop: boolean, shouldActivateMainWindow: boolean = true): Promise<void> => {
logger.info(`window-actions: Should we set always on top? ${shouldSetAlwaysOnTop}!`);
const browserWins: ICustomBrowserWindow[] = BrowserWindow.getAllWindows() as ICustomBrowserWindow[];
await config.updateUserConfig({ alwaysOnTop: shouldSetAlwaysOnTop });
if (browserWins.length > 0) {
browserWins
.filter((browser) => typeof browser.notificationData !== 'object')