refactor: use for-of
instead of for
simple array iteration (#39338)
This commit is contained in:
parent
67523a47b4
commit
3d45429667
5 changed files with 20 additions and 20 deletions
|
@ -194,8 +194,8 @@ const messageBox = (sync: boolean, window: BrowserWindow | null, options?: Messa
|
||||||
if (cancelId == null) {
|
if (cancelId == null) {
|
||||||
// If the defaultId is set to 0, ensure the cancel button is a different index (1)
|
// If the defaultId is set to 0, ensure the cancel button is a different index (1)
|
||||||
cancelId = (defaultId === 0 && buttons.length > 1) ? 1 : 0;
|
cancelId = (defaultId === 0 && buttons.length > 1) ? 1 : 0;
|
||||||
for (let i = 0; i < buttons.length; i++) {
|
for (const [i, button] of buttons.entries()) {
|
||||||
const text = buttons[i].toLowerCase();
|
const text = button.toLowerCase();
|
||||||
if (text === 'cancel' || text === 'no') {
|
if (text === 'cancel' || text === 'no') {
|
||||||
cancelId = i;
|
cancelId = i;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -60,8 +60,8 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt
|
||||||
const sources = await desktopCapturer.getSources({ types: ['screen'] });
|
const sources = await desktopCapturer.getSources({ types: ['screen'] });
|
||||||
expect(sources).to.be.an('array').of.length(displays.length);
|
expect(sources).to.be.an('array').of.length(displays.length);
|
||||||
|
|
||||||
for (let i = 0; i < sources.length; i++) {
|
for (const [i, source] of sources.entries()) {
|
||||||
expect(sources[i].display_id).to.equal(displays[i].id.toString());
|
expect(source.display_id).to.equal(displays[i].id.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -133,14 +133,14 @@ describe('renderer nodeIntegrationInSubFrames', () => {
|
||||||
|
|
||||||
const generateConfigs = (webPreferences: any, ...permutations: {name: string, webPreferences: any}[]) => {
|
const generateConfigs = (webPreferences: any, ...permutations: {name: string, webPreferences: any}[]) => {
|
||||||
const configs = [{ webPreferences, names: [] as string[] }];
|
const configs = [{ webPreferences, names: [] as string[] }];
|
||||||
for (let i = 0; i < permutations.length; i++) {
|
for (const permutation of permutations) {
|
||||||
const length = configs.length;
|
const length = configs.length;
|
||||||
for (let j = 0; j < length; j++) {
|
for (let j = 0; j < length; j++) {
|
||||||
const newConfig = Object.assign({}, configs[j]);
|
const newConfig = Object.assign({}, configs[j]);
|
||||||
newConfig.webPreferences = Object.assign({},
|
newConfig.webPreferences = Object.assign({},
|
||||||
newConfig.webPreferences, permutations[i].webPreferences);
|
newConfig.webPreferences, permutation.webPreferences);
|
||||||
newConfig.names = newConfig.names.slice(0);
|
newConfig.names = newConfig.names.slice(0);
|
||||||
newConfig.names.push(permutations[i].name);
|
newConfig.names.push(permutation.name);
|
||||||
configs.push(newConfig);
|
configs.push(newConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,16 +313,16 @@ function bitsToBuffer (bits) {
|
||||||
|
|
||||||
function generateEBML (json) {
|
function generateEBML (json) {
|
||||||
const ebml = [];
|
const ebml = [];
|
||||||
for (let i = 0; i < json.length; i++) {
|
for (const item of json) {
|
||||||
if (!('id' in json[i])) {
|
if (!('id' in item)) {
|
||||||
// already encoded blob or byteArray
|
// already encoded blob or byteArray
|
||||||
ebml.push(json[i]);
|
ebml.push(item);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = json[i].data;
|
let data = item.data;
|
||||||
if (typeof data === 'object') data = generateEBML(data);
|
if (typeof data === 'object') data = generateEBML(data);
|
||||||
if (typeof data === 'number') data = ('size' in json[i]) ? numToFixedBuffer(data, json[i].size) : bitsToBuffer(data.toString(2));
|
if (typeof data === 'number') data = ('size' in item) ? numToFixedBuffer(data, item.size) : bitsToBuffer(data.toString(2));
|
||||||
if (typeof data === 'string') data = strToBuffer(data);
|
if (typeof data === 'string') data = strToBuffer(data);
|
||||||
|
|
||||||
const len = data.size || data.byteLength || data.length;
|
const len = data.size || data.byteLength || data.length;
|
||||||
|
@ -335,7 +335,7 @@ function generateEBML (json) {
|
||||||
// going to fix this, i'm probably just going to write some hacky thing which
|
// going to fix this, i'm probably just going to write some hacky thing which
|
||||||
// converts that string into a buffer-esque thing
|
// converts that string into a buffer-esque thing
|
||||||
|
|
||||||
ebml.push(numToBuffer(json[i].id));
|
ebml.push(numToBuffer(item.id));
|
||||||
ebml.push(bitsToBuffer(size));
|
ebml.push(bitsToBuffer(size));
|
||||||
ebml.push(data);
|
ebml.push(data);
|
||||||
}
|
}
|
||||||
|
@ -349,13 +349,13 @@ function toFlatArray (arr, outBuffer) {
|
||||||
if (outBuffer == null) {
|
if (outBuffer == null) {
|
||||||
outBuffer = [];
|
outBuffer = [];
|
||||||
}
|
}
|
||||||
for (let i = 0; i < arr.length; i++) {
|
for (const item of arr) {
|
||||||
if (typeof arr[i] === 'object') {
|
if (typeof item === 'object') {
|
||||||
// an array
|
// an array
|
||||||
toFlatArray(arr[i], outBuffer);
|
toFlatArray(item, outBuffer);
|
||||||
} else {
|
} else {
|
||||||
// a simple element
|
// a simple element
|
||||||
outBuffer.push(arr[i]);
|
outBuffer.push(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outBuffer;
|
return outBuffer;
|
||||||
|
|
|
@ -74,14 +74,14 @@ crashReporter.start({
|
||||||
// https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md
|
// https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md
|
||||||
|
|
||||||
getSources({ types: ['window', 'screen'] }).then(sources => {
|
getSources({ types: ['window', 'screen'] }).then(sources => {
|
||||||
for (let i = 0; i < sources.length; ++i) {
|
for (const source of sources) {
|
||||||
if (sources[i].name === 'Electron') {
|
if (source.name === 'Electron') {
|
||||||
(navigator as any).webkitGetUserMedia({
|
(navigator as any).webkitGetUserMedia({
|
||||||
audio: false,
|
audio: false,
|
||||||
video: {
|
video: {
|
||||||
mandatory: {
|
mandatory: {
|
||||||
chromeMediaSource: 'desktop',
|
chromeMediaSource: 'desktop',
|
||||||
chromeMediaSourceId: sources[i].id,
|
chromeMediaSourceId: source.id,
|
||||||
minWidth: 1280,
|
minWidth: 1280,
|
||||||
maxWidth: 1280,
|
maxWidth: 1280,
|
||||||
minHeight: 720,
|
minHeight: 720,
|
||||||
|
|
Loading…
Reference in a new issue