Browse Source

- 如果环境变量中找不到 Windows 安装目录,则默认为 C 盘
- 修复一处文案错误

oldj 8 years ago
parent
commit
fcf560317c
7 changed files with 78 additions and 92 deletions
  1. 1 1
      README.md
  2. 52 72
      app/build/bundle.js
  3. 1 0
      app/index.html
  4. 20 15
      app/src/agent.js
  5. 2 2
      app/src/lang/en.js
  6. 1 1
      app/src/libs/paths.js
  7. 1 1
      app/version.js

+ 1 - 1
README.md

@@ -71,7 +71,7 @@ SwitchHosts! 的数据文件在 `~/.SwitchHosts` 目录下(Windows 用户为
 
     ```bash
     # zip
-    gulp zip  # the zipped files will be in ./dist
+    npm run zip  # the zipped files will be in ./dist
     ```
 
 ## 更新历史:

File diff suppressed because it is too large
+ 52 - 72
app/build/bundle.js


+ 1 - 0
app/index.html

@@ -11,6 +11,7 @@
 	const SH_event = require('./src/event').event;
 	const SH_Agent = require('./src/agent');
 	const {ipcRenderer} = require('electron');
+    const notifier = require('node-notifier');
 	const platform = process.platform;
 </script>
 <!--<script src="build/bundle.js"></script>-->

+ 20 - 15
app/src/agent.js

@@ -11,7 +11,6 @@ const fs = require('fs');
 const path = require('path');
 const request = require('request');
 const moment = require('moment');
-const notifier = require('node-notifier');
 const util = require('./libs/util');
 const platform = process.platform;
 
@@ -105,15 +104,15 @@ function apply_UNIX(content, success) {
     let cmd;
     if (!sudo_pswd) {
         cmd = [
-            'cat "' + tmp_fn + '" > ' + sys_host_path
-            , 'rm -rf ' + tmp_fn
+            `cat "${tmp_fn}" > ${sys_host_path}`
+            , `rm -rf ${tmp_fn}`
         ].join(' && ');
     } else {
         sudo_pswd = sudo_pswd.replace(/'/g, '\\x27');
         cmd = [
-            'echo \'' + sudo_pswd + '\' | sudo -S chmod 777 ' + sys_host_path
-            , 'cat "' + tmp_fn + '" > ' + sys_host_path
-            , 'echo \'' + sudo_pswd + '\' | sudo -S chmod 644 ' + sys_host_path
+            `echo '${sudo_pswd}' | sudo -S chmod 777 ${sys_host_path}`
+            , `cat "${tmp_fn}" > ${sys_host_path}`
+            , `echo '${sudo_pswd}' | sudo -S chmod 644 ${sys_host_path}`
             // , 'rm -rf ' + tmp_fn
         ].join(' && ');
     }
@@ -142,14 +141,21 @@ function apply_UNIX(content, success) {
 
 function _after_apply_unix(callback) {
     let cmd_fn = path.join(work_path, '_restart_mDNSResponder.sh');
-
-    let cmd = [
-        'sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist'
-        , 'sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist'
-        , 'sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist'
-        , 'sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.discoveryd.plist'
-        , 'sudo killall -HUP mDNSResponder'
-    ].join('\n');
+    let cmd = `
+p1=/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
+if [ -f $p1 ]; then
+    sudo launchctl unload -w $p1
+    sudo launchctl load -w $p1
+fi
+
+p2=/System/Library/LaunchDaemons/com.apple.discoveryd.plist
+if [ -f p2 ]; then
+    sudo launchctl unload -w $p2
+    sudo launchctl load -w $p2
+fi
+
+sudo killall -HUP mDNSResponder
+`;
 
     fs.writeFileSync(cmd_fn, cmd, 'utf-8');
 
@@ -219,7 +225,6 @@ SH_event.on('test', () => {
 
 SH_event.on('apply', (content, success) => {
     tryToApply(content, () => {
-
         let cmd = pref.get('after_cmd');
         if (cmd) {
             exec(cmd, function (error, stdout, stderr) {

+ 2 - 2
app/src/lang/en.js

@@ -66,7 +66,7 @@ exports.content = {
     , pref_after_cmd_info: 'The following system commands will be executed when Host applied:'
     , pref_after_cmd_placeholder: 'input your commands here'
     , pref_choice_mode: 'Choide mode'
-    , pref_choice_single: 'Single choice'
-    , pref_choice_multiple: 'Multiple choice'
+    , pref_choice_mode_single: 'Single choice'
+    , pref_choice_mode_multiple: 'Multiple choice'
     , search: 'Search'
 };

+ 1 - 1
app/src/libs/paths.js

@@ -9,7 +9,7 @@ const path = require('path');
 const util = require('./util');
 const platform = process.platform;
 const sys_host_path = platform == 'win32' ?
-    `${process.env.windir}\\system32\\drivers\\etc\\hosts` : // Windows 系统有可能不安装在 C 盘
+    `${process.env.windir || 'C:\\WINDOWS'}\\system32\\drivers\\etc\\hosts` : // Windows 系统有可能不安装在 C 盘
     '/etc/hosts';
 const home_path = util.getUserHome();
 const work_path = path.join(home_path, '.SwitchHosts');

+ 1 - 1
app/version.js

@@ -1 +1 @@
-exports.version = [3,2,1,4180];
+exports.version = [3,2,1,4181];

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