Skip to content

Commit

Permalink
小优化。
Browse files Browse the repository at this point in the history
  • Loading branch information
oldj committed Jan 10, 2016
1 parent 9cba52a commit 8a5e307
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/SH3/MacGap/SwitchHosts!-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2941</string>
<string>2950</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion app/SH3/public/js/main.js

Large diffs are not rendered by default.

32 changes: 6 additions & 26 deletions app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var config = require('./config');
Vue.use(require('./vue_dnd'));
var util = require('./util');
var agent = require('./agent');
var refresh = require('./refresh');
var lang = require('./lang').getLang(navigator.language);
var tray_obj;

Expand Down Expand Up @@ -148,30 +149,7 @@ var app = new Vue({
this.current_host.content = v;
},
getRemoteHost: function (host) {
if (host.where !== 'remote' || !host.url) return;
var tpl = [
'# REMOTE: ' + host.title,
'# URL: ' + host.url,
'# UPDATE: ' + util.now()
];

host.content = '# loading...';
this.onCurrentHostChange(host);

var _this = this;
agent.getURL(host.url, {}, function (s) {
// success
host.content = tpl.concat(['', s]).join('\n');
_this.onCurrentHostChange(host);
_this.doSave();
}, function (xhr, status) {
// fail
host.content = tpl.concat(['', 'FAIL to get!', status]).join('\n');
_this.onCurrentHostChange(host);
_this.doSave();
});

this.doSave();
refresh.getRemoteHost(this, host);
},
toSave: function () {
if (!this.chkHostTitle() || !this.chkHostUrl()) {
Expand Down Expand Up @@ -395,11 +373,13 @@ var app = new Vue({

checkRefresh: function () {
var _this = this;
require('./refresh').checkRefresh(this);
var t = 60 * 5 * 1000;
//var t = 1000;
refresh.checkRefresh(this);

setTimeout(function () {
_this.checkRefresh();
}, 60 * 5 * 1000);
}, t);
},

log: function (obj) {
Expand Down
36 changes: 28 additions & 8 deletions app/src/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,37 @@ function checkRefresh(app) {
});

to_refresh_list.map(function (host) {
agent.getURL(host.url, {}, function (c) {
host.content = c;
host.last_refresh = moment().format('YYYY-MM-DD HH:mm:ss');

app.onCurrentHostChange(host);
app.doSave();
});
getRemoteHost(app, host);
});
}
exports.checkRefresh = checkRefresh;

function getRemoteHosts(app, host) {
function getRemoteHost(app, host) {
if (host.where !== 'remote' || !host.url) return;
var tpl = [
'# REMOTE: ' + host.title,
'# URL: ' + host.url
];

host.content = '# loading...';
app.onCurrentHostChange(host);

agent.getURL(host.url, {}, function (s) {
// success
var now = moment().format('YYYY-MM-DD HH:mm:ss');
host.content = tpl.concat(['# UPDATE: ' + now, '', s]).join('\n');
host.last_refresh = now;
app.onCurrentHostChange(host);
app.doSave();
}, function (xhr, status) {
// fail
var now = moment().format('YYYY-MM-DD HH:mm:ss');
host.content = tpl.concat(['# UPDATE: ' + now, '', 'FAIL to get!', status]).join('\n');
host.last_refresh = now;
app.onCurrentHostChange(host);
app.doSave();
});

app.doSave();
}
exports.getRemoteHost = getRemoteHost;
8 changes: 0 additions & 8 deletions app/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

'use strict';

exports.now = function () {
var dt = new Date();
return [
dt.getFullYear(), '-', dt.getMonth() + 1, '-', dt.getDay(), ' ',
dt.getHours(), ':', dt.getMinutes(), ':', dt.getSeconds()
].join('');
};

exports.trim = function (s) {
if (!s) return '';
return (typeof s === 'string' ? s : s.toString()).replace(/^\s+|\s+$/g, '');
Expand Down

0 comments on commit 8a5e307

Please sign in to comment.