aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRael <rael.gc@gmail.com>2015-11-18 11:21:55 -0200
committerRael <rael.gc@gmail.com>2015-11-18 11:21:55 -0200
commit8fcb826d428443522afaaf4a5ba6791e5f5ea930 (patch)
treeac7c8f15d76d72a9ba8992df1a48ba4b6badbbd1
parent5351a04b9df8cdef26a1a63d5c4865fb1fe2e377 (diff)
downloadscudcloud-8fcb826d428443522afaaf4a5ba6791e5f5ea930.zip
scudcloud-8fcb826d428443522afaaf4a5ba6791e5f5ea930.tar.gz
scudcloud-8fcb826d428443522afaaf4a5ba6791e5f5ea930.tar.bz2
Implement a proper JS client (#292)
-rwxr-xr-xscudcloud-1.0/lib/scudcloud.py11
-rw-r--r--scudcloud-1.0/lib/wrapper.py29
-rw-r--r--scudcloud-1.0/resources/scudcloud.js2
-rw-r--r--scudcloud-1.0/scudcloud-src.js122
4 files changed, 94 insertions, 70 deletions
diff --git a/scudcloud-1.0/lib/scudcloud.py b/scudcloud-1.0/lib/scudcloud.py
index 3fb3b2c..abcc8ca 100755
--- a/scudcloud-1.0/lib/scudcloud.py
+++ b/scudcloud-1.0/lib/scudcloud.py
@@ -61,8 +61,6 @@ class ScudCloud(QtGui.QMainWindow):
self.systray(ScudCloud.minimized)
self.installEventFilter(self)
self.statusBar().showMessage('Loading Slack...')
- # Starting unread msgs counter
- self.setupTimer()
def addWrapper(self, url):
webView = Wrapper(self)
@@ -73,12 +71,6 @@ class ScudCloud(QtGui.QMainWindow):
self.stackedWidget.addWidget(webView)
self.stackedWidget.setCurrentWidget(webView)
- def setupTimer(self):
- self.timer = QTimer(self)
- self.timer.timeout.connect(self.count)
- self.timer.setInterval(2000)
- self.timer.start()
-
def webSettings(self):
self.cookiesjar = PersistentCookieJar(self)
self.zoom = self.readZoom()
@@ -281,7 +273,6 @@ class ScudCloud(QtGui.QMainWindow):
break
if not exists:
self.addWrapper(url)
- self.enableMenus(self.current().isConnected())
self.updateEditMenu()
def eventFilter(self, obj, event):
@@ -367,7 +358,7 @@ class ScudCloud(QtGui.QMainWindow):
total = 0
for i in range(0, self.stackedWidget.count()):
widget = self.stackedWidget.widget(i)
- messages = widget.count()
+ messages = widget.highlights
if messages == 0:
self.leftPane.stopAlert(widget.team())
else:
diff --git a/scudcloud-1.0/lib/wrapper.py b/scudcloud-1.0/lib/wrapper.py
index 084c631..115cbe9 100644
--- a/scudcloud-1.0/lib/wrapper.py
+++ b/scudcloud-1.0/lib/wrapper.py
@@ -10,6 +10,7 @@ from PyQt4.QtNetwork import QNetworkProxy
class Wrapper(QWebView):
+ highlights = 0
icon = None
def __init__(self, window):
@@ -26,18 +27,6 @@ class Wrapper(QWebView):
self.linkClicked.connect(self._linkClicked)
self.page().featurePermissionRequested.connect(self.permissionRequested)
self.addActions()
- self.setupTimer()
-
- # Starting a timer that will check by server side reloads (which drops ScudCloud notification)
- def setupTimer(self):
- timer = QTimer(self)
- timer.timeout.connect(self.overrideNotifications)
- # Hope each 10 minutes will not be produce high CPU usage
- timer.setInterval(600000)
- timer.start()
-
- def overrideNotifications(self):
- self.call("overrideNotifications")
def permissionRequested(self, frame, feature):
self.page().setFeaturePermission(frame, feature, QWebPage.PermissionGrantedByUser)
@@ -104,7 +93,6 @@ class Wrapper(QWebView):
def _loadFinished(self, ok=True):
self.page().currentFrame().addToJavaScriptWindowObject("desktop", self)
self.page().currentFrame().evaluateJavaScript(self.js)
- self.window.enableMenus(self.isConnected())
self.window.statusBar().hide()
def systemOpen(self, url):
@@ -127,9 +115,6 @@ class Wrapper(QWebView):
self.window.show()
self.call("preferences")
- def isConnected(self):
- return self.call("isConnected")
-
def createSnippet(self):
self.call("createSnippet")
@@ -148,9 +133,6 @@ class Wrapper(QWebView):
def about(self):
subprocess.call(('xdg-open', "https://github.com/raelgc/scudcloud"))
- def isConnected(self):
- return self.call("isConnected")
-
def listChannels(self):
return self.call("listChannels")
@@ -158,11 +140,10 @@ class Wrapper(QWebView):
self.call("join", menuitem.property_get("id"))
self.window.show()
- def count(self):
- try:
- return self.call("count")
- except:
- return 0
+ @QtCore.pyqtSlot(int, int)
+ def setBadgeCount(self, highlight, unread):
+ self.highlights = highlight
+ self.window.count()
@QtCore.pyqtSlot(str)
def populate(self, serialized):
diff --git a/scudcloud-1.0/resources/scudcloud.js b/scudcloud-1.0/resources/scudcloud.js
index 5e121c6..bf1f5d6 100644
--- a/scudcloud-1.0/resources/scudcloud.js
+++ b/scudcloud-1.0/resources/scudcloud.js
@@ -1 +1 @@
-var ScudCloud={overrideNotifications:function(){TS.ui.growls.no_notifications=!1,TS.ui.growls.checkPermission=function(){return!0},TS.ui.growls.getPermissionLevel=function(){return"granted"},TS.ui.growls.show=function(n,e){desktop.sendMessage(n,e)},TS.ui.banner.close()},overrideConnect:function(){TS.ms.connected_sig.add(function(){ScudCloud.connect(!0)}),TS.ms.disconnected_sig.add(function(){ScudCloud.connect(!1)})},overrideBanner:function(){ScudCloud.showBanner=TS.ui.banner.show,TS.ui.banner.show=function(){ScudCloud.showBanner(),ScudCloud.overrideNotifications()}},connect:function(n){desktop.enableMenus(n),n&&(ScudCloud.overrideNotifications(),desktop.populate(JSON.stringify({channels:ScudCloud.listChannels(),teams:ScudCloud.listTeams(),icon:TS.model.team.icon.image_44})))},count:function(){var n=0;return $("span.unread_highlight").not(".hidden").each(function(){n+=new Number($(this).text().replace("+",""))}),n},createSnippet:function(){return TS.ui.snippet_dialog.start()},listChannels:function(){return TS.channels.getUnarchivedChannelsForUser()},listTeams:function(){var n=TS.getAllTeams();return n[0].team_icon={image_44:TS.model.team.icon.image_44},n},quicklist:function(){desktop.quicklist(ScudCloud.listChannels())},join:function(n){return TS.channels.join(n)},setClipboard:function(n){TS.client.ui.file_pasted_sig.dispatch(n,TS.model.shift_key_pressed)},preferences:function(){return TS.ui.prefs_dialog.start()},addTeam:function(){document.location=TS.boot_data.signin_url},getCurrentTeam:function(){var n=TS.getAllTeams();if(null!=n)for(var e=0;n.length;e++)if(n[e].team_url==TS.boot_data.team_url)return n[e].id;return""},logout:function(){document.location=TS.boot_data.logout_url},help:function(){return TS.help_dialog.start()},isConnected:function(){return"undefined"!=typeof TS&&"undefined"!=typeof TS.model&&TS.model.ms_connected}};"undefined"!=typeof TS&&(document.onpaste=function(){desktop.pasted(!1)},ScudCloud.overrideNotifications(),ScudCloud.overrideConnect(),ScudCloud.overrideBanner());
+ScudCloud={hasPreference:function(e){return ScudCloud.na("hasPreference")},getPreference:function(e){return ScudCloud.na("getPreference")},setPreference:function(e,n){return ScudCloud.na("setPreference")},canShowHtmlNotifications:function(){return ScudCloud.na("canShowHtmlNotifications")},call:function(e,n){switch(ScudCloud.log(e),e){case"reload":return ScudCloud.reload();case"didStartLoading":return ScudCloud.didStartLoading();case"didFinishLoading":return ScudCloud.didFinishLoading();case"setConnectionStatus":return ScudCloud.setConnectionStatus(n);case"notify":return ScudCloud.notify(n);case"setBadgeCount":return ScudCloud.setBadgeCount(n);case"displayTeam":return ScudCloud.displayTeam(n);case"getModifierKeys":case"updateTitleBarColor":case"disableSecureInput":case"setImage":case"listWindows":case"focusWindow":case"openWindow":case"closeWindow":case"getGeometryForWindow":case"startDownload":case"supportsOpenFileAtPath":case"cancelDownloadWithToken":case"openFileAtPath":case"retryDownloadWithToken":case"pruneTokensFromHistory":case"metadataForDownloads":case"readFindString":}return!1},reload:function(){window.location.reload()},didStartLoading:function(){},didFinishLoading:function(){ScudCloud.populate()},setConnectionStatus:function(e){switch(e){case"online":desktop.enableMenus(!0);break;default:desktop.enableMenus(!1)}},notify:function(e){desktop.sendMessage(e.title,e.content)},setBadgeCount:function(e){desktop.setBadgeCount(e.all_unread_highlights_cnt,e.all_unread_cnt)},displayTeam:function(e){},na:function(e){return ScudCloud.log(e),!1},log:function(e){console.log("ScudCloud."+e)},populate:function(){desktop.populate(JSON.stringify({channels:ScudCloud.listChannels(),teams:ScudCloud.listTeams(),icon:TS.model.team.icon.image_44}))},createSnippet:function(){return TS.ui.snippet_dialog.start()},listChannels:function(){return TS.channels.getUnarchivedChannelsForUser()},listTeams:function(){var e=TS.getAllTeams();return e[0].team_icon={image_44:TS.model.team.icon.image_44},e},quicklist:function(){desktop.quicklist(ScudCloud.listChannels())},join:function(e){return TS.channels.join(e)},setClipboard:function(e){TS.client.ui.file_pasted_sig.dispatch(e,TS.model.shift_key_pressed)},preferences:function(){return TS.ui.prefs_dialog.start()},addTeam:function(){document.location=TS.boot_data.signin_url},getCurrentTeam:function(){var e=TS.getAllTeams();if(null!=e)for(var n=0;e.length;n++)if(e[n].team_url==TS.boot_data.team_url)return e[n].id;return""},logout:function(){document.location=TS.boot_data.logout_url},help:function(){return TS.help_dialog.start()}},"undefined"!=typeof TS&&(document.onpaste=function(e){desktop.pasted(!1)},window.winssb=TSSSB=ScudCloud);
diff --git a/scudcloud-1.0/scudcloud-src.js b/scudcloud-1.0/scudcloud-src.js
index c16a0b9..4cf759b 100644
--- a/scudcloud-1.0/scudcloud-src.js
+++ b/scudcloud-1.0/scudcloud-src.js
@@ -1,33 +1,90 @@
-var ScudCloud = {
- overrideNotifications: function(){
- TS.ui.growls.no_notifications = false;
- TS.ui.growls.checkPermission = function() { return true; };
- TS.ui.growls.getPermissionLevel = function() { return 'granted'; };
- TS.ui.growls.show = function(j,f,o,p){ desktop.sendMessage(j,f); };
- TS.ui.banner.close();
- },
- overrideConnect: function(){
- TS.ms.connected_sig.add(function(){ScudCloud.connect(true);});
- TS.ms.disconnected_sig.add(function(){ScudCloud.connect(false);});
- },
- overrideBanner: function(){
- ScudCloud.showBanner = TS.ui.banner.show;
- TS.ui.banner.show = function(){ ScudCloud.showBanner(); ScudCloud.overrideNotifications(); };
- },
- connect: function(b){
- desktop.enableMenus(b);
- if(b){
- ScudCloud.overrideNotifications();
- desktop.populate(JSON.stringify({'channels': ScudCloud.listChannels(), 'teams': ScudCloud.listTeams(), 'icon': TS.model.team.icon.image_44}));
+ScudCloud = {
+ // App functions
+ hasPreference: function(name){
+ return ScudCloud.na("hasPreference");
+ },
+ getPreference: function(name){
+ return ScudCloud.na("getPreference");
+ },
+ setPreference: function(name, value){
+ return ScudCloud.na("setPreference");
+ },
+ canShowHtmlNotifications: function(){
+ return ScudCloud.na("canShowHtmlNotifications");
+ },
+ // TSSSB.call
+ call: function(name, args){
+ ScudCloud.log(name);
+ switch(name){
+ case "reload":
+ return ScudCloud.reload();
+ case "didStartLoading":
+ return ScudCloud.didStartLoading();
+ case "didFinishLoading":
+ return ScudCloud.didFinishLoading();
+ case "setConnectionStatus":
+ return ScudCloud.setConnectionStatus(args);
+ case "notify":
+ return ScudCloud.notify(args);
+ case "setBadgeCount":
+ return ScudCloud.setBadgeCount(args);
+ case "displayTeam":
+ return ScudCloud.displayTeam(args);
+ case "getModifierKeys":
+ case "updateTitleBarColor":
+ case "disableSecureInput":
+ case "setImage":
+ case "listWindows":
+ case "focusWindow":
+ case "openWindow":
+ case "closeWindow":
+ case "getGeometryForWindow":
+ case "startDownload":
+ case "supportsOpenFileAtPath":
+ case "cancelDownloadWithToken":
+ case "openFileAtPath":
+ case "retryDownloadWithToken":
+ case "pruneTokensFromHistory":
+ case "metadataForDownloads":
+ case "readFindString":
+ }
+ return false;
+ },
+ // TSSSB.call implementations
+ reload: function(){
+ window.location.reload();
+ },
+ didStartLoading: function(){
+ },
+ didFinishLoading: function(){
+ ScudCloud.populate();
+ },
+ setConnectionStatus: function(status){
+ // "online", "connecting", "offline"
+ switch(status){
+ case "online": desktop.enableMenus(true); break;
+ default: desktop.enableMenus(false);
}
},
- count: function(){
- var total=0;
- $('span.unread_highlight').not('.hidden').each(function(i){
- total+= new Number($(this).text().replace('+','')); }
- );
- return total;
- },
+ notify: function(args){
+ desktop.sendMessage(args.title, args.content);
+ },
+ setBadgeCount: function(args){
+ desktop.setBadgeCount(args.all_unread_highlights_cnt, args.all_unread_cnt);
+ },
+ displayTeam: function(id){
+ },
+ // ScudCloud internal functions
+ na: function(name){
+ ScudCloud.log(name);
+ return false;
+ },
+ log: function(name){
+ console.log("ScudCloud."+name);
+ },
+ populate: function(){
+ desktop.populate(JSON.stringify({'channels': ScudCloud.listChannels(), 'teams': ScudCloud.listTeams(), 'icon': TS.model.team.icon.image_44}));
+ },
createSnippet: function(){
return TS.ui.snippet_dialog.start();
},
@@ -69,14 +126,9 @@ var ScudCloud = {
},
help: function(){
return TS.help_dialog.start();
- },
- isConnected: function(){
- return "undefined" != typeof TS && "undefined" != typeof TS.model && TS.model.ms_connected;
- }
+ }
};
if("undefined" != typeof TS){
document.onpaste = function(e){desktop.pasted(false);};
- ScudCloud.overrideNotifications();
- ScudCloud.overrideConnect();
- ScudCloud.overrideBanner();
+ window.winssb = TSSSB = ScudCloud;
}