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. 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 // Expose only expected IPC wrapper APIs to the renderer process to avoid
// handing out generalised messaging access. // handing out generalised messaging access.
@ -39,21 +39,21 @@ const CHANNELS = [
contextBridge.exposeInMainWorld( contextBridge.exposeInMainWorld(
"electron", "electron",
{ {
on(channel, listener) { on(channel: string, listener: (event: IpcRendererEvent, ...args: any[]) => void) {
if (!CHANNELS.includes(channel)) { if (!CHANNELS.includes(channel)) {
console.error(`Unknown IPC channel ${channel} ignored`); console.error(`Unknown IPC channel ${channel} ignored`);
return; return;
} }
ipcRenderer.on(channel, listener); ipcRenderer.on(channel, listener);
}, },
send(channel, ...args) { send(channel: string, ...args: any[]) {
if (!CHANNELS.includes(channel)) { if (!CHANNELS.includes(channel)) {
console.error(`Unknown IPC channel ${channel} ignored`); console.error(`Unknown IPC channel ${channel} ignored`);
return; return;
} }
ipcRenderer.send(channel, ...args); ipcRenderer.send(channel, ...args);
}, },
async getDesktopCapturerSources(options) { async getDesktopCapturerSources(options: SourcesOptions) {
const sources = await desktopCapturer.getSources(options); const sources = await desktopCapturer.getSources(options);
const desktopCapturerSources = []; const desktopCapturerSources = [];