Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Friday, January 28, 2011

Notifications in Chrome

Some of us would be familiar, and piqued, by the recent suggestion in our Gmail windows: "Click here to enable mail notifications in Chrome". Choose to, and whichever tab you might be browsing on, any new mail or chat message is reported in a tiny corner bottom right of the screen. This nifty addition surprised me enough to find out more about the concept, and its other possible applications.

Notifications to the desktop are nothing new, but notifications on the browser are.
The OSX folks have had something called Growl notifications in place, which requires installation, then could be accessed through the windows.fluid object built into Safari on Mac.

Google, with their support for Web Notifications, and their W3C recommendation in general, have tried standardizing this concept.
Here's a small working example for the same:

PS: Try it, in baby steps, on Jash. FUN!
<script type="text/javascript">
(function() {
var notificationStatus;

setupNotifications = function() {
if(window.webkitNotifications) {
if(window.webkitNotifications.checkPermission() == 0 ) { //permission granted
notificationStatus = 'Permission granted';
} else if(window.webkitNotifications.checkPermission() == 1 ) { //permission unknown
//notificationStatus = 'Permission not granted yet';
notificationStatus = "Unknown, click to <a href='javascript:window.webkitNotifications.requestPermission(setupNotifications);'>enable web notifications</a>.";
window.webkitNotifications.requestPermission(setupNotifications);
} else { //permission denied
notificationStatus = 'Permission denied';
}
} else alert('Not supported');

if(!!document.getElementById("notificationStatus"))
document.getElementById("notificationStatus").innerHTML = notificationStatus;
}

notifyMe = function() {
//permission already granted
if(window.webkitNotifications.checkPermission() == 0 ) {
var popup = window.webkitNotifications.createNotification(
"myicon.ico",
"You nailed it",
"My good sir, by delving into this notification thingy you open yourself to plenty of bobfoolery"
);
//ondisplay is one of the three events for the notification API
// ondisplay, onerror, oncancel
popup.ondisplay = function() {
setTimeout(function () {popup.cancel();}, 6000);
//we keep a timeout for the notification, since they don't have one by default
};
popup.show(); //this displays the notification
}
}
window.onload = setupNotifications;
})();
</script>
A simplified concept, a small API, and user security considerations - the spec has its bases covered. Presently these notifications only work on the Chrome browser across Windows and Linux.
For the old crowd, things were ridiculous, with the programmers having to resort to annoying and invasive hacks like window.alert. This new feature would give online tools like e-mail clients, calendering software, task managers, monitoring systems, etc. an elegant and consistent way to notify users.

However, not everybody is gaga over it. After some toying around, even I am a bit skeptical about the specs and the architecture: The notifications take a while to associate with their tab. They aren't a welcome experience to deal with when your friends start firing messages in your gmail chat window. Moreover, with the proliferation of these (among Tier 1 sites, to merely begin with) we can only anticipate an avalanche of these, since the recommendation suggests no way to restrict or control the notifications.

Thursday, May 8, 2008

PHP Woes: Getting pspell to work

The pspell extension allows some language tools like spell checking and similar-word recommendations.

To get pspell working, Aspell is required. Aspell is an OpenSource spellchecker, that has become the preferred one, replacing pspell and Ispell. Only the name remains, pspell functions in PHP are waiting to be renamed to Aspell ones.

I'm listing out the following steps for a Windows-specific installation. This has nothing to do with the server you're using (IIS or Apache)


  1. Get the Windows port of Aspell from http://aspell.net/win32/ (v0.50.3 installer here)
  2. Alongside, download a language dictionary as well (English dictionary here)
  3. Install Aspell followed by the language dictionary

  4. Make aspell-15.dll and pspell-15.dll available to PHP by either
    • Adding your Aspell bin directory (C:/Program Files/Aspell/bin in my case) to system's PATH variable OR
    • Copying the files to your PHP folder (C:/PHP in my case), if your PHP folder is already listed in PATH variable OR
    • Copying the files to windows folder (C:/Windows/) or system folder (C:/Windows/System32/)

  5. Enable the pspell extension in your php.ini file
    • Open your php.ini (generally in the PHP root folder or in Windows folder)
    • Firstly, make sure you have pspell.dll in your extentions folder (configured by variable 'extension_dir' in php.ini)
    • scroll down to where your extensions are listed, and decomment (remove the semicolon) so it looks like extension=php_pspell.dll - doing so enables the extension
    • Parsing of the ini file is cranky on some systems, so make sure that the above line goes to top of other commented/disabled extentions.


  6. Restart your server. It reloads the PHP module, which in turn reads the ini file and loads respective extensions again.

  7. Test if working: Saving as little code as <?php $pspell = pspell_new('en'); ?> in a script, and executing the script should do it.