2017-11-13 19:00:15 +08:00
|
|
|
define([
|
|
|
|
'/common/visible.js',
|
|
|
|
'/common/notify.js'
|
|
|
|
], function (Visible, Notify) {
|
|
|
|
var Notifier = {};
|
|
|
|
|
|
|
|
var notify = {};
|
|
|
|
Notifier.unnotify = function () {
|
|
|
|
if (notify.tabNotification &&
|
|
|
|
typeof(notify.tabNotification.cancel) === 'function') {
|
|
|
|
notify.tabNotification.cancel();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-02 18:08:25 +08:00
|
|
|
Notifier.notify = function (data) {
|
2019-10-04 23:30:42 +08:00
|
|
|
if (Visible.isSupported() && (!Visible.currently() || (data && data.force))) {
|
2018-10-02 18:08:25 +08:00
|
|
|
if (data) {
|
|
|
|
var title = data.title;
|
|
|
|
if (document.title) { title += ' (' + document.title + ')'; }
|
|
|
|
Notify.system(data.msg, title);
|
|
|
|
return;
|
|
|
|
}
|
2017-11-13 19:00:15 +08:00
|
|
|
Notifier.unnotify();
|
|
|
|
notify.tabNotification = Notify.tab(1000, 10);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-02 18:08:25 +08:00
|
|
|
Notifier.getPermission = function () {
|
|
|
|
if (Notify.isSupported()) {
|
|
|
|
Notify.getPermission();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-13 19:00:15 +08:00
|
|
|
if (Visible.isSupported()) {
|
|
|
|
Visible.onChange(function (yes) {
|
|
|
|
if (yes) { Notifier.unnotify(); }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Notifier;
|
|
|
|
});
|