зеркало из https://github.com/electron/electron.git
test: enable linting of ts-smoke and fix all issues (#37322)
This commit is contained in:
Родитель
ee87438d28
Коммит
e34cc6f48c
|
@ -22,10 +22,7 @@ process.env.PATH = `${process.env.PATH}${path.delimiter}${DEPOT_TOOLS}`;
|
|||
const IGNORELIST = new Set([
|
||||
['shell', 'browser', 'resources', 'win', 'resource.h'],
|
||||
['shell', 'common', 'node_includes.h'],
|
||||
['spec', 'fixtures', 'pages', 'jquery-3.6.0.min.js'],
|
||||
['spec', 'ts-smoke', 'electron', 'main.ts'],
|
||||
['spec', 'ts-smoke', 'electron', 'renderer.ts'],
|
||||
['spec', 'ts-smoke', 'runner.js']
|
||||
['spec', 'fixtures', 'pages', 'jquery-3.6.0.min.js']
|
||||
].map(tokens => path.join(ELECTRON_ROOT, ...tokens)));
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -6,67 +6,65 @@ import {
|
|||
clipboard,
|
||||
crashReporter,
|
||||
shell
|
||||
} from 'electron'
|
||||
|
||||
import * as fs from 'fs'
|
||||
} from 'electron';
|
||||
|
||||
// In renderer process (web page).
|
||||
// https://github.com/electron/electron/blob/main/docs/api/ipc-renderer.md
|
||||
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong"
|
||||
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
|
||||
|
||||
ipcRenderer.on('asynchronous-reply', (event, arg: any) => {
|
||||
console.log(arg) // prints "pong"
|
||||
event.sender.send('another-message', 'Hello World!')
|
||||
})
|
||||
console.log(arg); // prints "pong"
|
||||
event.sender.send('another-message', 'Hello World!');
|
||||
});
|
||||
|
||||
ipcRenderer.send('asynchronous-message', 'ping')
|
||||
ipcRenderer.send('asynchronous-message', 'ping');
|
||||
|
||||
// web-frame
|
||||
// https://github.com/electron/electron/blob/main/docs/api/web-frame.md
|
||||
|
||||
webFrame.setZoomFactor(2)
|
||||
console.log(webFrame.getZoomFactor())
|
||||
webFrame.setZoomFactor(2);
|
||||
console.log(webFrame.getZoomFactor());
|
||||
|
||||
webFrame.setZoomLevel(200)
|
||||
console.log(webFrame.getZoomLevel())
|
||||
webFrame.setZoomLevel(200);
|
||||
console.log(webFrame.getZoomLevel());
|
||||
|
||||
webFrame.setVisualZoomLevelLimits(50, 200)
|
||||
webFrame.setVisualZoomLevelLimits(50, 200);
|
||||
|
||||
webFrame.setSpellCheckProvider('en-US', {
|
||||
spellCheck (words, callback) {
|
||||
setTimeout(() => {
|
||||
const spellchecker = require('spellchecker')
|
||||
const misspelled = words.filter(x => spellchecker.isMisspelled(x))
|
||||
callback(misspelled)
|
||||
}, 0)
|
||||
const spellchecker = require('spellchecker');
|
||||
const misspelled = words.filter(x => spellchecker.isMisspelled(x));
|
||||
callback(misspelled);
|
||||
}, 0);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
webFrame.insertText('text')
|
||||
webFrame.insertText('text');
|
||||
|
||||
webFrame.executeJavaScript('return true;').then((v: boolean) => console.log(v))
|
||||
webFrame.executeJavaScript('return true;', true).then((v: boolean) => console.log(v))
|
||||
webFrame.executeJavaScript('return true;', true)
|
||||
webFrame.executeJavaScript('return true;', true).then((result: boolean) => console.log(result))
|
||||
webFrame.executeJavaScript('return true;').then((v: boolean) => console.log(v));
|
||||
webFrame.executeJavaScript('return true;', true).then((v: boolean) => console.log(v));
|
||||
webFrame.executeJavaScript('return true;', true);
|
||||
webFrame.executeJavaScript('return true;', true).then((result: boolean) => console.log(result));
|
||||
|
||||
console.log(webFrame.getResourceUsage())
|
||||
webFrame.clearCache()
|
||||
console.log(webFrame.getResourceUsage());
|
||||
webFrame.clearCache();
|
||||
|
||||
// clipboard
|
||||
// https://github.com/electron/electron/blob/main/docs/api/clipboard.md
|
||||
|
||||
clipboard.writeText('Example String')
|
||||
clipboard.writeText('Example String', 'selection')
|
||||
console.log(clipboard.readText('selection'))
|
||||
console.log(clipboard.availableFormats())
|
||||
clipboard.clear()
|
||||
clipboard.writeText('Example String');
|
||||
clipboard.writeText('Example String', 'selection');
|
||||
console.log(clipboard.readText('selection'));
|
||||
console.log(clipboard.availableFormats());
|
||||
clipboard.clear();
|
||||
|
||||
clipboard.write({
|
||||
html: '<html></html>',
|
||||
text: 'Hello World!',
|
||||
bookmark: 'Bookmark name',
|
||||
image: clipboard.readImage()
|
||||
})
|
||||
});
|
||||
|
||||
// crash-reporter
|
||||
// https://github.com/electron/electron/blob/main/docs/api/crash-reporter.md
|
||||
|
@ -76,14 +74,14 @@ crashReporter.start({
|
|||
companyName: 'YourCompany',
|
||||
submitURL: 'https://your-domain.com/url-to-submit',
|
||||
uploadToServer: true
|
||||
})
|
||||
});
|
||||
|
||||
// desktopCapturer
|
||||
// https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md
|
||||
|
||||
desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => {
|
||||
for (let i = 0; i < sources.length; ++i) {
|
||||
if (sources[i].name == 'Electron') {
|
||||
if (sources[i].name === 'Electron') {
|
||||
(navigator as any).webkitGetUserMedia({
|
||||
audio: false,
|
||||
video: {
|
||||
|
@ -96,18 +94,18 @@ desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => {
|
|||
maxHeight: 720
|
||||
}
|
||||
}
|
||||
}, gotStream, getUserMediaError)
|
||||
return
|
||||
}, gotStream, getUserMediaError);
|
||||
return;
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
function gotStream (stream: any) {
|
||||
(document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream)
|
||||
(document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream);
|
||||
}
|
||||
|
||||
function getUserMediaError (error: Error) {
|
||||
console.log('getUserMediaError', error)
|
||||
console.log('getUserMediaError', error);
|
||||
}
|
||||
|
||||
// File object
|
||||
|
@ -119,78 +117,81 @@ function getUserMediaError (error: Error) {
|
|||
</div>
|
||||
*/
|
||||
|
||||
const holder = document.getElementById('holder')
|
||||
const holder = document.getElementById('holder');
|
||||
|
||||
holder.ondragover = function () {
|
||||
return false
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
holder.ondragleave = holder.ondragend = function () {
|
||||
return false
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
holder.ondrop = function (e) {
|
||||
e.preventDefault()
|
||||
const file = e.dataTransfer.files[0]
|
||||
console.log('File you dragged here is', file.path)
|
||||
return false
|
||||
}
|
||||
e.preventDefault();
|
||||
const file = e.dataTransfer.files[0];
|
||||
console.log('File you dragged here is', file.path);
|
||||
return false;
|
||||
};
|
||||
|
||||
// nativeImage
|
||||
// https://github.com/electron/electron/blob/main/docs/api/native-image.md
|
||||
|
||||
const image = clipboard.readImage()
|
||||
const image = clipboard.readImage();
|
||||
console.log(image.getSize());
|
||||
|
||||
// https://github.com/electron/electron/blob/main/docs/api/process.md
|
||||
|
||||
// preload.js
|
||||
const _setImmediate = setImmediate
|
||||
const _clearImmediate = clearImmediate
|
||||
const _setImmediate = setImmediate;
|
||||
const _clearImmediate = clearImmediate;
|
||||
process.once('loaded', function () {
|
||||
global.setImmediate = _setImmediate
|
||||
global.clearImmediate = _clearImmediate
|
||||
})
|
||||
global.setImmediate = _setImmediate;
|
||||
global.clearImmediate = _clearImmediate;
|
||||
});
|
||||
|
||||
// shell
|
||||
// https://github.com/electron/electron/blob/main/docs/api/shell.md
|
||||
|
||||
shell.openExternal('https://github.com').then(() => {})
|
||||
shell.openExternal('https://github.com').then(() => {});
|
||||
|
||||
// <webview>
|
||||
// https://github.com/electron/electron/blob/main/docs/api/webview-tag.md
|
||||
|
||||
const webview = document.createElement('webview')
|
||||
webview.loadURL('https://github.com')
|
||||
const webview = document.createElement('webview');
|
||||
webview.loadURL('https://github.com');
|
||||
|
||||
webview.addEventListener('console-message', function (e) {
|
||||
console.log('Guest page logged a message:', e.message)
|
||||
})
|
||||
console.log('Guest page logged a message:', e.message);
|
||||
});
|
||||
|
||||
webview.addEventListener('found-in-page', function (e) {
|
||||
if (e.result.finalUpdate) {
|
||||
webview.stopFindInPage('keepSelection')
|
||||
webview.stopFindInPage('keepSelection');
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const requestId = webview.findInPage('test')
|
||||
const requestId = webview.findInPage('test');
|
||||
console.log(requestId);
|
||||
|
||||
webview.addEventListener('close', function () {
|
||||
webview.src = 'about:blank'
|
||||
})
|
||||
webview.src = 'about:blank';
|
||||
});
|
||||
|
||||
// In embedder page.
|
||||
webview.addEventListener('ipc-message', function (event) {
|
||||
console.log(event.channel) // Prints "pong"
|
||||
})
|
||||
webview.send('ping')
|
||||
webview.capturePage().then(image => { console.log(image) })
|
||||
console.log(event.channel); // Prints "pong"
|
||||
});
|
||||
webview.send('ping');
|
||||
webview.capturePage().then(image => { console.log(image); });
|
||||
|
||||
{
|
||||
const opened: boolean = webview.isDevToolsOpened()
|
||||
const focused: boolean = webview.isDevToolsFocused()
|
||||
}
|
||||
const opened = webview.isDevToolsOpened();
|
||||
console.log('isDevToolsOpened', opened);
|
||||
|
||||
const focused = webview.isDevToolsFocused();
|
||||
console.log('isDevToolsFocused', focused);
|
||||
|
||||
// In guest page.
|
||||
ipcRenderer.on('ping', function () {
|
||||
ipcRenderer.sendToHost('pong')
|
||||
})
|
||||
ipcRenderer.sendToHost('pong');
|
||||
});
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
const path = require('path')
|
||||
const childProcess = require('child_process')
|
||||
const path = require('path');
|
||||
const childProcess = require('child_process');
|
||||
|
||||
const typeCheck = () => {
|
||||
const tscExec = path.resolve(require.resolve('typescript'), '../../bin/tsc')
|
||||
const tscExec = path.resolve(require.resolve('typescript'), '../../bin/tsc');
|
||||
const tscChild = childProcess.spawn(process.execPath, [tscExec, '--project', './ts-smoke/tsconfig.json'], {
|
||||
cwd: path.resolve(__dirname, '../')
|
||||
})
|
||||
tscChild.stdout.on('data', d => console.log(d.toString()))
|
||||
tscChild.stderr.on('data', d => console.error(d.toString()))
|
||||
});
|
||||
tscChild.stdout.on('data', d => console.log(d.toString()));
|
||||
tscChild.stderr.on('data', d => console.error(d.toString()));
|
||||
tscChild.on('exit', (tscStatus) => {
|
||||
if (tscStatus !== 0) {
|
||||
process.exit(tscStatus)
|
||||
process.exit(tscStatus);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
typeCheck()
|
||||
typeCheck();
|
||||
|
|
Загрузка…
Ссылка в новой задаче