Browse Source

- 调整目录结构
- 添加 notify 。

oldj 8 years ago
parent
commit
4b0d3a7297
11 changed files with 9196 additions and 10621 deletions
  1. 1 3
      README.md
  2. 9157 10591
      app/bundle.js
  3. 2 1
      app/package.json
  4. 20 0
      app/server/actions/notify.js
  5. 2 0
      app/server/http/api/toggle.js
  6. 1 1
      app/version.js
  7. 5 1
      package.json
  8. 1 1
      ui/events/list_updated.js
  9. 1 1
      ui/events/save.js
  10. 6 3
      ui/events/toggle_hosts.js
  11. 0 19
      ui/package.json

+ 1 - 3
README.md

@@ -39,12 +39,10 @@ SwitchHosts! 的数据文件在 `~/.SwitchHosts` 目录下(Windows 用户为
  - 安装 [Node.js](https://nodejs.org/) 环境;
  - 在根目录 `./` 下,运行 `npm install` 命令,安装开发依赖库;
  - 在 `./app` 目录下,运行 `npm install` 命令,安装 App 运行依赖库;
- - 在 `./ui` 目录下,运行 `npm install` 命令,安装 UI 开发依赖库。
 
     ```bash
     npm install
     cd app && npm install && cd ..
-    cd ui && npm install && cd ..
     ```
 
 ### 构建及运行
@@ -78,7 +76,7 @@ SwitchHosts! 的数据文件在 `~/.SwitchHosts` 目录下(Windows 用户为
     ```bash
     # pack
     npm run pack  # the packed files will be in ./dist
- 
+
     # 也可以只打包特定平台的版本,如
     npm run pack-mac  # pack for macOS, the packed files will be in ./dist
     npm run pack-win  # pack for Windows, the packed files will be in ./dist

File diff suppressed because it is too large
+ 9157 - 10591
app/bundle.js


+ 2 - 1
app/package.json

@@ -1,6 +1,6 @@
 {
   "name": "switchhosts",
-  "version": "3.3.0",
+  "version": "3.3.1",
   "description": "Switch hosts quickly!",
   "main": "main.js",
   "scripts": {
@@ -13,6 +13,7 @@
     "express": "^4.15.2",
     "js-beautify": "^1.6.12",
     "md5-file": "^3.1.1",
+    "node-notifier": "^5.1.2",
     "superagent": "^3.5.2"
   }
 }

+ 20 - 0
app/server/actions/notify.js

@@ -0,0 +1,20 @@
+/**
+ * @author oldj
+ * @blog https://oldj.net
+ */
+
+'use strict'
+
+const path = require('path')
+const notifier = require('node-notifier')
+
+module.exports = (svr, title, message) => {
+  return Promise.resolve()
+    .then(() => {
+      notifier.notify({
+        title,
+        message,
+        icon: path.join(__dirname, '..', '..', 'assets', 'logo_512.png')
+      })
+    })
+}

+ 2 - 0
app/server/http/api/toggle.js

@@ -8,6 +8,7 @@
 const getUserHosts = require('../../actions/getUserHosts')
 const saveHosts = require('../../actions/saveHosts')
 const getPref = require('../../actions/getPref')
+const notify = require('../../actions/notify')
 const svr = require('../../svr')
 
 module.exports = (req, res) => {
@@ -39,6 +40,7 @@ module.exports = (req, res) => {
 
       saveHosts(svr, list)
         .then(() => {
+          notify(svr, 'SwitchHosts!', 'OK')
           svr.broadcast('reload')
           res.end('toggle:' + id)
         })

+ 1 - 1
app/version.js

@@ -1 +1 @@
-exports.version = [3,3,0,5090];
+exports.version = [3,3,1,5093];

+ 5 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "switchhosts",
-  "version": "3.3.0",
+  "version": "3.3.1",
   "description": "Homepage: [https://oldj.github.io/SwitchHosts/](https://oldj.github.io/SwitchHosts/)",
   "main": "",
   "scripts": {
@@ -41,6 +41,8 @@
     "babel-preset-stage-2": "^6.22.0",
     "babel-register": "^6.22.0",
     "chalk": "^1.1.3",
+    "classnames": "^2.2.5",
+    "codemirror": "^5.25.0",
     "connect-history-api-fallback": "^1.3.0",
     "copy-webpack-plugin": "^4.0.1",
     "css-loader": "^0.26.1",
@@ -74,6 +76,7 @@
     "react-dom": "^15.4.2",
     "rimraf": "^2.6.0",
     "semver": "^5.3.0",
+    "sortablejs": "^1.5.1",
     "spectron": "^3.6.0",
     "style-loader": "^0.16.0",
     "uglify-loader": "^2.0.0",
@@ -83,6 +86,7 @@
     "webpack-dev-middleware": "^1.10.0",
     "webpack-hot-middleware": "^2.16.1",
     "webpack-merge": "^2.6.1",
+    "wheel-js": "0.0.5",
     "yargs": "^6.5.0"
   },
   "ava": {

+ 1 - 1
ui/events/list_updated.js

@@ -9,7 +9,7 @@ import Agent from '../Agent'
 
 module.exports = (app, new_list, hosts = null) => {
   let state = {list: new_list}
-  Agent.pact('getSysHosts')
+  return Agent.pact('getSysHosts')
     .then(sys_hosts => {
       state.sys_hosts = sys_hosts
 

+ 1 - 1
ui/events/save.js

@@ -9,7 +9,7 @@ import Agent from '../Agent'
 import updated from './list_updated'
 
 module.exports = (app, list, hosts = null) => {
-  Agent.pact('saveHosts', list)
+  return Agent.pact('saveHosts', list)
     .then(new_list => {
       updated(app, new_list, hosts)
     })

+ 6 - 3
ui/events/toggle_hosts.js

@@ -11,7 +11,7 @@ import save from './save'
 module.exports = (app, hosts) => {
   hosts.on = !hosts.on
 
-  Agent.pact('getPref')
+  return Agent.pact('getPref')
     .then(pref => {
       let list = app.state.list.slice(0)
       let is_single = pref.choice_mode === 'single'
@@ -35,8 +35,11 @@ module.exports = (app, hosts) => {
         list.splice(idx, 1, Object.assign({}, old_hosts, hosts))
       }
 
-      save(app, list, hosts)
+      return save(app, list, hosts)
+    })
+    .then(() => {
+      Agent.pact('statRecord', 'switch')
+      return Agent.pact('notify', 'SwitchHosts!', 'OK')
     })
 
-  Agent.pact('statRecord', 'switch')
 }

+ 0 - 19
ui/package.json

@@ -1,19 +0,0 @@
-{
-  "name": "ui",
-  "version": "1.0.0",
-  "description": "",
-  "main": "index.js",
-  "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
-  },
-  "author": "oldj",
-  "license": "MIT",
-  "devDependencies": {
-    "classnames": "^2.2.5",
-    "codemirror": "^5.25.0",
-    "react": "^15.4.2",
-    "react-dom": "^15.4.2",
-    "sortablejs": "^1.5.1",
-    "wheel-js": "0.0.5"
-  }
-}

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