Merge pull request #1139 from johankwarnmarksymphony/preview_screen_share

fix: Preview screen share
This commit is contained in:
Johan Kwarnmark 2020-12-07 18:13:30 +01:00 committed by GitHub
commit 6282c52890
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 43 deletions

View File

@ -1091,6 +1091,59 @@ export class WindowHandler {
} }
} }
/**
* Draw red frame on shared screen application
*
*/
public drawScreenShareIndicatorFrame(source) {
const displays = electron.screen.getAllDisplays();
logger.info('window-utils: displays.length: ' + displays.length);
for (let i = 0, len = displays.length; i < len; i++) {
logger.info(
'window-utils: display[' + i + ']: ' + JSON.stringify(displays[i]),
);
}
if (source != null) {
logger.info('window-handler: drawScreenShareIndicatorFrame');
if (isWindowsOS || isMac) {
const type = source.id.split(':')[0];
if (type === 'window') {
const hwnd = source.id.split(':')[1];
this.execCmd(this.screenShareIndicatorFrameUtil, [hwnd]);
} else if (isMac && type === 'screen') {
const dispId = source.id.split(':')[1];
this.execCmd(this.screenShareIndicatorFrameUtil, [dispId]);
} else if (isWindowsOS && type === 'screen') {
logger.info(
'window-handler: source.display_id: ' + source.display_id,
);
if (source.display_id !== '') {
this.execCmd(this.screenShareIndicatorFrameUtil, [
source.display_id,
]);
} else {
const dispId = source.id.split(':')[1];
const clampedDispId = Math.min(dispId, displays.length - 1);
const keyId = 'id';
logger.info('window-utils: dispId: ' + dispId);
logger.info('window-utils: clampedDispId: ' + clampedDispId);
logger.info(
'window-utils: displays [' +
clampedDispId +
'] [id]: ' +
displays[clampedDispId][keyId],
);
this.execCmd(this.screenShareIndicatorFrameUtil, [
displays[clampedDispId][keyId].toString(),
]);
}
}
}
}
}
/** /**
* Creates a screen picker window * Creates a screen picker window
* *
@ -1140,52 +1193,19 @@ export class WindowHandler {
}); });
this.addWindow(opts.winKey, this.screenPickerWindow); this.addWindow(opts.winKey, this.screenPickerWindow);
}); });
ipcMain.once('screen-source-selected', (_event, source) => {
const displays = electron.screen.getAllDisplays();
logger.info('window-utils: displays.length: ' + displays.length);
for (let i = 0, len = displays.length; i < len; i++) {
logger.info(
'window-utils: display[' + i + ']: ' + JSON.stringify(displays[i]),
);
}
ipcMain.on('screen-source-select', (_event, source) => {
if (source != null) { if (source != null) {
logger.info(`window-handler: screen-source-selected`, source, id); logger.info(`window-handler: screen-source-select`, source, id);
if (isWindowsOS || isMac) {
const type = source.id.split(':')[0]; this.drawScreenShareIndicatorFrame(source);
if (type === 'window') {
const hwnd = source.id.split(':')[1];
this.execCmd(this.screenShareIndicatorFrameUtil, [hwnd]);
} else if (isMac && type === 'screen') {
const dispId = source.id.split(':')[1];
this.execCmd(this.screenShareIndicatorFrameUtil, [dispId]);
} else if (isWindowsOS && type === 'screen') {
logger.info(
'window-handler: source.display_id: ' + source.display_id,
);
if (source.display_id !== '') {
this.execCmd(this.screenShareIndicatorFrameUtil, [
source.display_id,
]);
} else {
const dispId = source.id.split(':')[1];
const clampedDispId = Math.min(dispId, displays.length - 1);
const keyId = 'id';
logger.info('window-utils: dispId: ' + dispId);
logger.info('window-utils: clampedDispId: ' + clampedDispId);
logger.info(
'window-utils: displays [' +
clampedDispId +
'] [id]: ' +
displays[clampedDispId][keyId],
);
this.execCmd(this.screenShareIndicatorFrameUtil, [
displays[clampedDispId][keyId].toString(),
]);
}
}
}
} }
});
ipcMain.once('screen-source-selected', (_event, source) => {
logger.info(`window-handler: screen-source-selected`, source, id);
this.drawScreenShareIndicatorFrame(source);
window.send('start-share' + id, source); window.send('start-share' + id, source);
if (this.screenPickerWindow && windowExists(this.screenPickerWindow)) { if (this.screenPickerWindow && windowExists(this.screenPickerWindow)) {
@ -1193,6 +1213,7 @@ export class WindowHandler {
} }
}); });
this.screenPickerWindow.once('closed', () => { this.screenPickerWindow.once('closed', () => {
this.execCmd(this.screenShareIndicatorFrameUtil, []);
this.removeWindow(opts.winKey); this.removeWindow(opts.winKey);
this.screenPickerWindow = null; this.screenPickerWindow = null;
}); });

View File

@ -278,6 +278,10 @@ export default class ScreenPicker extends React.Component<{}, IState> {
*/ */
private select(selectedSource: ICustomDesktopCapturerSource): void { private select(selectedSource: ICustomDesktopCapturerSource): void {
this.setState({ selectedSource }); this.setState({ selectedSource });
if (selectedSource) {
ipcRenderer.send('screen-source-select', selectedSource);
}
} }
/** /**