diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index afb4189b4..2d40a49f5 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -12,6 +12,21 @@ jobs:
fail-fast: false
steps:
+ - name: Setup DBUS environment
+ if: matrix.os == 'ubuntu-latest'
+ run: |
+ export DISPLAY=:0
+ sudo apt install dbus-x11
+ machineId=$(cat /var/lib/dbus/machine-id)
+ mkdir -p /home/runner/.dbus
+ mkdir -p /home/runner/.dbus/session-bus/
+ touch /home/runner/.dbus/session-bus/${machineId}-0
+ sudo dbus-launch --exit-with-session&
+ sleep 5 # Wait for the DBUS session to start
+ echo "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" > /home/runner/.dbus/session-bus/${machineId}-0
+ - name: 1
+ if: matrix.os == 'ubuntu-latest'
+ run: cat /home/runner/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0
- name: Set Timezone
uses: szenius/set-timezone@v1.1
with:
@@ -31,5 +46,6 @@ jobs:
- run: npx nyc --reporter=lcov npm test
env:
CI: true
+ DISPLAY: ':0'
- name: Codecov
uses: codecov/codecov-action@v3
diff --git a/.nvmrc b/.nvmrc
new file mode 100644
index 000000000..4a1f488b6
--- /dev/null
+++ b/.nvmrc
@@ -0,0 +1 @@
+18.17.1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f59ac85f7..72856ec07 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+### Fixed
+- improve DND monitoring memory usage
+
## [1.15.0] - 2023-11-11
### Added
- new end-of-the-break sound
diff --git a/app/preferences.html b/app/preferences.html
index 7f88a3613..c418c8e8e 100644
--- a/app/preferences.html
+++ b/app/preferences.html
@@ -69,7 +69,7 @@
-
+
diff --git a/app/utils/dndManager.js b/app/utils/dndManager.js
index 06f2c622d..54a0f99a9 100644
--- a/app/utils/dndManager.js
+++ b/app/utils/dndManager.js
@@ -8,6 +8,17 @@ class DndManager extends EventEmitter {
this.monitorDnd = settings.get('monitorDnd')
this.timer = null
this.isOnDnd = false
+
+ if (process.platform === 'win32') {
+ this.windowsFocusAssist = require('windows-focus-assist')
+ this.windowsQuietHours = require('windows-quiet-hours')
+ } else if (process.platform === 'darwin') {
+ this.macosNotificationState = require('macos-notification-state')
+ } else if (process.platform === 'linux') {
+ this.bus = require('dbus-final').sessionBus()
+ this.util = require('node:util')
+ }
+
if (this.monitorDnd) {
this.start()
}
@@ -31,10 +42,8 @@ class DndManager extends EventEmitter {
}
async _isDndEnabledLinux () {
- const dbus = require('dbus-final')
- const bus = dbus.sessionBus()
try {
- const obj = await bus.getProxyObject('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
+ const obj = await this.bus.getProxyObject('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
const properties = obj.getInterface('org.freedesktop.DBus.Properties')
const dndEnabled = await properties.Get('org.freedesktop.Notifications', 'Inhibited')
if (await dndEnabled.value) {
@@ -45,7 +54,7 @@ class DndManager extends EventEmitter {
}
try {
- const obj = await bus.getProxyObject('org.xfce.Xfconf', '/org/xfce/Xfconf')
+ const obj = await this.bus.getProxyObject('org.xfce.Xfconf', '/org/xfce/Xfconf')
const properties = obj.getInterface('org.xfce.Xfconf')
const dndEnabled = await properties.GetProperty('xfce4-notifyd', '/do-not-disturb')
if (await dndEnabled.value) {
@@ -56,8 +65,7 @@ class DndManager extends EventEmitter {
}
try {
- const util = require('node:util')
- const exec = util.promisify(require('node:child_process').exec)
+ const exec = this.util.promisify(require('node:child_process').exec)
const { stdout } = await exec('gsettings get org.gnome.desktop.notifications show-banners')
if (stdout.replace(/[^0-9a-zA-Z]/g, '') === 'false') {
return true
@@ -75,12 +83,12 @@ class DndManager extends EventEmitter {
if (process.platform === 'win32') {
let wfa = 0
try {
- wfa = require('windows-focus-assist').getFocusAssist().value
+ wfa = this.windowsFocusAssist.getFocusAssist().value
} catch (e) { wfa = -1 } // getFocusAssist() throw an error if OS isn't windows
- const wqh = require('windows-quiet-hours').getIsQuietHours()
+ const wqh = this.windowsQuietHours.getIsQuietHours()
return wqh || (wfa !== -1 && wfa !== 0)
} else if (process.platform === 'darwin') {
- return require('macos-notification-state').getDoNotDisturb()
+ return this.macosNotificationState.getDoNotDisturb()
} else if (process.platform === 'linux') {
return await this._isDndEnabledLinux()
}