Skip to content

Commit

Permalink
Notification fix. It works now!
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor44 committed Jul 11, 2024
1 parent ecf927a commit 754cb27
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 63 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
8 changes: 1 addition & 7 deletions packages/app/src/app-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,8 @@ export class BrowserXAppWorker {
this.mainWindowManager.on('swipe-left', () => this.dispatch(executeWebviewMethodForCurrentTab('go-back')));
this.mainWindowManager.on('swipe-right', () => this.dispatch(executeWebviewMethodForCurrentTab('go-forward')));
this.mainWindowManager.on('new-notification', (notificationId: string, props: NotificationProps, options: NotificationOptions) => {


require('electron-log').log('>>>>>> New notification 10', (new Date()).toLocaleTimeString(), notificationId);


this.dispatch(notificationCenter.newNotification(undefined, undefined, notificationId, props, options))
}
);
});
}

private initSDK() {
Expand Down
44 changes: 0 additions & 44 deletions packages/app/src/notification-center/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,52 +110,18 @@ function* sagaResetSnooze(action: ResetSnoozeDurationAction): SagaIterator {
}

function* sagaNewNotification(action: NewNotificationAction): SagaIterator {


console.log('>>>>>> New notification 20', (new Date()).toLocaleTimeString(), action.notificationId);


// Call listeners
const { notifications }: DeprecatedSDKProvider = yield call(getProvider);


console.log('>>>>>> New notification 21', (new Date()).toLocaleTimeString(), action.notificationId);


const [e, tamperedAction] = yield call([notifications, notifications.callNew], action);


console.log('>>>>>> New notification 22', (new Date()).toLocaleTimeString(), action.notificationId);


if (e.isDefaultPrevented()) return;
const { applicationId, tabId, notificationId, options, props: { title, timestamp, body, icon } } = tamperedAction;


console.log('>>>>>> New notification 23', (new Date()).toLocaleTimeString(), action.notificationId);


yield put(addNotification(
notificationId,
{ applicationId, tabId, title, timestamp, body, icon,
full: options.full, silent: options.silent, webContentsId: options.webContentsId }
));


console.log('>>>>>> New notification 24', (new Date()).toLocaleTimeString(), action.notificationId);


yield put(appendNotification(notificationId));


console.log('>>>>>> New notification 25', (new Date()).toLocaleTimeString(), action.notificationId);


yield put(showNotification(notificationId));

console.log('>>>>>> New notification 30', (new Date()).toLocaleTimeString(), action.notificationId);


}

function* sagaShowNotification(action: ShowNotificationAction): SagaIterator {
Expand Down Expand Up @@ -187,11 +153,6 @@ const notificationClickChannel = (notif: RPC.Node<OSNotification>) => eventChann
});

function* sagaNotificationClick(action: NotificationClickAction): SagaIterator {


console.log('>>>>>> sagaNotificationClick');


const { notificationId } = action;
// Mark notification as read
yield put(markAsRead(notificationId));
Expand Down Expand Up @@ -246,11 +207,6 @@ function* interceptNotificationEventsFromWebContents({ webcontentsId, tabId }: {
}));
}


require('electron-log').log('>>>>>> New notification 12', (new Date()).toLocaleTimeString(), props.id);



yield put(newNotification(applicationId, tabId, props.id, props));
});

Expand Down
8 changes: 5 additions & 3 deletions packages/app/src/services/services/os-notification/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Notification, webContents } from 'electron';
import log from 'electron-log';

import { ServiceSubscription } from '../../lib/class';
import { RPC } from '../../lib/types';
Expand All @@ -8,6 +9,9 @@ import { getDoNotDisturb, asNativeImage } from './utils';
export class OSNotificationServiceImpl extends OSNotificationService implements RPC.Interface<OSNotificationService> {

async show(param: IOSNotificationServiceShowParam) {

log.info(`>>> OSNotificationServiceImpl.show ${JSON.stringify(param)}`);

const notificationOptions: Electron.NotificationConstructorOptions = {
title: param.title,
actions: [],
Expand All @@ -24,13 +28,11 @@ export class OSNotificationServiceImpl extends OSNotificationService implements

const notification = new Notification(notificationOptions);
notification.show();

return new OSNotificationImpl(notification);
}

async triggerClick(webContentsId: number, notificationId: string) {

console.log('OSNotificationServiceImpl.triggerClick', webContentsId, notificationId);

try {
const myWebcontent = webContents.fromId(webContentsId);
if (!myWebcontent) return;
Expand Down
13 changes: 10 additions & 3 deletions packages/app/src/services/services/os-notification/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import * as memoize from 'memoizee';

export const asNativeImage = memoize((url: string): Promise<Electron.NativeImage> => {
return new Promise((resolve, reject) => {
if (url.indexOf('data:') === 0) {
if (url.startsWith('data:')) {
resolve(nativeImage.createFromDataURL(url));
return;
}

if (url.indexOf('http:') === 0 || url.indexOf('https:') === 0) {
if (url.startsWith('http:') || url.startsWith('https:')) {
fetch(url)
.then((res: any) => res.buffer())
.then((buffer: Buffer) => {
Expand All @@ -19,9 +19,16 @@ export const asNativeImage = memoize((url: string): Promise<Electron.NativeImage
return;
}

if (url.startsWith('blob:http')) {
//FIXME: implement blob:https:// ( Telegram notifications )
resolve(nativeImage.createEmpty());
return;
}

try {
resolve(nativeImage.createFromPath(url));
} catch (e) {
}
catch (e) {
reject(new Error(`Unknow schema for ${url}`));
}
});
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const enhanceSession = (session: Session) => {

if (responseHeaders) {
delete responseHeaders['content-security-policy']; //vk: causes "This document requires 'TrustedHTML' assignment." error. Does not allow us to modify page CSS.
delete responseHeaders['content-security-policy-report-only'];
}

callback({
Expand Down
10 changes: 9 additions & 1 deletion packages/app/src/static/preload/webview-inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,19 @@ class BxNotification {
})
);

let fixedIconUrl = this.icon;
if (typeof fixedIconUrl === 'string') {
//vk: I have no idea why but...
if (fixedIconUrl.startsWith('//')) { // Gmail
fixedIconUrl = 'https:' + this.icon;
}
}

window.bxApi.notificationCenter.sendNotification(this.id, {
timestamp: this.timestamp,
title: this.title,
body: this.body,
icon: this.icon,
icon: fixedIconUrl,
});
}

Expand Down
5 changes: 0 additions & 5 deletions packages/app/src/windows/utils/GenericWindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ export default class GenericWindowManager extends EventEmitter {
self.emit('context-menu', params);
},
onNewNotification(notificationId: string, props: NotificationProps) {


require('electron-log').log('>>>>>> New notification 11', (new Date()).toLocaleTimeString(), notificationId);


self.emit('new-notification', notificationId, props, {
webContentsId,
});
Expand Down

0 comments on commit 754cb27

Please sign in to comment.