Skip to content

Commit

Permalink
Fix notifications toggle when using screen notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilprusko committed Jan 1, 2015
1 parent 4c92bfb commit 6eb936d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 46 deletions.
54 changes: 26 additions & 28 deletions extension/extension.js
Expand Up @@ -152,40 +152,38 @@ const PomodoroExtension = new Lang.Class({
},

_onTimerStateChanged: function() {
let state = this.timer.getState();

if (this._state === state) {
return;
}
let timerState = this.timer.getState();

this._state = state;
if (this._timerState !== timerState) {
this._timerState = timerState;

if (this.dialog && state != Timer.State.PAUSE) {
this.dialog.close();
}
if (this.dialog && timerState != Timer.State.PAUSE) {
this.dialog.close();
}

if (this.reminderManager) {
this.reminderManager.destroy();
this.reminderManager = null;
}
if (this.reminderManager) {
this.reminderManager.destroy();
this.reminderManager = null;
}

switch (state) {
case Timer.State.POMODORO:
case Timer.State.IDLE:
this._onNotifyPomodoroStart();
break;
switch (timerState) {
case Timer.State.POMODORO:
case Timer.State.IDLE:
this._notifyPomodoroStart();
break;

case Timer.State.PAUSE:
this._onNotifyPomodoroEnd();
break;
case Timer.State.PAUSE:
this._notifyPomodoroEnd();
break;

case Timer.State.NULL:
this._destroyNotifications();
break;
case Timer.State.NULL:
this._destroyNotifications();
break;
}
}
},

_onNotifyPomodoroStart: function() {
_notifyPomodoroStart: function() {
if (this.notification &&
this.notification instanceof Notifications.PomodoroStartNotification)
{
Expand All @@ -206,7 +204,7 @@ const PomodoroExtension = new Lang.Class({
this._destroyPreviousNotifications();
},

_onNotifyPomodoroEnd: function() {
_notifyPomodoroEnd: function() {
if (this.notification &&
this.notification instanceof Notifications.PomodoroEndNotification)
{
Expand Down Expand Up @@ -327,11 +325,11 @@ const PomodoroExtension = new Lang.Class({
let state = this.timer.getState();

if (state == Timer.State.POMODORO || state == Timer.State.IDLE) {
this._onNotifyPomodoroStart();
this._notifyPomodoroStart();
}

if (state == Timer.State.PAUSE) {
this._onNotifyPomodoroEnd();
this._notifyPomodoroEnd();
}
},

Expand Down
42 changes: 24 additions & 18 deletions extension/presence.js
Expand Up @@ -114,13 +114,9 @@ const Presence = new Lang.Class({
if (isRunning) {
this._patch.apply();

this._updateNotificationsMenuItem();

this.update();
}
else {
this._updateNotificationsMenuItem();

this.update();

this._patch.revert();
Expand All @@ -130,19 +126,21 @@ const Presence = new Lang.Class({
},

_onNotificationsMenuItemToggled: function(item, state) {
let isRunning = (this._timerState != Timer.State.NULL);
if (!this._notificationsMenuItemLock) {
let isRunning = (this._timerState != Timer.State.NULL);

if (isRunning && this._timerState == Timer.State.POMODORO) {
this.setNotificationsDuringPomodoro(state);
}
if (isRunning && this._timerState == Timer.State.POMODORO) {
this.setNotificationsDuringPomodoro(state);
}

if (isRunning && this._timerState != Timer.State.POMODORO) {
this.setNotificationsDuringBreak(state);
if (isRunning && this._timerState != Timer.State.POMODORO) {
this.setNotificationsDuringBreak(state);
}
}
},

_updateNotificationsMenuItem: function() {
let timerState = Extension.extension.timer.getState();
let timerState = this._timerState;
let isRunning = timerState != Timer.State.NULL;

try {
Expand Down Expand Up @@ -201,30 +199,38 @@ const Presence = new Lang.Class({
? !this._notificationsDuringPomodoro
: !this._notificationsDuringBreak;

let hasDialog = Extension.extension.dialog && Extension.extension.dialog.isOpened;
let isDialogOpened = Extension.extension.dialog && Extension.extension.dialog.isOpened;

messageTray._busy = busy || hasDialog;
messageTray._busy = busy || isDialogOpened;
messageTray._updateState();

if (menuItem.state == messageTray._busy) {
if (menuItem.state != !messageTray._busy) {
this._notificationsMenuItemLock = true;
menuItem.toggle();
this._notificationsMenuItemLock = false;
}
}
catch (error) {
Extension.extension.logError(error.message);
}

this._updateNotificationsMenuItem();
},

setNotificationsDuringPomodoro: function(enabled) {
this._notificationsDuringPomodoro = enabled;
if (this._notificationsDuringPomodoro != enabled) {
this._notificationsDuringPomodoro = enabled;

this.update();
this.update();
}
},

setNotificationsDuringBreak: function(enabled) {
this._notificationsDuringBreak = enabled;
if (this._notificationsDuringBreak != enabled) {
this._notificationsDuringBreak = enabled;

this.update();
this.update();
}
},

destroy: function() {
Expand Down

0 comments on commit 6eb936d

Please sign in to comment.