Explorar o código

Merge branch 'master' into develop

# Conflicts:
#	.gitignore
#	app/package-lock.json
#	package-lock.json
#	package.json
oldj %!s(int64=6) %!d(string=hai) anos
pai
achega
4ba0dc8918
Modificáronse 7 ficheiros con 63 adicións e 10 borrados
  1. 7 2
      .gitignore
  2. 10 2
      README.md
  3. 9 1
      README_cn.md
  4. 1 0
      app/lang/cn.js
  5. 1 0
      app/lang/en.js
  6. 31 1
      app/menu/tray.js
  7. 4 4
      gulpfile.js

+ 7 - 2
.gitignore

@@ -1,11 +1,18 @@
 .idea
 *.pyc
 *.swp
+src/build
+src/dist
+dist
+projectFilesBackup
 *.DS_Store
+tmp
 *.js.map
 
 *.hosts
 
+src/configs.json
+
 *.swh
 *.iml
 
@@ -15,5 +22,3 @@ xcdebugger
 npm-debug.log*
 .nyc_output
 coverage/
-tmp
-dist

+ 10 - 2
README.md

@@ -31,7 +31,7 @@ You can download the source code and build it yourself, or download the built ve
 
 ### brew
 
-If you are using macOS, you can install SwitchHosts! by `brew cast`:
+On macOS you can install SwitchHosts! by `brew cask`:
 
 ```bash
 brew cask install switchhosts
@@ -39,7 +39,15 @@ brew cask install switchhosts
 
 Thanks to [@gobinathm](https://github.com/gobinathm) and [@iamybj](https://github.com/iamybj) for updating the `brew cask` version.
 
+### scoop
 
+On Windows you can install SwitchHosts! by [scoop](https://scoop.sh/):
+
+```
+scoop install switchhosts
+```
+
+Thanks to [@batkiz](https://github.com/batkiz) for updating the `scoop` version.
 
 ## Backup
 
@@ -100,7 +108,7 @@ SwitchHosts! stores data at `~/.SwitchHosts` (Or folder `.SwitchHosts` under the
     npm run pack-win  # pack for Windows, the packed files will be in ./dist
     ```
 
- - After packaging, you can make a zip file by run the following command.
+ - After packaging, you can make a zip file by running the following command.
 
     ```bash
     # zip

+ 9 - 1
README_cn.md

@@ -31,7 +31,7 @@
 
 ### brew
 
-在 macOS 上,也可以使用 `brew cast` 安装,命令如下:
+在 macOS 上,也可以使用 `brew cask` 安装,命令如下:
 
 ```bash
 brew cask install switchhosts
@@ -39,7 +39,15 @@ brew cask install switchhosts
 
 感谢 [@gobinathm](https://github.com/gobinathm)、[@iamybj](https://github.com/iamybj) 更新 `brew cask` 版本。
 
+### scoop
 
+在 Windows 上,也可以使用 [scoop](https://scoop.sh/) 安装,命令如下:
+
+```
+scoop install switchhosts
+```
+
+感谢 [@batkiz](https://github.com/batkiz) 更新 `scoop` 版本。
 
 ## 文件备份
 

+ 1 - 0
app/lang/cn.js

@@ -24,6 +24,7 @@ exports.content = {
   , confirm_del: '确定要删除此 hosts 方案吗?'
   , confirm_import: '确定要导入吗?原方案列表将被覆盖,此操作不可撤销。'
   // , current_version: '当前版本:'
+  , current_active_hosts: '当前生效配置'
   , day: '天'
   , days: '天'
   , del_hosts: '删除当前 hosts 方案'

+ 1 - 0
app/lang/en.js

@@ -24,6 +24,7 @@ exports.content = {
   , confirm_del: 'Are you sure you want to delete this hosts?'
   , confirm_import: 'You sure you want to import it? The original rules will be overwriten, this operation can not be undone.'
   // , current_version: 'Current version: '
+  , current_active_hosts: 'Current effective config'
   , day: 'day'
   , days: 'days'
   , del_hosts: 'Delete current hosts'

+ 31 - 1
app/menu/tray.js

@@ -107,20 +107,50 @@ function makeMenu (app, list, contents, sys_lang) {
   return menu
 }
 
+function makeTitle(list = []) {
+  const currItems = (list || []).filter(item => item.on) || []
+
+  const appendTitleEvt = function(lis = [], opr = ',') {
+    let _str = ''
+    if(lis.length) {
+      const appendTitle = (prev, curr) => {
+        return {
+          title: `${prev.title}${prev.title ? `${opr}` : ''}${curr.title}`
+        }
+      }
+      _str = currItems.reduce(appendTitle, { title: '' }).title || ''
+    }
+    return _str;
+  };
+
+  const _ori = appendTitleEvt(list)
+
+  return {
+    ori: _ori,
+    show: _ori.length > 20 ? `${_ori.substr(0, 20)}...` : _ori,
+    tips: `${appendTitleEvt(list, '\n')}`
+  }
+}
+
+
 function makeTray (app, contents, sys_lang = 'en') {
+  const lang = m_lang.getLang(sys_lang)
+
   let icon = 'logo.png'
   if (process.platform === 'darwin') {
     icon = 'ilogoTemplate.png'
   }
 
   tray = new Tray(path.join(__dirname, '..', 'assets', icon))
-  tray.setToolTip('SwitchHosts!')
 
   svr.on('update_tray', () => {
     getUserHosts()
       .then(list => {
         let contextMenu = Menu.buildFromTemplate(makeMenu(app, list, contents, sys_lang))
         tray.setContextMenu(contextMenu)
+        const { ori = '', show = '', tips = '' } = makeTitle(list)
++       tray.setTitle(show)
++       tray.setToolTip(ori ? `\n${lang.current_active_hosts}: \n\n${tips}\n` : 'SwitchHosts!')
       })
   })
 

+ 4 - 4
gulpfile.js

@@ -60,19 +60,19 @@ gulp.task('pack', (done) => {
   let pack = {}
   pack.macOS = `
 # for macOS
-electron-packager ./app 'SwitchHosts!' --platform=darwin --arch=x64 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.icns --ignore=node_modules/.bin --ignore=.git --ignore=dist --ignore=node_modules/electron-* --out=dist --app-version=${v1} --build-version=${v2}
+electron-packager ./app 'SwitchHosts!' --platform=darwin --arch=x64 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.icns --ignore=node_modules/.bin --ignore=.git --ignore=${__dirname}/dist --ignore="node_modules/electron-(?!(?:window-state)).*" --out=dist --app-version=${v1} --build-version=${v2}
 `
   pack.win64 = `
 # for windows x64
-electron-packager ./app 'SwitchHosts!' --platform=win32  --arch=x64 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.ico  --ignore=node_modules/.bin --ignore=.git --ignore=dist --ignore=node_modules/electron-* --out=dist --app-version=${v1} --build-version=${v2}
+electron-packager ./app 'SwitchHosts!' --platform=win32  --arch=x64 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.ico  --ignore=node_modules/.bin --ignore=.git --ignore=${__dirname}/dist --ignore="node_modules/electron-(?!(?:window-state)).*" --out=dist --app-version=${v1} --build-version=${v2}
 `
   pack.win32 = `
 # for windows ia32
-electron-packager ./app 'SwitchHosts!' --platform=win32  --arch=ia32 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.ico  --ignore=node_modules/.bin --ignore=.git --ignore=dist --ignore=node_modules/electron-* --out=dist --app-version=${v1} --build-version=${v2}
+electron-packager ./app 'SwitchHosts!' --platform=win32  --arch=ia32 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.ico  --ignore=node_modules/.bin --ignore=.git --ignore=${__dirname}/dist --ignore="node_modules/electron-(?!(?:window-state)).*" --out=dist --app-version=${v1} --build-version=${v2}
 `
   pack.linux = `
 # for linux x86_64
-electron-packager ./app 'SwitchHosts!' --platform=linux  --arch=x64 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.ico  --ignore=node_modules/.bin --ignore=.git --ignore=dist --ignore=node_modules/electron-* --out=dist --app-version=${v1} --build-version=${v2}
+electron-packager ./app 'SwitchHosts!' --platform=linux  --arch=x64 --electron-version=${ELECTRON_VERSION} --overwrite --asar=true --prune --icon=./assets/app.ico  --ignore=node_modules/.bin --ignore=.git --ignore=${__dirname}/dist --ignore="node_modules/electron-(?!(?:window-state)).*" --out=dist --app-version=${v1} --build-version=${v2}
 `
 
   let cmds = []