mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
chore(notify) new -> module.exports
This commit is contained in:
parent
ab196b35a6
commit
3d05a6ee1e
1 changed files with 33 additions and 38 deletions
|
|
@ -4,48 +4,43 @@
|
|||
|
||||
const Events = require('./events');
|
||||
|
||||
module.exports = new Notify();
|
||||
let Show;
|
||||
|
||||
function Notify() {
|
||||
let Show;
|
||||
Events.add({
|
||||
'blur': () => {
|
||||
Show = true;
|
||||
},
|
||||
'focus': () => {
|
||||
Show = false;
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.send = (msg) => {
|
||||
const notifications = CloudCmd.config('notifications');
|
||||
const focus = window.focus.bind(window);
|
||||
const granted = check();
|
||||
|
||||
const Notify = this;
|
||||
const Notification = window.Notification;
|
||||
if (!notifications || !granted || !Show)
|
||||
return;
|
||||
|
||||
Events.add({
|
||||
'blur': () => {
|
||||
Show = true;
|
||||
},
|
||||
'focus': () => {
|
||||
Show = false;
|
||||
}
|
||||
const notify = new Notification(msg, {
|
||||
icon: '/img/favicon/favicon-notify.png'
|
||||
});
|
||||
|
||||
Events.addClick(notify, focus);
|
||||
};
|
||||
|
||||
module.exports.check = check;
|
||||
|
||||
function check() {
|
||||
const Not = Notification;
|
||||
const perm = Not && Not.permission;
|
||||
|
||||
this.send = (msg) => {
|
||||
const notifications = CloudCmd.config('notifications');
|
||||
const focus = window.focus.bind(window);
|
||||
const granted = Notify.check();
|
||||
|
||||
if (notifications && granted && Show) {
|
||||
const notify = new Notification(msg, {
|
||||
icon: '/img/favicon/favicon-notify.png'
|
||||
});
|
||||
|
||||
Events.addClick(notify, focus);
|
||||
}
|
||||
};
|
||||
|
||||
this.check = () => {
|
||||
const Not = Notification;
|
||||
const perm = Not && Not.permission;
|
||||
|
||||
if (perm === 'granted')
|
||||
return true;
|
||||
};
|
||||
|
||||
this.request = () => {
|
||||
if (Notification)
|
||||
Notification.requestPermission();
|
||||
};
|
||||
return perm === 'granted';
|
||||
}
|
||||
|
||||
module.exports.request = () => {
|
||||
if (Notification)
|
||||
Notification.requestPermission();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue