Skip to content

Commit

Permalink
Merge pull request getstation#400 from viktor44/hotfix/notif_telegram…
Browse files Browse the repository at this point in the history
…_icon

Fix Telegram notification icons
  • Loading branch information
viktor44 authored Jul 13, 2024
2 parents 8d377c1 + 99fce8d commit 5d40de4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 0 additions & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/services/services/os-notification/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down
13 changes: 2 additions & 11 deletions packages/app/src/services/services/os-notification/utils.ts
Original file line number Diff line number Diff line change
@@ -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<Electron.NativeImage> => {
Expand All @@ -11,20 +10,12 @@ export const asNativeImage = memoize((url: string): Promise<Electron.NativeImage

if (url.startsWith('http:') || url.startsWith('https:')) {
fetch(url)
.then((res: any) => 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));
}
Expand Down
45 changes: 33 additions & 12 deletions packages/app/src/static/preload/webview-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,49 @@ 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') {
//vk: I have no idea why but...
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,
});
}
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5d40de4

Please sign in to comment.