"use strict"; const _ = require("lodash"); const render_compose_notification = require("../templates/compose_notification.hbs"); const render_notification = require("../templates/notification.hbs"); const alert_words = require("./alert_words"); const favicon = require("./favicon"); const people = require("./people"); const settings_config = require("./settings_config"); const stream_ui_updates = require("./stream_ui_updates"); const notice_memory = new Map(); // When you start Zulip, window_focused should be true, but it might not be the // case after a server-initiated reload. let window_focused = document.hasFocus && document.hasFocus(); let supports_sound; 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) .on("focus", () => { window_focused = 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(); }) .on("blur", () => { window_focused = false; }); const audio = $("