From e1a16e186f6715595fb6d4696971b275613e48b7 Mon Sep 17 00:00:00 2001 From: bingenito Date: Mon, 11 Jun 2018 09:00:00 -0400 Subject: [PATCH] Provide default implementation of showNotification for Electron that simply delegates to Electron. This still requires a polyfill to be provided (example in app.js) for Windows 7 --- src/Electron/electron.ts | 11 ++++++++++- tests/unit/Electron/electron.spec.ts | 13 +++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Electron/electron.ts b/src/Electron/electron.ts index 51a3093c..ca3449d4 100644 --- a/src/Electron/electron.ts +++ b/src/Electron/electron.ts @@ -371,7 +371,16 @@ export class ElectronContainer extends WebContainerBase { } public showNotification(title: string, options?: NotificationOptions) { - throw new TypeError("showNotification requires an implementation."); + const Notification = this.electron.Notification; + const notify = new Notification(Object.assign(options || {}, { title: title })); + if (options["onClick"]) { + notify.addListener("click", options["onClick"]); + } + if (options["notification"]) { + notify.once("show", () => notify.addListener("click", options["notification"]["onclick"])); + } + + notify.show(); } public addTrayIcon(details: TrayIconDetails, listener: () => void, menuItems?: MenuItem[]) { diff --git a/tests/unit/Electron/electron.spec.ts b/tests/unit/Electron/electron.spec.ts index 2192b2b5..a65ec3e8 100644 --- a/tests/unit/Electron/electron.spec.ts +++ b/tests/unit/Electron/electron.spec.ts @@ -339,6 +339,13 @@ describe("ElectronContainer", () => { Menu: { buildFromTemplate: (menuItems: any) => { } }, + Notification: (options: any) => { + return { + show: () => {}, + addListener: () => {}, + once: () => {} + } + }, require: (type: string) => { return {} }, getCurrentWindow: () => { return windows[0]; } }; @@ -441,8 +448,10 @@ describe("ElectronContainer", () => { }); describe("notifications", () => { - it("showNotification throws not implemented", () => { - expect(() => container.showNotification("title", {})).toThrowError(TypeError); + it("showNotification delegates to electron notification", () => { + spyOn(electron, "Notification").and.callThrough(); + container.showNotification("title", { onClick: () => {}, notification: { } }); + expect(electron.Notification).toHaveBeenCalledWith({ title: "title", onClick: jasmine.any(Function), notification: jasmine.any(Object) }); }); it("requestPermission granted", (done) => {