Pause the thread updater when offline.

This commit is contained in:
Nicolas Stepien 2012-09-14 03:09:36 +02:00
parent 659bf231b4
commit b9f0aa47fc
3 changed files with 83 additions and 41 deletions

View File

@ -2407,27 +2407,47 @@
_ref1 = $$('input', dialog); _ref1 = $$('input', dialog);
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
input = _ref1[_i]; input = _ref1[_i];
switch (input.type) { if (input.type === 'checkbox') {
case 'checkbox': $.on(input, 'click', this.cb.checkbox.bind(this));
$.on(input, 'click', this.cb.checkbox.bind(this)); input.dispatchEvent(new Event('click'));
input.dispatchEvent(new Event('click')); }
$.on(input, 'click', $.cb.checked); switch (input.name) {
case 'Scroll BG':
$.on(input, 'click', this.cb.scrollBG.bind(this));
this.cb.scrollBG.call(this);
break; break;
case 'number': case 'Auto Update This':
$.on(input, 'click', this.cb.autoUpdate.bind(this));
break;
case 'Interval':
$.on(input, 'change', this.cb.interval.bind(this)); $.on(input, 'change', this.cb.interval.bind(this));
input.dispatchEvent(new Event('change')); input.dispatchEvent(new Event('change'));
break; break;
case 'button': case 'Update Now':
$.on(input, 'click', this.update.bind(this)); $.on(input, 'click', this.update.bind(this));
} }
} }
$.on(window, 'online offline', this.cb.online.bind(this));
$.on(d, 'QRPostSuccessful', this.cb.post.bind(this)); $.on(d, 'QRPostSuccessful', this.cb.post.bind(this));
$.on(d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', this.cb.visibility.bind(this)); $.on(d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', this.cb.visibility.bind(this));
this.set('timer', this.getInterval()); this.cb.online.call(this);
$.add(d.body, dialog); $.add(d.body, dialog);
} }
_Class.prototype.cb = { _Class.prototype.cb = {
online: function() {
if (this.online = navigator.onLine) {
this.unsuccessfulFetchCount = 0;
this.set('timer', this.getInterval());
this.set('status', null);
this.status.className = null;
} else {
this.status.className = 'warning';
this.set('status', 'Offline');
this.set('timer', null);
}
return this.cb.autoUpdate.call(this);
},
post: function(e) { post: function(e) {
if (!(this['Auto Update This'] && +e.detail.threadID === this.thread.ID)) { if (!(this['Auto Update This'] && +e.detail.threadID === this.thread.ID)) {
return; return;
@ -2453,19 +2473,20 @@
input = e.target; input = e.target;
checked = input.checked, name = input.name; checked = input.checked, name = input.name;
this[name] = checked; this[name] = checked;
switch (name) { return $.cb.checked.call(input);
case 'Scroll BG': },
return this.scrollBG = checked ? function() { scrollBG: function() {
return true; return this.scrollBG = this['Scroll BG'] ? function() {
} : function() { return true;
return !(d.hidden || d.oHidden || d.mozHidden || d.webkitHidden); } : function() {
}; return !(d.hidden || d.oHidden || d.mozHidden || d.webkitHidden);
case 'Auto Update This': };
if (checked) { },
return this.timeoutID = setTimeout(this.timeout.bind(this), 1000); autoUpdate: function() {
} else { if (this['Auto Update This'] && this.online) {
return clearTimeout(this.timeoutID); return this.timeoutID = setTimeout(this.timeout.bind(this), 1000);
} } else {
return clearTimeout(this.timeoutID);
} }
}, },
interval: function(e) { interval: function(e) {
@ -2548,6 +2569,9 @@
_Class.prototype.update = function() { _Class.prototype.update = function() {
var url; var url;
if (!this.online) {
return;
}
this.seconds = 0; this.seconds = 0;
this.set('timer', '...'); this.set('timer', '...');
if (this.req) { if (this.req) {

View File

@ -1,5 +1,6 @@
alpha alpha
- Mayhem - Mayhem
The Thread Updater will pause when offline, and resume when online.
Fix Chrome's install warning that 4chan X would execute on all domains. Fix Chrome's install warning that 4chan X would execute on all domains.
Fix Quote Backlinks not affecting inlined quotes. Fix Quote Backlinks not affecting inlined quotes.
Fix Quote Highlighting not affecting inlined quotes. Fix Quote Highlighting not affecting inlined quotes.

View File

@ -2148,24 +2148,40 @@ ThreadUpdater =
@lastPost = +@threadRoot.lastElementChild.id[2..] @lastPost = +@threadRoot.lastElementChild.id[2..]
for input in $$ 'input', dialog for input in $$ 'input', dialog
switch input.type if input.type is 'checkbox'
when 'checkbox' $.on input, 'click', @cb.checkbox.bind @
$.on input, 'click', @cb.checkbox.bind @ input.dispatchEvent new Event 'click'
input.dispatchEvent new Event 'click' switch input.name
$.on input, 'click', $.cb.checked when 'Scroll BG'
when 'number' $.on input, 'click', @cb.scrollBG.bind @
@cb.scrollBG.call @
when 'Auto Update This'
$.on input, 'click', @cb.autoUpdate.bind @
when 'Interval'
$.on input, 'change', @cb.interval.bind @ $.on input, 'change', @cb.interval.bind @
input.dispatchEvent new Event 'change' input.dispatchEvent new Event 'change'
when 'button' when 'Update Now'
$.on input, 'click', @update.bind @ $.on input, 'click', @update.bind @
$.on window, 'online offline', @cb.online.bind @
$.on d, 'QRPostSuccessful', @cb.post.bind @ $.on d, 'QRPostSuccessful', @cb.post.bind @
$.on d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', @cb.visibility.bind @ $.on d, 'visibilitychange ovisibilitychange mozvisibilitychange webkitvisibilitychange', @cb.visibility.bind @
@set 'timer', @getInterval() @cb.online.call @
$.add d.body, dialog $.add d.body, dialog
cb: cb:
online: ->
if @online = navigator.onLine
@unsuccessfulFetchCount = 0
@set 'timer', @getInterval()
@set 'status', null
@status.className = null
else
@status.className = 'warning'
@set 'status', 'Offline'
@set 'timer', null
@cb.autoUpdate.call @
post: (e) -> post: (e) ->
return unless @['Auto Update This'] and +e.detail.threadID is @thread.ID return unless @['Auto Update This'] and +e.detail.threadID is @thread.ID
@unsuccessfulFetchCount = 0 @unsuccessfulFetchCount = 0
@ -2181,18 +2197,18 @@ ThreadUpdater =
input = e.target input = e.target
{checked, name} = input {checked, name} = input
@[name] = checked @[name] = checked
switch name $.cb.checked.call input
when 'Scroll BG' scrollBG: ->
@scrollBG = @scrollBG =
if checked if @['Scroll BG']
-> true -> true
else else
-> !(d.hidden or d.oHidden or d.mozHidden or d.webkitHidden) -> !(d.hidden or d.oHidden or d.mozHidden or d.webkitHidden)
when 'Auto Update This' autoUpdate: ->
if checked if @['Auto Update This'] and @online
@timeoutID = setTimeout @timeout.bind(@), 1000 @timeoutID = setTimeout @timeout.bind(@), 1000
else else
clearTimeout @timeoutID clearTimeout @timeoutID
interval: (e) -> interval: (e) ->
input = e.target input = e.target
val = Math.max 5, parseInt input.value, 10 val = Math.max 5, parseInt input.value, 10
@ -2263,6 +2279,7 @@ ThreadUpdater =
@set 'timer', n @set 'timer', n
update: -> update: ->
return unless @online
@seconds = 0 @seconds = 0
@set 'timer', '...' @set 'timer', '...'
if @req if @req