浏览代码

Merge branch 'feature/cmd-problem' into develop

oldj 8 年之前
父节点
当前提交
701e581ba8

文件差异内容过多而无法显示
+ 0 - 1
app/bundle.js


+ 1 - 1
app/package.json

@@ -1,6 +1,6 @@
 {
   "name": "switchhosts",
-  "version": "3.3.2",
+  "version": "3.3.3",
   "description": "Switch hosts quickly!",
   "main": "main.js",
   "scripts": {

+ 23 - 1
app/server/actions/checkNeedRemoteRefresh.js

@@ -8,8 +8,30 @@
 const saveHosts = require('./saveHosts')
 const checkOne = require('./checkOneRemoteHosts')
 
+function isHostsEqual(hosts1, hosts2) {
+  return hosts1.id === hosts2.id && hosts1.content === hosts2.content
+}
+
+function isListEqual (list1, list2) {
+  let len = list1.length
+
+  if (len !== list2.length) return false
+  for (let i = 0; i < len; i ++) {
+    if (!isHostsEqual(list1[i] ,list2[i])) {
+      return false
+    }
+  }
+
+  return true
+}
+
 module.exports = (svr, list, hosts = null) => {
   return Promise.all(list.map(i => checkOne(svr, i, hosts && hosts.id === i.id)))
-    .then(list2 => saveHosts(svr, list2))
+    .then(list2 => {
+      if (!isListEqual(list, list2)) {
+        // 仅在 list 的内容发生变化时才再次保存
+        return saveHosts(svr, list2)
+      }
+    })
 }
 

+ 7 - 5
app/server/actions/checkOneRemoteHosts.js

@@ -23,13 +23,15 @@ module.exports = (svr, hosts, force = false) => {
     }
 
     if (force || isExpired(svr, hosts)) {
-      console.log('check', hosts.title, force, isExpired(svr, hosts))
-      getUrl(svr, hosts.url)
+      let hosts2 = Object.assign({}, hosts)
+
+      console.log('check', hosts2.title, force, isExpired(svr, hosts2))
+      getUrl(svr, hosts2.url)
         .then(content => {
-          hosts.content = content
-          hosts.last_refresh = now()
+          hosts2.content = content
+          hosts2.last_refresh = now()
         })
-        .then(() => resolve(hosts))
+        .then(() => resolve(hosts2))
         .catch(e => resolve(e))
     } else {
       resolve(hosts)

+ 5 - 3
app/server/apply.js

@@ -151,7 +151,7 @@ module.exports = (cnt, pswd) => {
 
         if (file_md5 === cnt_md5) {
           // 文件相同
-          resolve()
+          resolve(true)
           return
         }
 
@@ -159,8 +159,10 @@ module.exports = (cnt, pswd) => {
         //reject('need_sudo')
       })
     })
-    .then(() => {
-      return new Promise((resolve, reject) => {
+    .then(eq => {
+      // eq 为 true 表示新内容与系统 hosts 内容相同,hosts 没有变化,不需要执行自定义命令
+
+      return eq ? null : new Promise((resolve, reject) => {
         let after_cmd = pref.after_cmd
 
         if (after_cmd) {

+ 1 - 1
app/server/http/app.js

@@ -15,7 +15,7 @@ app.use(function (req, res, next) {
 })
 
 app.get('/', function (req, res) {
-  res.send('Hello SwitchHost!')
+  res.send('Hello SwitchHosts!')
 })
 
 app.get('/remote-test', function (req, res) {

+ 1 - 1
app/version.js

@@ -1 +1 @@
-exports.version = [3,3,2,5199];
+exports.version = [3,3,3,5203];

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "switchhosts",
-  "version": "3.3.2",
+  "version": "3.3.3",
   "description": "Homepage: [https://oldj.github.io/SwitchHosts/](https://oldj.github.io/SwitchHosts/)",
   "main": "",
   "scripts": {

+ 0 - 0
ui/app.js → ui/app.jsx


+ 0 - 0
ui/content/content.js → ui/content/content.jsx


+ 0 - 0
ui/content/editor.js → ui/content/editor.jsx


+ 0 - 0
ui/frame/edit.js → ui/frame/edit.jsx


+ 0 - 0
ui/frame/frame.js → ui/frame/frame.jsx


+ 0 - 0
ui/frame/group.js → ui/frame/group.jsx


+ 0 - 0
ui/frame/preferences.js → ui/frame/preferences.jsx


+ 0 - 0
ui/frame/sudo.js → ui/frame/sudo.jsx


+ 0 - 0
ui/index.js → ui/index.jsx


+ 0 - 0
ui/panel/buttons.js → ui/panel/buttons.jsx


+ 0 - 0
ui/panel/list-item.js → ui/panel/list-item.jsx


+ 0 - 0
ui/panel/list.js → ui/panel/list.jsx


+ 0 - 0
ui/panel/panel.js → ui/panel/panel.jsx


+ 0 - 0
ui/panel/searchbar.js → ui/panel/searchbar.jsx


+ 2 - 5
webpack.config.js

@@ -11,7 +11,7 @@ const moment = require('moment')
 const version = require('./app/version').version.join('.')
 
 module.exports = {
-  entry: './ui/index.js',
+  entry: './ui/index.jsx',
   devtool: 'source-map',
   output: {
     path: path.join(__dirname, 'app')
@@ -37,10 +37,7 @@ module.exports = {
         test: /\.(eot|woff|woff2|ttf|svg|png|jpg)$/,
         use: 'url-loader?limit=30000&name=[name]-[hash].[ext]'
       }
-    ]//,
-    // query: {
-    // presets: ['es2015', 'stage-0', 'react']
-    // }
+    ]
     , noParse: [/\bAgent\b/]
   },
   plugins: [

部分文件因为文件数量过多而无法显示