diff --git a/src/preload.js b/src/preload.ts similarity index 86% rename from src/preload.js rename to src/preload.ts index 64849f5..491e8b9 100644 --- a/src/preload.js +++ b/src/preload.ts @@ -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 = [];