ELECTRON-1409 - Identify screens based on name instead of display_id for Windows (#745)

This commit is contained in:
Kiran Niranjan 2019-07-19 22:22:11 +05:30 committed by Vishwas Shashidhar
parent e1f7fa53d0
commit d54b5b2ae7
2 changed files with 36 additions and 2 deletions

View File

@ -283,6 +283,40 @@ describe('screen picker', () => {
expect(wrapper.find(applicationTabCustomSelector)).toHaveLength(0);
});
it('should show `screen-tab` for Windows when source name is Entire screen and display_id is not present', () => {
const env = require('../src/common/env');
const wrapper = shallow(React.createElement(ScreenPicker));
const entireScreenStateMock = {
sources: [
{ display_id: '', id: '1', name: 'Entire screen', thumbnail: undefined },
{ display_id: '', id: '2', name: 'Screen 2', thumbnail: undefined },
{ display_id: '', id: '3', name: 'screen 3', thumbnail: undefined },
],
};
env.isWindowsOS = true;
env.isMac = false;
wrapper.setState(entireScreenStateMock);
expect(wrapper.find(screenTabCustomSelector)).toHaveLength(1);
expect(wrapper.find(applicationTabCustomSelector)).toHaveLength(0);
});
it('should not show `screen-tab` for Mac when source name is Entire screen and display_id is not present', () => {
const env = require('../src/common/env');
const wrapper = shallow(React.createElement(ScreenPicker));
const entireScreenStateMock = {
sources: [
{ display_id: '', id: '1', name: 'Entire screen', thumbnail: undefined },
{ display_id: '', id: '2', name: 'Screen 2', thumbnail: undefined },
{ display_id: '', id: '3', name: 'screen 3', thumbnail: undefined },
],
};
env.isWindowsOS = false;
env.isMac = true;
wrapper.setState(entireScreenStateMock);
expect(wrapper.find(screenTabCustomSelector)).toHaveLength(0);
expect(wrapper.find(applicationTabCustomSelector)).toHaveLength(1);
});
it('should show `screen-tab` and `application-tab` when `isScreensAvailable` and `isApplicationsAvailable` is true', () => {
const wrapper = shallow(React.createElement(ScreenPicker));
const customState = {

View File

@ -3,7 +3,7 @@ import { ipcRenderer } from 'electron';
import * as React from 'react';
import { apiCmds, apiName } from '../../common/api-interface';
import { isWindowsOS } from '../../common/env';
import { isMac, isWindowsOS } from '../../common/env';
import { i18n } from '../../common/i18n-preload';
const screenRegExp = new RegExp(/^Screen \d+$/gmi);
@ -131,7 +131,7 @@ export default class ScreenPicker extends React.Component<{}, IState> {
'ScreenPicker-item-container',
{ 'ScreenPicker-selected': this.shouldHighlight(source.id) },
);
if (source.display_id !== '') {
if ((isMac && source.display_id !== '') || (isWindowsOS && (source.name === 'Entire screen' || screenRegExp.exec(source.name)))) {
source.fileName = 'fullscreen';
let sourceName;
if (source.name === 'Entire screen') {