const render_compose_notification = require('../templates/compose_notification.hbs'); const render_notification = require('../templates/notification.hbs'); const settings_config = require("./settings_config"); const notice_memory = new Map(); // When you start Zulip, window_has_focus should be true, but it might not be the // case after a server-initiated reload. let window_has_focus = document.hasFocus && document.hasFocus(); let supports_sound; const unread_pms_favicon = '/static/images/favicon/favicon-pms.png'; let current_favicon; let previous_favicon; let flashing = false; let NotificationAPI; exports.set_notification_api = function (n) { NotificationAPI = n; }; if (window.electron_bridge && window.electron_bridge.new_notification) { class ElectronBridgeNotification extends EventTarget { constructor(title, options) { super(); Object.assign( this, window.electron_bridge.new_notification(title, options, (type, eventInit) => this.dispatchEvent(new Event(type, eventInit)) ) ); } static get permission() { return Notification.permission; } static async requestPermission(callback) { if (callback) { callback(await Promise.resolve(Notification.permission)); } return Notification.permission; } } NotificationAPI = ElectronBridgeNotification; } else if (window.Notification) { NotificationAPI = window.Notification; } exports.get_notifications = function () { return notice_memory; }; function get_audio_file_path(audio_element, audio_file_without_extension) { if (audio_element.canPlayType('audio/ogg; codecs="vorbis"')) { return audio_file_without_extension + ".ogg"; } return audio_file_without_extension + ".mp3"; } exports.initialize = function () { $(window).focus(function () { window_has_focus = true; for (const notice_mem_entry of notice_memory.values()) { notice_mem_entry.obj.close(); } notice_memory.clear(); // Update many places on the DOM to reflect unread // counts. unread_ops.process_visible(); }).blur(function () { window_has_focus = false; }); const audio = $("