oldj 10 years ago
parent
commit
a6ac794eae
4 changed files with 9 additions and 14 deletions
  1. 1 1
      README.md
  2. 4 7
      app/js/cf.js
  3. 2 4
      app/js/sh.js
  4. 2 2
      app/main.js

+ 1 - 1
README.md

@@ -8,7 +8,7 @@
  - Latest Stable: 3.0.0
 
 
-这是一个用于快速切换 hosts 文件的小程序,基于 [Electron](http://electron.atom.io/) 开发。
+这是一个用于快速切换 hosts 文件的小程序,基于 [Electron](http://electron.atom.io/) 开发,同时使用了 [Vue.js](http://vuejs.org/) 以及 [CodeMirror](http://codemirror.net/) 等框架/库
 
 
 ## 功能特性:

+ 4 - 7
app/js/cf.js

@@ -109,16 +109,14 @@ function saveHost(content, sudo_pswd, callback) {
         exec(cmd, function (err, stdout, stderr) {
             if (!err) {
                 fs.writeFile(sys_host_path, content, 'utf-8', function (err) {
-                    if (err) {
-                        callback(err);
-                        return;
-                    }
-
                     // change the host file's permission back
                     cmd = `echo '${sudo_pswd}' | sudo -S chmod 644 ${sys_host_path}`;
                     exec(cmd, function (err) {
-                        callback(err);
+                        //callback(err);
+                        err && console.log(err);
                     });
+
+                    callback(err);
                 });
             } else {
                 callback(err);
@@ -129,7 +127,6 @@ function saveHost(content, sudo_pswd, callback) {
         fs.writeFile(sys_host_path, content, 'utf-8', function (err) {
             callback(err);
         });
-
     }
 
 }

+ 2 - 4
app/js/sh.js

@@ -186,7 +186,6 @@ const app = new Vue({
 
             let s_hosts = on_hosts.join('\n\n# --------------------\n\n');
             s_hosts = `# SwitchHosts!\n${s_hosts}`;
-            //console.log(s_hosts);
             cf.saveHost(s_hosts, this.sudo_pswd, (err) => {
                 if (err) {
                     console.log(err);
@@ -216,9 +215,9 @@ const app = new Vue({
             setTimeout(() => $('#ipt-pswd').focus(), 100);
         },
         chkPswd: function () {
-            this.switchHost(this._to_switch_host);
+            //this.switchHost(this._to_switch_host);
             this.closePrompt();
-            this._to_switch_host = null;
+            //this._to_switch_host = null;
 
             let f;
             while (f = this.on_after_permission.shift()) {
@@ -297,7 +296,6 @@ $(document).ready(function () {
 
         let info = cm.lineInfo(n);
         //cm.setGutterMarker(n, "breakpoints", info.gutterMarkers ? null : makeMarker());
-        //console.log(info);
         let ln = info.text;
         if (/^\s*$/.test(ln)) return;
 

+ 2 - 2
app/main.js

@@ -13,8 +13,8 @@ const http = require('http');
 const Menu = require('menu');
 //const Tray = require('tray');
 
-let is_debug = true;
-//let is_debug = false;
+//let is_debug = true;
+let is_debug = false;
 
 
 // Report crashes to our server.