Fix Notifier imports in NotificationControllers
require() is a bit weird for riot-web's webpack, so we fork it out to its own function to reduce the weirdness. The added weirdness is that require() is sync though exports a module instead. If we use import(), we get a promise which doesn't help us here. We therefore have to require() and pull out the default export, though this is only a problem for webpack - babel (our chosen compiler for exporting ES6) doesn't need this, hence the if statement.
This commit is contained in:
parent
615648af13
commit
18ac2db2ea
1 changed files with 11 additions and 10 deletions
|
@ -34,10 +34,15 @@ function isMasterRuleEnabled() {
|
|||
return !masterRule.enabled;
|
||||
}
|
||||
|
||||
function getNotifier() {
|
||||
let Notifier = require('../../Notifier'); // avoids cyclical references
|
||||
if (Notifier.default) Notifier = Notifier.default; // correct for webpack require() weirdness
|
||||
return Notifier;
|
||||
}
|
||||
|
||||
export class NotificationsEnabledController extends SettingController {
|
||||
getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) {
|
||||
const Notifier = require('../../Notifier'); // avoids cyclical references
|
||||
if (!Notifier.isPossible()) return false;
|
||||
if (!getNotifier().isPossible()) return false;
|
||||
|
||||
if (calculatedValue === null || calculatedAtLevel === "default") {
|
||||
return isMasterRuleEnabled();
|
||||
|
@ -47,18 +52,15 @@ export class NotificationsEnabledController extends SettingController {
|
|||
}
|
||||
|
||||
onChange(level, roomId, newValue) {
|
||||
const Notifier = require('../../Notifier'); // avoids cyclical references
|
||||
|
||||
if (Notifier.supportsDesktopNotifications()) {
|
||||
Notifier.setEnabled(newValue);
|
||||
if (getNotifier().supportsDesktopNotifications()) {
|
||||
getNotifier().setEnabled(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class NotificationBodyEnabledController extends SettingController {
|
||||
getValueOverride(level, roomId, calculatedValue) {
|
||||
const Notifier = require('../../Notifier'); // avoids cyclical references
|
||||
if (!Notifier.isPossible()) return false;
|
||||
if (!getNotifier().isPossible()) return false;
|
||||
|
||||
if (calculatedValue === null) {
|
||||
return isMasterRuleEnabled();
|
||||
|
@ -70,8 +72,7 @@ export class NotificationBodyEnabledController extends SettingController {
|
|||
|
||||
export class AudioNotificationsEnabledController extends SettingController {
|
||||
getValueOverride(level, roomId, calculatedValue) {
|
||||
const Notifier = require('../../Notifier'); // avoids cyclical references
|
||||
if (!Notifier.isPossible()) return false;
|
||||
if (!getNotifier().isPossible()) return false;
|
||||
|
||||
// Note: Audio notifications are *not* enabled by default.
|
||||
return calculatedValue;
|
||||
|
|
Loading…
Reference in a new issue