Skip to content

Commit

Permalink
electron - remove menu
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Aug 15, 2023
1 parent 223a35a commit e030f62
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
2 changes: 2 additions & 0 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async function createWindow() {
},
});

win.removeMenu();

if (tinyUrl) {
// electron-vite-vue#298
win.loadURL(tinyUrl);
Expand Down
59 changes: 51 additions & 8 deletions src/client/state/Notifications/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Capacitor } from '@capacitor/core';
import { LocalNotifications } from '@capacitor/local-notifications';
// import { Notification as ElectronNoti } from 'electron';

import EventEmitter from 'events';
import renderAvatar from '../../../app/atoms/avatar/render';
Expand Down Expand Up @@ -253,13 +254,16 @@ class Notifications extends EventEmitter {

async _displayPopupNoti(mEvent, room) {

// Data Prepare
const body = $('body');
const userStatus = getAccountStatus('status');
if (!settings.showNotifications && !settings.isNotificationSounds) return;

// Actions
const actions = this.matrixClient.getPushActionsForEvent(mEvent);
if (!actions?.notify) return;

// Check Window
if (
!body.hasClass('modal-open') &&
navigation.selectedRoomId === room.roomId &&
Expand All @@ -269,10 +273,12 @@ class Notifications extends EventEmitter {

if (userStatus === 'dnd' || userStatus === '🔴') return;

// Encrypted
if (mEvent.isEncrypted()) {
await mEvent.attemptDecryption(this.matrixClient.crypto);
}

// Show Notification
if (settings.showNotifications) {
let title;
if (!mEvent.sender || room.name === mEvent.sender.name) {
Expand Down Expand Up @@ -310,6 +316,7 @@ class Notifications extends EventEmitter {
body = plain(content.body, state);
}

// Android Mode
if (Capacitor.isNativePlatform()) {

/*
Expand All @@ -323,20 +330,53 @@ class Notifications extends EventEmitter {
]});
*/

} else {
}

// Browser and Desktop
else {

const noti = new window.Notification(title, {
// Prepare Data
const notiData = {
body: body.plain,
icon,
tag: mEvent.getId(),
silent: settings.isNotificationSounds,
});
};

// Silent Mode
let noti;
if (__ENV_APP__.electron_mode) {
notiData.silent = true;
// notiData.title = title;
// noti = new ElectronNoti(notiData);
noti = new window.Notification(title, notiData);
} else {
notiData.silent = settings.isNotificationSounds;
noti = new window.Notification(title, notiData);
}

if (__ENV_APP__.electron_mode) {

// Play Notification
if (settings.isNotificationSounds) {
// noti.on('click', () => this._playNotiSound());
noti.onshow = () => this._playNotiSound();
}

// noti.on('click', () => selectRoom(room.roomId, mEvent.getId()));
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());

} else {

// Play Notification
if (settings.isNotificationSounds) {
noti.onshow = () => this._playNotiSound();
}

noti.onclick = () => selectRoom(room.roomId, mEvent.getId());

if (settings.isNotificationSounds) {
noti.onshow = () => this._playNotiSound();
}
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());

// Set Event
this.eventIdToPopupNoti.set(mEvent.getId(), noti);
if (this.roomIdToPopupNotis.has(room.roomId)) {
this.roomIdToPopupNotis.get(room.roomId).push(noti);
Expand All @@ -346,7 +386,10 @@ class Notifications extends EventEmitter {

}

} else {
}

// Notification Sound Play
else {
this._playNotiSound();
}

Expand Down

0 comments on commit e030f62

Please sign in to comment.