desktop notifications à la gmail notifications in chrome

Third-party modifications and add-ons, Apps and Clients

Moderator: moderators

desktop notifications à la gmail notifications in chrome

Postby chris.h » Thu Jan 27, 2011 2:23 pm

http://gmailblog.blogspot.com/2011/01/d ... s-and.html

It would be awesome if there was an option for turning on desktop notifications for song changes. Something along the lines of how gmail now can notify you of new emails when using chrome.
chris.h
 
Posts: 13
Joined: Tue Nov 17, 2009 12:52 am

Postby station » Mon Jan 31, 2011 7:18 pm

This would probably best be implemented as a google chrome extension, or a userscript (like Greasemonkey scripts).

I might poke around and try to figure out how to hook into the javascript events being fired on the page, but I'd love for someone to guide me!
station
 
Posts: 4
Joined: Mon Jan 31, 2011 7:15 pm

Postby station » Tue Feb 22, 2011 12:55 am

I didn't end up creating a Chrome extension, but I did modify subsonic's files on the server directly to add notifications.

    - Stop subsonic
    - Find the subsonic program files. On Windows this was in the "Program Files" folder
    - Extract the subsonic.war file somewhere convenient. I used the program 7-Zip for this.
    - Open the file WEB-INF\jsp\playlist.jsp for editing
    - Add this line to the end of the end of the "skip" function:
    Code: Select all
    setNotification(song);

    - Add the following after that function:
    Code: Select all
    function setNotification(song)
       {
          var n;

          //webkitNotifications
          if (window.webkitNotifications.checkPermission() != 0)
          {
             setAllowNotification();
             return 0;
          }

          n = window.webkitNotifications.createNotification('/icons/now_playing.png', song.title, song.artist + ' - ' + song.album);
          n.ondisplay = function() {
                   setTimeout(function(){
                      n.cancel();
                   },5000); };
          n.show();
       }
       
       function setAllowNotification()
       {
          window.webkitNotifications.requestPermission(permissionGranted);
       }

       function permissionGranted()
       {
          if (window.webkitNotifications.checkPermission() == 0)
             setNotification();
       }

    - Zip the contents of the unzipped folder back up into subsonic.war and place it in the subsonic program files folder
    - Restart subsonic


I used these sites for the notification code:
http://www.210computing.com/google/chro ... tions.html
http://sandbox.gtaero.net/chrome/notifications.php
station
 
Posts: 4
Joined: Mon Jan 31, 2011 7:15 pm

Postby Tanner Williamson » Wed Feb 23, 2011 12:57 am

@station

This would be great to have in the Mods forum if it's not there already.
Tanner Williamson https://www.tannerwilliamson.com/

Image
Tanner Williamson
 
Posts: 51
Joined: Mon Dec 14, 2009 7:30 am

Postby donpearson » Wed Feb 23, 2011 4:03 pm

Moved to Mods :wink:
Facebook Group:
http://www.facebook.com/groups/subsonic.group/

Image
donpearson
 
Posts: 361
Joined: Wed Oct 15, 2008 3:53 pm
Location: UK

Postby mmilburn » Mon Apr 11, 2011 2:33 pm

Thank you for this modification! It's probably my favorite thus far.

Any idea how I can link to the cover art for the new track?
mmilburn
 
Posts: 1
Joined: Thu Oct 21, 2010 3:04 pm

Postby achoo5000 » Thu Apr 14, 2011 4:17 am

So i've made this into a google chrome userscript (like greasemonkey).

It's a totally terrible hack-job, but it works basically. I just did it so people wouldn't need to edit their subsonic files. It would be much nicer to be built-in though for sure.

I've even updated it from above to put the album art (sort of*) into the popup.

Installation instructions:

1. Copy code below into a file called subsonicchromenotifications.user.js
2. change @match line to point to your subsonic server.
3. drag into chrome and follow instructions given by chrome.

Like above, the first time you listen to a song, it will ask for confirmation to make notifications, click allow.

Code: Select all
// ==UserScript==
// @name           Subsonic Chrome Notifications
// @namespace      http://www.activeobjects.no/subsonic/forum/viewforum.php?f=8
// @description    Uses chrome desktop notifications to display song title information while using Subsonic
// @match          http://<subsonichostname>/*
// ==/UserScript==

var pathname = window.location.pathname

if (pathname.substring(pathname.length-13,pathname.length) == 'playlist.view'){
   
    function addFunction(func, exec) {
        var script = document.createElement("script");
        script.setAttribute("type", "application/javascript");
        script.textContent = (exec ? "(" : "") + func.toString() + (exec ? ")();" : "");
        setTimeout(function() {
            document.head.appendChild(script)
        },500);
    }
   
    // this function is run with access to the real browser environment.
    inject = function() {
        // store the original skip (hopefully to preserve functionality for future changes to subsonic)
        skip_orig = skip;

        // add new skip with notification
        skip = function(index) {
            skip_orig(index);
            setNotification(songs[getCurrentSongIndex()]);
        };

        // notification functions
        setNotification = function(song) {
            var n;

            //webkitNotifications
            if (window.webkitNotifications.checkPermission() != 0) {
                setAllowNotification();
                return 0;
            }
           
            // get album art from nowPlatingService, and create the notification inside the callback
           
            window.parent.right.nowPlayingService.getNowPlaying(function(nowPlaying) {
               
                var imgUrl = 'icons/now_playing.png';
               
                for (var j = 0; j<nowPlaying.length; j++){
                    if(nowPlaying[j].artist == song.artist) {
                        imgUrl = nowPlaying[j].coverArtUrl;
                        break;
                    }
                }
                n = window.webkitNotifications.createNotification(imgUrl, song.title, song.artist + ' - ' + song.album);
               
                n.ondisplay = function() {
                    setTimeout(function() {
                        n.cancel();
                    },5000);
                };

                n.show();
               
            });
        }
           
        setAllowNotification = function() {
            window.webkitNotifications.requestPermission(permissionGranted);
        }

        permissionGranted = function() {
            if (window.webkitNotifications.checkPermission() == 0)
                setNotification();
        }
    } //  end of injected code
   
    addFunction(inject,true);
}



*it tries to get the album-art, but I did it in a very shitty hacky way that should work most of the time but not always.
achoo5000
 
Posts: 29
Joined: Wed Mar 30, 2011 10:47 pm
Location: USA

more robust solution

Postby runebune » Wed Apr 27, 2011 1:29 pm

I have a solution to get it to work more often with your hacky script ;)
I noticed that the player need a little time to update itself. I first through it was a albumart download delay and cache issue.
I have also altered the condition where the albumart should be set:
if(nowPlaying[j].streamUrl == song.streamUrl)
instead of:
if(nowPlaying[j].artist == song.artist)
I will soon try to embed it into my server code


Code: Select all
// ==UserScript==
// @name           Subsonic Chrome Notifications
// @namespace      http://www.activeobjects.no/subsonic/forum/viewforum.php?f=8
// @description    Uses chrome desktop notifications to display song title information while using Subsonic
// @match          http://<subsonichostname>/*
// ==/UserScript==

var pathname = window.location.pathname

if (pathname.substring(pathname.length-13,pathname.length) == 'playlist.view'){
   
    function addFunction(func, exec) {
        var script = document.createElement("script");
        script.setAttribute("type", "application/javascript");
        script.textContent = (exec ? "(" : "") + func.toString() + (exec ? ")();" : "");
        setTimeout(function() {
            document.head.appendChild(script)
        },500);
    }
   
    // this function is run with access to the real browser environment.
    inject = function() {
        // store the original skip (hopefully to preserve functionality for future changes to subsonic)
        skip_orig = skip;

        // add new skip with notification
        skip = function(index) {
            skip_orig(index);
         //insert e small delay to let the player update the albumart url
            setTimeout('setNotification(songs[getCurrentSongIndex()])', 500);         
        };

        // notification functions
        setNotification = function(song) {
            var n;

            //webkitNotifications
            if (window.webkitNotifications.checkPermission() != 0) {
                setAllowNotification();
                return 0;
            }
           
            // get album art from nowPlatingService, and create the notification inside the callback
            window.parent.right.nowPlayingService.getNowPlaying(function(nowPlaying) {
               
                var imgUrl = '/icons/desktop_notification.png';
               
                for (var j = 0; j<nowPlaying.length; j++){
                    if(nowPlaying[j].streamUrl == song.streamUrl) {
                        imgUrl = nowPlaying[j].coverArtUrl;
                        break;
                    }
                }
                n = window.webkitNotifications.createNotification(imgUrl, song.title, song.artist + ' - ' + song.album);
               
                n.ondisplay = function() {
                    setTimeout(function() {
                        n.cancel();
                    },5000);
                };

                n.show();
               
            });
        }
           
        setAllowNotification = function() {
            window.webkitNotifications.requestPermission(permissionGranted);
        }

        permissionGranted = function() {
            if (window.webkitNotifications.checkPermission() == 0)
                setNotification();
        }
    } //  end of injected code
   
    addFunction(inject,true);
}
runebune
 
Posts: 1
Joined: Tue Apr 12, 2011 7:41 am

Postby achoo5000 » Wed Apr 27, 2011 8:42 pm

That's beautiful. Well done :D.
achoo5000
 
Posts: 29
Joined: Wed Mar 30, 2011 10:47 pm
Location: USA

Postby vividboarder » Thu Jun 02, 2011 7:54 pm

This is a great feature and would be awesome to see as an option in the player settings in Subsonic itself!

Sindre read these posts?

I checked out a branch and I might try it out later when I get the chance (a lot on my plate at the moment).
vividboarder
 
Posts: 18
Joined: Wed Sep 22, 2010 1:37 pm
Location: 223

Postby tricer » Tue Jun 07, 2011 6:45 pm

I created the .js file per the instructions and also changed @match. I dragged it into chrome and allowed the program when prompted.

It isn't working for me. Desktop notifications work for me from Gmail, but this doesn't.

Can anyone think of what else I may need to do?
tricer
 
Posts: 7
Joined: Thu Mar 17, 2011 1:09 pm

Postby kermit22 » Tue Jun 14, 2011 1:28 pm

tricer wrote:I created the .js file per the instructions and also changed @match. I dragged it into chrome and allowed the program when prompted.

It isn't working for me. Desktop notifications work for me from Gmail, but this doesn't.

Can anyone think of what else I may need to do?


Are you running Chrome in full screen mode? There is an addon confirmation bar that appears at the top of the screen that doesn't appear correctly while you are in full screen mode.
User avatar
kermit22
 
Posts: 218
Joined: Fri Feb 20, 2009 7:00 pm

Not working for me either...

Postby jacobthe4th » Thu Jun 16, 2011 2:03 pm

I created *js file as stated above, dragged it into my chrome browser. I allowed the install of the extension, as well as, permitted the server to post notifications...

No dice.

I had the previous notification running, no trouble.

Any clues?

I've flushed my cache, both in my browser as well as on my server.

Thanks,

Jacob
Subsonic V6.1.6 User - Lifetime Donation

- WHS 2011 (HP EX 490 - e7500 with 4GB RAM, 16TB HDD)
- 2,039 artists
- 9,121 albums
- 120,791 songs

All FLAC, All the time...
User avatar
jacobthe4th
 
Posts: 41
Joined: Thu Oct 07, 2010 2:23 pm
Location: US

Re: desktop notifications à la gmail notifications in chrome

Postby tsquillario » Fri Mar 09, 2012 12:47 am

I just happened to stumble on this thread while Googling for some related stuff. I'm implementing the Desktop Notifications in the MiniSub Chrome App. I'm in the process of coding and testing it right now. It will be included in the next version.

Chrome App
https://chrome.google.com/webstore/detail/jccdpflnecheidefpofmlblgebobbloc

Forum Thread
http://forum.subsonic.org/forum/viewtopic.php?f=8&t=7553
Jamstash Developer
Chrome App - https://chrome.google.com/webstore/detail/jccdpflnecheidefpofmlblgebobbloc
Beta Site - http://beta.jamstash.com
GitHub Project - https://github.com/tsquillario/Jamstash
User avatar
tsquillario
 
Posts: 206
Joined: Thu Jun 30, 2011 5:10 pm
Location: State College, PA

Re: desktop notifications à la gmail notifications in chrome

Postby tsquillario » Sat Mar 10, 2012 4:53 pm

tsquillario wrote:I just happened to stumble on this thread while Googling for some related stuff. I'm implementing the Desktop Notifications in the MiniSub Chrome App. I'm in the process of coding and testing it right now. It will be included in the next version.

Chrome App
https://chrome.google.com/webstore/detail/jccdpflnecheidefpofmlblgebobbloc

Forum Thread
http://forum.subsonic.org/forum/viewtopic.php?f=8&t=7553


I pushed this update today, it's on GitHub and the Chrome Web Store, check it out!
Jamstash Developer
Chrome App - https://chrome.google.com/webstore/detail/jccdpflnecheidefpofmlblgebobbloc
Beta Site - http://beta.jamstash.com
GitHub Project - https://github.com/tsquillario/Jamstash
User avatar
tsquillario
 
Posts: 206
Joined: Thu Jun 30, 2011 5:10 pm
Location: State College, PA


Return to Mods, Apps and Clients

Who is online

Users browsing this forum: No registered users and 6 guests