<commit_before>(ns frontend.notifications
  (:require [frontend.utils :as utils :include-macros true]
            [goog.events]))

(defn notifiable-browser? [] (exists? (.-Notification js/window)))
(defn notifications-permission [] (.-permission js/Notification))
(defn notifications-granted?  [] (= (notifications-permission) "granted"))

(defn request-permission
  ([]
   (request-permission (fn [result] (utils/mlog "Notifications are now: " result))))
  ([callback]
   (-> js/Notification
       (.requestPermission)
       (.then callback))))

;; Some notes about properties
;; - The title should be 32 characters MAX, note that if using system default,
;;   only 22 chars are visible on hover (because of resulting UI), so keep
;;   critical information 22 chars
;; - The body property should be a MAX of 42 characters (this is assuming a
;;   default text size with San Francisco, the default system font on macOS)
(defn notify [title properties]
  (when (notifications-granted?)
    (let [new-notification (js/Notification.
                             title
                             (clj->js (assoc
                                        properties
                                        :lang "en")))]
      (goog.events/listen
        new-notification
        "click"
        (fn [event]
          (.preventDefault event)<commit_msg>fix undefined "Notification" on iOS Safari<commit_after>(ns frontend.notifications
  (:require [frontend.utils :as utils :include-macros true]
            [goog.events]))

(defn notifiable-browser? [] (exists? (.-Notification js/window)))
(defn notifications-permission [] (when (notifiable-browser?)
                                    (.-permission js/Notification)))
(defn notifications-granted?  [] (= (notifications-permission) "granted"))

(defn request-permission
  ([]
   (request-permission (fn [result] (utils/mlog "Notifications are now: " result))))
  ([callback]
   (-> js/Notification
       (.requestPermission)
       (.then callback))))

;; Some notes about properties
;; - The title should be 32 characters MAX, note that if using system default,
;;   only 22 chars are visible on hover (because of resulting UI), so keep
;;   critical information 22 chars
;; - The body property should be a MAX of 42 characters (this is assuming a
;;   default text size with San Francisco, the default system font on macOS)
(defn notify [title properties]
  (when (notifications-granted?)
    (let [new-notification (js/Notification.
                             title
                             (clj->js (assoc
                                        properties
                                        :lang "en")))]
      (goog.events/listen
        new-notification
        "click"
        (fn [event]
          (.preventDefault event)
{'fraction_non_alphanumeric': 0.11023622047244094, 'fraction_numerical': 0.00572655690765927, 'mean_word_length': 2.33134684147795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3814677', 'n_tokens_mistral': 727, 'n_tokens_neox': 685, 'n_words': 244}