Browse Source

小优化。

oldj 10 years ago
parent
commit
75b8db5c2c
5 changed files with 35 additions and 43 deletions
  1. 1 1
      app/SH3/MacGap/SwitchHosts!-Info.plist
  2. 0 0
      app/SH3/public/js/main.js
  3. 6 26
      app/src/main.js
  4. 28 8
      app/src/refresh.js
  5. 0 8
      app/src/util.js

+ 1 - 1
app/SH3/MacGap/SwitchHosts!-Info.plist

@@ -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>

File diff suppressed because it is too large
+ 0 - 0
app/SH3/public/js/main.js


+ 6 - 26
app/src/main.js

@@ -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;
 
@@ -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()) {
@@ -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) {

+ 28 - 8
app/src/refresh.js

@@ -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;

+ 0 - 8
app/src/util.js

@@ -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, '');

Some files were not shown because too many files changed in this diff