Merge pull request #1275 from johankwarnmarksymphony/sda-3418

Only use our native screen-snippet tool on Windows
This commit is contained in:
Johan Kwarnmark 2021-10-25 13:21:52 +02:00 committed by GitHub
commit c509db990a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 42 deletions

View File

@ -177,7 +177,7 @@
},
"optionalDependencies": {
"auto-update": "file:auto_update",
"screen-snippet": "git+https://github.com/symphonyoss/ScreenSnippet2.git#v2.4.0",
"screen-snippet": "git+https://github.com/symphonyoss/ScreenSnippet2.git#9.2.2",
"screen-share-indicator-frame": "git+https://github.com/symphonyoss/ScreenShareIndicatorFrame.git#v1.4.10",
"swift-search": "2.0.3"
},

View File

@ -1,4 +1,4 @@
import { app, BrowserWindow, clipboard, ipcMain, nativeImage } from 'electron';
import { app, BrowserWindow, ipcMain, nativeImage } from 'electron';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
@ -28,7 +28,6 @@ const readFile = util.promisify(fs.readFile);
class ScreenSnippet {
private readonly tempDir: string;
private readonly isOldWindows: boolean;
private outputFilePath: string | undefined;
private captureUtil: string;
private captureUtilArgs: ReadonlyArray<string>;
@ -45,16 +44,6 @@ class ScreenSnippet {
fs.mkdirSync(this.tempDir);
}
}
this.isOldWindows =
isWindowsOS &&
(parseInt(os.release().split('.')[0], 10) < 10 ||
parseInt(os.release().split('.')[2], 10) < 15002);
logger.info(
`screen-snippet-handler: isOldWindows ${
this.isOldWindows
} os.release: ${os.release()}`,
);
this.captureUtil = '';
this.captureUtilArgs = [];
@ -96,13 +85,14 @@ class ScreenSnippet {
'symphonyImage-' + Date.now() + '.png',
);
let usingClipboard = false;
if (isMac) {
logger.info('screen-snippet-handler: Mac');
this.captureUtil = '/usr/sbin/screencapture';
this.captureUtilArgs = ['-i', '-s', '-t', 'png', this.outputFilePath];
} else if (isWindowsOS) {
logger.info('screen-snippet-handler: Windows');
if (windowHandler.isMana) {
if (this.isOldWindows) {
logger.info('screen-snippet-handler: Mana, no native annotate');
this.captureUtil = isDevEnv
? path.join(
__dirname,
@ -114,11 +104,6 @@ class ScreenSnippet {
this.outputFilePath,
i18n.getLocale(),
];
} else {
this.captureUtil = 'SnippingTool';
this.captureUtilArgs = ['/clip'];
usingClipboard = true;
}
} else {
this.captureUtil = isDevEnv
? path.join(
@ -147,17 +132,8 @@ class ScreenSnippet {
this.killChildProcess();
}
try {
if (usingClipboard) {
logger.info(
`screen-snippet-handler: Using clipboard when capturing screen snippet`,
);
clipboard.clear();
await this.execCmd(this.captureUtil, this.captureUtilArgs);
fs.writeFileSync(this.outputFilePath, clipboard.readImage().toPNG());
clipboard.clear();
} else {
await this.execCmd(this.captureUtil, this.captureUtilArgs);
}
if (windowHandler.isMana) {
logger.info(
'screen-snippet-handler: Attempting to extract image dimensions from: ' +