import $ from "jquery"; import _ from "lodash"; import render_compose_notification from "../templates/compose_notification.hbs"; import render_notification from "../templates/notification.hbs"; import * as alert_words from "./alert_words"; import * as blueslip from "./blueslip"; import * as channel from "./channel"; import * as favicon from "./favicon"; import * as message_store from "./message_store"; import * as muting from "./muting"; import * as narrow from "./narrow"; import * as narrow_state from "./narrow_state"; import * as navigate from "./navigate"; import * as people from "./people"; import * as settings_config from "./settings_config"; import * as spoilers from "./spoilers"; import * as stream_data from "./stream_data"; import * as stream_ui_updates from "./stream_ui_updates"; import * as ui from "./ui"; import * as unread from "./unread"; import * as unread_ops from "./unread_ops"; 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; export function set_notification_api(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; } export function get_notifications() { 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"; } export function initialize() { $(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 = $("