LibNotify-1.0

This library provides a simple way to show somewhat tolerable notifications. The library also provides a way to remember if the user has already seen a notification. Typical use cases:

 

Version checks - instead of spamming the chat window, pop a notification with "NotifyOnce", supplying your new version number as ID. If the user has seen the version notification before, it will be ignored.

 

Addon changelog - you can supply a table of notifications, one for each addon update you wish to inform the user about. Again, use "NotifyOnce" to only show it once. Each item in the table you supply is checked individually.

 

Other - spam away. The user will only ever see one notification at once.

 

API

self:Notify(title, message/function, icon) or self:Notify(table)

Queues a notification or a list of notifications to be shown. If supplying a table, the same keys should be supplied for each item. Message and icon can both be omitted.

If the title is too long for the notification window, it will be truncated.

The message can be HTML formatted, but note that WoW's HTML parser is very limited.

A function can be supplied instead of a message. The function will be executed when the user clicks on the notification.

 

self:NotifyOnce(title, message, icon, id) or self:Notify(table)

Queues a notification or a list of notifications to be shown.

 

The "id" parameter is used to identify notifications. If omitted, the title is used.

 

The storage must have been set first with SetNotifyStorage.

 

self:SetNotifyIcon(icon_path)

Sets the default icon to be used.

 

self:SetNotifyStorage(table)
Sets the storage to be used for saving which of your addon's notifications have been seen by the user. This would typically be somewhere in your user's saved variables. Technically you can of course also use a non-persistant storage if you wish for these notifications to possibly be shown in another playing session.

 

Examples

Basic usage

The library can be used standalone or embedded in an Ace3 addon.

 

Embedded example:

local addon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "LibNotify-1.0")
addon:Notify("Hello world!")

Standalone example:

local libnotify = LibStub("LibNotify-1.0")
libnotify.Notify(myaddon, "Hello world!")

Addon changelog

local addon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "LibNotify-1.0")
local seen_versions = {} -- This would probably point to your user's active profile
local versions = {
   {
     title = "MyAddon 1.1",
     message = "Added more stuff! Also, crackers.<br/>Fixed previous stuff."
   },
   {
     title = "MyAddon 1.0",
     message = "Added a lot of stuff."
   }
}
addon:SetNotifyIcon("Interface\\Icons\\Spell_Lightning_LightningBolt01")
addon:SetNotifyStorage(seen_versions)
addon:NotifyOnce(versions)

 

New version notification

-- find out the new version number by way of addon communication channel
-- and then notify user
local version = "1.0.0"
addon:NotifyOnce("MyAddon version " + version + " available!", "Be sure to check out the newest version, which has extra features and cats. Meow!", nil,version)

One-off notification

addon:Notify("Smurf alert!", "The smurfs are coming, lock your doors!", "Some fancy icon")

Locale support

This is out of the library's scope. You can simply pass in notification tables/parameters based on the user's locale. The library currently has one line of text by itself, the instructions in the notification frame, which is translated for most locales.


Comments

  • To post a comment, please or register a new account.
Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    257942
  • Created
    Jan 24, 2017
  • Last Released File
    Oct 14, 2020
  • Total Downloads
    13,858
  • License

Categories

Members

Recent Files

WoW Retail