diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz index 79c161a..5f80d61 100644 Binary files a/.yarn/install-state.gz and b/.yarn/install-state.gz differ diff --git a/packages/app/package.json b/packages/app/package.json index 6afc545..e904a20 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -68,7 +68,6 @@ "electron-better-web-request": "^1.0.1", "electron-chrome-extension": "https://github.com/viktor44/electron-chrome-extension/releases/download/v6.0.3/release.tar.gz", "electron-debug": "^3.2.0", - "electron-fetch": "^1.9.1", "electron-log": "^2.2.14", "electron-process-manager": "^1.0.0", "electron-process-reporter": "1.4.0", diff --git a/packages/app/src/services/services/os-notification/main.ts b/packages/app/src/services/services/os-notification/main.ts index cf1ec2f..975ab3c 100644 --- a/packages/app/src/services/services/os-notification/main.ts +++ b/packages/app/src/services/services/os-notification/main.ts @@ -1,5 +1,5 @@ import { Notification, webContents } from 'electron'; -import log from 'electron-log'; +// import log from 'electron-log'; import { ServiceSubscription } from '../../lib/class'; import { RPC } from '../../lib/types'; @@ -10,7 +10,7 @@ export class OSNotificationServiceImpl extends OSNotificationService implements async show(param: IOSNotificationServiceShowParam) { - log.info(`>>> OSNotificationServiceImpl.show ${JSON.stringify(param)}`); + // log.info(`>>> OSNotificationServiceImpl.show ${JSON.stringify(param)}`); const notificationOptions: Electron.NotificationConstructorOptions = { title: param.title, diff --git a/packages/app/src/services/services/os-notification/utils.ts b/packages/app/src/services/services/os-notification/utils.ts index f6396d6..efc39a6 100644 --- a/packages/app/src/services/services/os-notification/utils.ts +++ b/packages/app/src/services/services/os-notification/utils.ts @@ -1,5 +1,4 @@ import { nativeImage } from 'electron'; -import fetch from 'electron-fetch'; import * as memoize from 'memoizee'; export const asNativeImage = memoize((url: string): Promise => { @@ -11,20 +10,12 @@ export const asNativeImage = memoize((url: string): Promise res.buffer()) - .then((buffer: Buffer) => { - resolve(nativeImage.createFromBuffer(buffer)); - }) + .then((res) => res.arrayBuffer()) + .then((arrayBuffer) => resolve(nativeImage.createFromBuffer(Buffer.from(arrayBuffer)))) .catch(reject); return; } - if (url.startsWith('blob:http')) { - //FIXME: implement blob:https:// ( Telegram notifications ) - resolve(nativeImage.createEmpty()); - return; - } - try { resolve(nativeImage.createFromPath(url)); } diff --git a/packages/app/src/static/preload/webview-inject.js b/packages/app/src/static/preload/webview-inject.js index 680c818..0601cc6 100644 --- a/packages/app/src/static/preload/webview-inject.js +++ b/packages/app/src/static/preload/webview-inject.js @@ -94,15 +94,15 @@ class BxNotification { this._registerIPC(); - console.log( - '>>>>>> New notification 1', (new Date()).toLocaleTimeString(), JSON.stringify({ - id: this.id, - timestamp: this.timestamp, - title: this.title, - body: this.body, - icon: this.icon, - }) - ); + const newNotification = { + id: this.id, + timestamp: this.timestamp, + title: this.title, + body: this.body, + icon: this.icon, + }; + + console.log('>>>>>> New notification 1', (new Date()).toLocaleTimeString(), JSON.stringify(newNotification)); let fixedIconUrl = this.icon; if (typeof fixedIconUrl === 'string') { @@ -110,12 +110,33 @@ class BxNotification { if (fixedIconUrl.startsWith('//')) { // Gmail fixedIconUrl = 'https:' + this.icon; } + else if (fixedIconUrl.startsWith('blob:http')) { // Telegram + const xhr = new XMLHttpRequest(); + xhr.responseType = 'blob'; + xhr.onreadystatechange = () => { + if (xhr.readyState === 4) { + const reader = new FileReader(); + reader.onload = function(event) { + window.bxApi.notificationCenter.sendNotification(this.id, { + ...newNotification, + icon: event.target.result, + }); + } + reader.readAsDataURL(xhr.response); + } + }; + xhr.open('GET', fixedIconUrl); + xhr.send(); + return; + } + } + else { + console.log('Unsupported notification icon type', (typeof fixedIconUrl)); + fixedIconUrl = undefined; } window.bxApi.notificationCenter.sendNotification(this.id, { - timestamp: this.timestamp, - title: this.title, - body: this.body, + ...newNotification, icon: fixedIconUrl, }); } diff --git a/yarn.lock b/yarn.lock index ad704f2..485b74f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -28863,7 +28863,6 @@ __metadata: electron-builder: "npm:^24.9.1" electron-chrome-extension: "https://github.com/viktor44/electron-chrome-extension/releases/download/v6.0.3/release.tar.gz" electron-debug: "npm:^3.2.0" - electron-fetch: "npm:^1.9.1" electron-log: "npm:^2.2.14" electron-mocha: "npm:^8.1.0" electron-process-manager: "npm:^1.0.0"