Skip to content

Commit

Permalink
More accurate notification count and improved the "Open Ghetto Skype
Browse files Browse the repository at this point in the history
when recieving message" setting
  • Loading branch information
stanfieldr committed Aug 6, 2016
1 parent 6737482 commit 5490145
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
2 changes: 2 additions & 0 deletions app/GhettoSkype.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class GhettoSkype {
openSettings() {
if (this.settingsWindow) {
this.settingsWindow.show();
this.settingsWindow.focus();
return;
}

Expand All @@ -102,6 +103,7 @@ class GhettoSkype {
zoomFactor: this.settings.ZoomFactor
}
});
this.settingsWindow.focus();

if (this.settings.Theme) {
let folder = path.join(__dirname, '..', 'themes', this.settings.Theme);
Expand Down
7 changes: 5 additions & 2 deletions app/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ exports.setNotificationCount = function(count) {
}

let image = basePath;

if (count > 0) {
image += 'skype24-1.png';
mainWindow.flashFrame(true);
if (GhettoSkype.settings.OpenWhenMessaged) {
GhettoSkype.sendToRenderers('read-latest-thread');
// Do not click threads once a user reads one
if (count > lastCount) {
GhettoSkype.sendToRenderers('read-latest-thread');
}

mainWindow.show();
mainWindow.focus();
}
Expand Down
37 changes: 25 additions & 12 deletions views/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
});

ipc.on('read-latest-thread', function(event) {
document.querySelector(".recent.message").click();
$('.unseenNotifications:first').closest('.message').get(0).click();
});

ipc.on('settings-updated', function(event, settings) {
Expand All @@ -32,17 +32,6 @@
setActivityHandle(settings.RefreshInterval);
});

setInterval(function() {
let hasNotifications = document.querySelector('.unseenNotifications');
let count = 0;

if (hasNotifications) {
count = 1;
}

ipc.sendToHost('notification-count', count);
}, 1000);

window.addEventListener("DOMContentLoaded", function(event) {
$ = require('../assets/jquery-2.2.3.min');

Expand All @@ -63,6 +52,30 @@
hasActivity = true;
});
}

// Get an accurate notification count... we can't parse it out of the title
// because Web Skype has a bug
let lastCount = 0;
setInterval(function() {
// Gets a numeric representation of each thread's unread messages
let unreadCounters = $('.unseenNotifications').map(function() {
return Number($(this).find('p').text());
});

// Sums them all up
let count = 0;
for (let i = 0; i < unreadCounters.length; i++) {
count += unreadCounters[i];
}

// We currently do not have a way to determine who last messaged the user
// TODO: figure this out by intercepting HTML5 notifications
if (count > 0 && lastCount !== 0)
return;

lastCount = count;
ipc.sendToHost('notification-count', count);
}, 500);
});

function setActivityHandle(minutes) {
Expand Down

0 comments on commit 5490145

Please sign in to comment.