notification-logger icon indicating copy to clipboard operation
notification-logger copied to clipboard

No icon on the demo website

Open Outpox opened this issue 9 years ago • 8 comments

image

Running on Linux Mint 18 with Google Chrome (53.0.2785.143)

Outpox avatar Oct 12 '16 15:10 Outpox

@Outpox This is also the case on OSX 10.12

mikeerickson avatar Oct 12 '16 16:10 mikeerickson

@Outpox Here is a quick and dirty fix (using a PD icon) You can change the icon property to anything that is available publicly should you wish to change the icon.

(function() {
    var isInitialized = false, _console = {};
    var icon = 'https://cdn2.iconfinder.com/data/icons/windows-8-metro-style/512/console.png'
    Notification.requestPermission();
    function log(body, title) {
        title = title || "Notification";
        if (!("Notification" in window)) {
            alert("This browser does not support desktop notification");
        } else if (Notification.permission === "granted") {
            new Notification(title ,{body: body, icon: icon});
        } else if (Notification.permission !== 'denied') {
            Notification.requestPermission(function (permission) {
                if (permission === "granted") {
                    new Notification(title ,{body: body, icon: icon});
                }
        });
      }
    }

    function genericLogger() {
        return function (body, title) {
            title = title || "Notification";
            if (!("Notification" in window)) {
                alert("This browser does not support desktop notification");
            } else if (Notification.permission === "granted") {
                new Notification(title ,{body: body, icon: icon});
            } else if (Notification.permission !== 'denied') {
                Notification.requestPermission(function (permission) {
                    if (permission === "granted") {
                        new Notification(title ,{body: body, icon: icon});
                    }
                });
            }
        }
    }

    function originalFnCallDecorator(fn, fnName) {
        return function() {
            fn.apply(this, arguments);
            if (typeof _console[fnName] === 'function') {
                _console[fnName].apply(console, arguments);
            }
        };
    }

    function destroy() {
        isInitialized = false;
        console.log = _console.log;
    }

    function init() {
        if (isInitialized) { return; }
            isInitialized = true;
        _console.log = console.log;
        console.log = originalFnCallDecorator(log, 'log');
    }

    window.logger = {
        log: log,
        init: init,
        destroy:destroy
    }
})();

mikeerickson avatar Oct 12 '16 16:10 mikeerickson

@Outpox I will be extending the package to provide ability to set icon

@hkirat The option to set the icon can be done by adding an options parameter (in addition to title and message parameters, or I can instead extend the entry point to accept an option 3rd parameter for icon

Possible signatures

function log(body[, title, icon])

or

function log(body[, title, options])

Where options would be a JS object

var options = {
  icon: 'validUrl',
  ...
}

The second object allows the developer to extend call to include whatever they see fit (see Notification API) for list of all possible properties.

@hkirat which method do you prefer. Don't want to keep the API simple, add the icon as parameter, make it more extensible, add options

mikeerickson avatar Oct 12 '16 18:10 mikeerickson

I think logger should have an icon variable ( logger.icon). If the user wants to modify it, there should be a function logger.modifyIcon(icon_address). Initially, the logger.icon should point to notifications.png that I have recently committed in the repo. So the first option, adding icon as a parameter and providing a function to the user, logger.modifyIcon

hkirat avatar Oct 12 '16 18:10 hkirat

@hkirat OK, sounds good. I will implement it the way you want.

mikeerickson avatar Oct 12 '16 19:10 mikeerickson

Any progress @mikeerickson ? Shouldn't be that difficult

hkirat avatar Oct 13 '16 16:10 hkirat

@hkirat Not a difficulty issue, more of a time issue. Have some deadlines for work that need to take priority :-)

mikeerickson avatar Oct 13 '16 16:10 mikeerickson

I've added a logo on the website for now. Whenever you get the time please make the changes. Thanks

hkirat avatar Oct 14 '16 07:10 hkirat