Permalink
Browse files

Merge pull request #157 from marcoceppi/unity-web-apps

Unity web apps
  • Loading branch information...
2 parents 6ad6891 + a7d6e5b commit 4b46d78244f85621bfe987946f4cea22bb047aff @thedjpetersen committed Sep 14, 2012
Showing with 39 additions and 1 deletion.
  1. +17 −1 assets/js/client.js
  2. +14 −0 assets/js/collections.js
  3. +8 −0 assets/js/views/chat_application.js
View
@@ -14,18 +14,33 @@
window.irc = {
socket: io.connect(null, {port: PORT}),
chatWindows: new WindowList(),
+ connected: false,
+ loggedIn: false
+};
+
+window.unity = {
+ api: external.getUnityObject(1.0),
connected: false
};
$(function() {
// window.app = new ChatApplicationRouter;
irc.appView = new ChatApplicationView();
+
+ window.unity.init({
+ name: "Subay IRC",
+ iconUrl: window.location.protocol+"//"+window.location.host+"/assets/images/subway.png",
+ onInit: function() {
+ window.unity.connected = true;
+ }
+ });
+
// EVENTS //
// **TODO**: is there a better place for this to go?
$(window).bind('beforeunload', function() {
- if(!window.irc.connected) { return null; }
+ if(!window.irc.connected || window.irc.loggedIn) { return null; }
return "If you leave, you'll be signed out of Subway.";
});
@@ -56,6 +71,7 @@ $(function() {
irc.socket.on('login_success', function(data) {
if(data.exists){
irc.socket.emit('connect', {});
+ window.irc.loggedIn = true;
} else {
$('#overview').html(ich.overview_connection());
}
@@ -69,6 +69,20 @@ var WindowList = Backbone.Collection.extend({
return count;
}
+ unreadByChannel: function() {
+ var channels = this.byType('channel');
+ var pms = this.byType('pm');
+
+ var windowCounts = {};
+ $.each(channels, function(key, chat) {
+ windowCounts[chat.get('name')] = chat.get('unread');
+ });
+
+ $.each(pms, function(key, pm) {
+ windowCounts[pm.get('name')] = pm.get('unread');
+ });
+
+ return windowCounts;
});
var UserList = Backbone.Collection.extend({
@@ -65,8 +65,16 @@ var ChatApplicationView = Backbone.View.extend({
var unreads = irc.chatWindows.unreadCount();
if (unreads > 0)
document.title = '(' + unreads + ') ' + this.originalTitle;
+ if( window.unity.connected ) {
+ window.unity.api.Launcher.setCount(unreads);
+ window.unity.api.Launcher.setUrgent(true);
+ }
else
document.title = this.originalTitle;
+ if( window.unity.connected ) {
+ window.unity.api.Launcher.clearCount();
+ window.unity.api.Launcher.setUrgent(false);
+ }
},
playSound: function(type) {

0 comments on commit 4b46d78

Please sign in to comment.