notifications: clearAlert
This commit is contained in:
+6
-2
@@ -168,7 +168,7 @@ async function getConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function reboot() {
|
async function reboot() {
|
||||||
await notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', '');
|
await notifications.clearAlert(notifications.ALERT_REBOOT, 'Reboot Required');
|
||||||
|
|
||||||
const [error] = await safe(shell.promises.sudo('reboot', [ REBOOT_CMD ], {}));
|
const [error] = await safe(shell.promises.sudo('reboot', [ REBOOT_CMD ], {}));
|
||||||
if (error) debug('reboot: could not reboot', error);
|
if (error) debug('reboot: could not reboot', error);
|
||||||
@@ -198,7 +198,11 @@ async function checkMailStatus() {
|
|||||||
|
|
||||||
async function checkRebootRequired() {
|
async function checkRebootRequired() {
|
||||||
const rebootRequired = await isRebootRequired();
|
const rebootRequired = await isRebootRequired();
|
||||||
await notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', rebootRequired ? 'To finish ubuntu security updates, a reboot is necessary.' : '');
|
if (rebootRequired) {
|
||||||
|
await notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', 'To finish ubuntu security updates, a reboot is necessary.');
|
||||||
|
} else {
|
||||||
|
await notifications.clearAlert(notifications.ALERT_REBOOT, 'Reboot Required');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkUbuntuVersion() {
|
async function checkUbuntuVersion() {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ exports = module.exports = {
|
|||||||
ALERT_MANUAL_APP_UPDATE: 'manualAppUpdate',
|
ALERT_MANUAL_APP_UPDATE: 'manualAppUpdate',
|
||||||
|
|
||||||
alert,
|
alert,
|
||||||
|
clearAlert,
|
||||||
|
|
||||||
// exported for testing
|
// exported for testing
|
||||||
_add: add
|
_add: add
|
||||||
@@ -233,7 +234,6 @@ async function alert(id, title, message) {
|
|||||||
|
|
||||||
const result = await getByTitle(title);
|
const result = await getByTitle(title);
|
||||||
|
|
||||||
if (message) {
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return await add(null /* eventId */, title, message);
|
return await add(null /* eventId */, title, message);
|
||||||
} else {
|
} else {
|
||||||
@@ -246,10 +246,15 @@ async function alert(id, title, message) {
|
|||||||
});
|
});
|
||||||
return result.id;
|
return result.id;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// id is unused but nice to search code
|
||||||
|
async function clearAlert(id, title) {
|
||||||
|
assert.strictEqual(typeof id, 'string');
|
||||||
|
assert.strictEqual(typeof title, 'string');
|
||||||
|
|
||||||
await database.query('DELETE FROM notifications WHERE title = ?', [ title ]);
|
await database.query('DELETE FROM notifications WHERE title = ?', [ title ]);
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onEvent(id, action, source, data) {
|
async function onEvent(id, action, source, data) {
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ describe('Notifications', function () {
|
|||||||
expect(result.acknowledged).to.be(false); // notification resurfaces
|
expect(result.acknowledged).to.be(false); // notification resurfaces
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can delete the alert', async function () {
|
it('can clear the alert', async function () {
|
||||||
const id = await notifications.alert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available', '');
|
const id = await notifications.clearAlert(notifications.ALERT_BOX_UPDATE, 'Cloudron xx is available');
|
||||||
expect(id).to.be(null);
|
expect(id).to.be(null);
|
||||||
|
|
||||||
const result = await notifications.get(alertId);
|
const result = await notifications.get(alertId);
|
||||||
|
|||||||
Reference in New Issue
Block a user