Convert preload.js to Typescript so that it gets copied to lib where we expect it

This commit is contained in:
Michael Telatynski 2021-07-01 09:11:42 +01:00
parent 0143b4b114
commit d353c68a75

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const { ipcRenderer, desktopCapturer, contextBridge } = require('electron');
import { ipcRenderer, desktopCapturer, contextBridge, IpcRendererEvent, SourcesOptions } from 'electron';
// Expose only expected IPC wrapper APIs to the renderer process to avoid
// handing out generalised messaging access.
@ -39,21 +39,21 @@ const CHANNELS = [
contextBridge.exposeInMainWorld(
"electron",
{
on(channel, listener) {
on(channel: string, listener: (event: IpcRendererEvent, ...args: any[]) => void) {
if (!CHANNELS.includes(channel)) {
console.error(`Unknown IPC channel ${channel} ignored`);
return;
}
ipcRenderer.on(channel, listener);
},
send(channel, ...args) {
send(channel: string, ...args: any[]) {
if (!CHANNELS.includes(channel)) {
console.error(`Unknown IPC channel ${channel} ignored`);
return;
}
ipcRenderer.send(channel, ...args);
},
async getDesktopCapturerSources(options) {
async getDesktopCapturerSources(options: SourcesOptions) {
const sources = await desktopCapturer.getSources(options);
const desktopCapturerSources = [];