mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
ELECTRON-828 - Make screen snippet top most window (#766)
This commit is contained in:
parent
c09eabbc8b
commit
44ae65a65c
@ -145,7 +145,7 @@
|
||||
"shell-path": "2.1.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"screen-snippet": "git+https://github.com/symphonyoss/ScreenSnippet.git#v1.0.7",
|
||||
"screen-snippet": "git+https://github.com/symphonyoss/ScreenSnippet.git#v1.0.8",
|
||||
"swift-search": "2.0.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { app } from 'electron';
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
@ -9,8 +9,7 @@ import { IScreenSnippet } from '../common/api-interface';
|
||||
import { isDevEnv, isLinux, isMac } 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);
|
||||
|
||||
@ -18,13 +17,12 @@ class ScreenSnippet {
|
||||
private readonly tempDir: string;
|
||||
private readonly captureUtil: string;
|
||||
private outputFileName: string | undefined;
|
||||
private isAlwaysOnTop: boolean;
|
||||
private captureUtilArgs: ReadonlyArray<string> | undefined;
|
||||
private child: ChildProcess | undefined;
|
||||
private focusedWindow: BrowserWindow | null = null;
|
||||
|
||||
constructor() {
|
||||
this.tempDir = os.tmpdir();
|
||||
this.isAlwaysOnTop = false;
|
||||
this.captureUtil = isMac ? '/usr/sbin/screencapture' : isDevEnv
|
||||
? path.join(__dirname,
|
||||
'../../node_modules/screen-snippet/bin/Release/ScreenSnippet.exe')
|
||||
@ -47,18 +45,13 @@ class ScreenSnippet {
|
||||
this.captureUtilArgs = isMac
|
||||
? [ '-i', '-s', '-t', 'png', this.outputFileName ]
|
||||
: [ this.outputFileName, i18n.getLocale() ];
|
||||
this.focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
|
||||
if (isLinux) {
|
||||
this.captureUtilArgs = ['-a', '-f', this.outputFileName];
|
||||
}
|
||||
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!`);
|
||||
@ -97,9 +90,6 @@ class ScreenSnippet {
|
||||
private execCmd(captureUtil: string, captureUtilArgs: ReadonlyArray<string>): Promise<ChildProcess> {
|
||||
return new Promise<ChildProcess>((resolve, reject) => {
|
||||
return this.child = execFile(captureUtil, captureUtilArgs, (error: ExecException | null) => {
|
||||
if (this.isAlwaysOnTop) {
|
||||
updateAlwaysOnTop(true, false);
|
||||
}
|
||||
if (error && error.killed) {
|
||||
// processs was killed, just resolve with no data.
|
||||
return reject(error);
|
||||
@ -137,6 +127,9 @@ class ScreenSnippet {
|
||||
? { message: `file does not exist`, type: 'ERROR' }
|
||||
: { message: `${error}`, type: 'ERROR' };
|
||||
} finally {
|
||||
if (this.focusedWindow && windowExists(this.focusedWindow)) {
|
||||
this.focusedWindow.moveTop();
|
||||
}
|
||||
// remove tmp file (async)
|
||||
if (this.outputFileName) {
|
||||
fs.unlink(this.outputFileName, (removeErr) => {
|
||||
|
Loading…
Reference in New Issue
Block a user