Browse Source

Merge branch 'feature/m5' into develop

oldj 9 years ago
parent
commit
1df7aae499

+ 1 - 0
.eslintrc.js

@@ -24,6 +24,7 @@ module.exports = {
         'quotes': [
             'error',
             'single'
+            // 'backtick'
         ],
         'semi': [
             'error',

+ 2 - 0
.gitignore

@@ -14,6 +14,8 @@ src/configs.json
 *.swh
 *.iml
 
+/node_modules
+tmp
 node_modules
 UserInterfaceState.xcuserstate
 xcdebugger

+ 1 - 1
app/SH3/MacGap/SwitchHosts!-Info.plist

@@ -21,7 +21,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>3241</string>
+	<string>3464</string>
 	<key>LSApplicationCategoryType</key>
 	<string>public.app-category.developer-tools</string>
 	<key>LSMinimumSystemVersion</key>

+ 7 - 18
app/SH3/public/index.html

@@ -19,21 +19,7 @@
 					<span class="title">{{ lang.sys_host_title }}</span>
 				</li>
 			</ul>
-			<ul id="custom-list">
-				<li v-cloak
-					v-for="host in hosts.list | filterBy mySearch"
-					@click="selectHost(host)"
-					v-draggable="{index: $index, dragged: 'dragged'}"
-					v-dropzone="sort(hosts.list, $index, $droptag, $dropdata)"
-					:class="{selected:host==current_host}">
-					<!--<i class="switch" @click="switchHost(host)" :class="{'on':host.on}"></i>-->
-					<i class="iconfont switch" @click="switchHost(host)"
-					   :class="{'icon-on':host.on, 'icon-off':!host.on}"></i>
-					<i class="iconfont icon-doc i-h"></i>
-					<span class="title">{{ host.title }}</span>
-					<i class="iconfont icon-edit btn-edit" @click="edit(host)"></i>
-				</li>
-			</ul>
+			<host-list v-bind:host="host" v-bind:hosts="hosts"></host-list>
 		</div>
 		<div class="operations">
 			<div id="search-bar" v-show="is_search_bar_show" v-cloak>
@@ -60,7 +46,8 @@
 	<div id="body">
 		<div class="status">
 			<div class="icons">
-				<i class="iconfont icon-earth" v-if="current_host.where == 'remote'" title="{{ lang.remote_hosts }}"></i>
+				<i class="iconfont icon-earth" v-if="current_host.where == 'remote'"
+				   title="{{ lang.remote_hosts }}"></i>
 				<i class="iconfont icon-lock2" v-if="current_host.is_editable == false" title="{{ lang.readonly }}"></i>
 			</div>
 		</div>
@@ -106,7 +93,8 @@
 			</div>
 			<div class="ln" v-if="current_edit_host.where=='remote'">
 				<label for="ipt-refresh-interval">{{ lang.auto_refresh }}</label>
-				<select name="host_refresh_interval" id="ipt-refresh-interval" v-model="current_edit_host.refresh_interval">
+				<select name="host_refresh_interval" id="ipt-refresh-interval"
+						v-model="current_edit_host.refresh_interval">
 					<option value="{{ opt[0] }}" v-for="opt in refresh_options">{{ opt[1] }}</option>
 				</select>
 				<span class="info">
@@ -118,7 +106,8 @@
 					<i class="iconfont icon-delete"></i>
 					{{ lang.del_host }}
 				</a>
-				<a href="#" class="refresh-host" @click="refreshHosts(current_host)" v-if="current_edit_host.where=='remote'">
+				<a href="#" class="refresh-host" @click="refreshHosts(current_host)"
+				   v-if="current_edit_host.where=='remote'">
 					<i class="iconfont icon-refresh"></i>
 					{{ lang.refresh }}
 				</a>

File diff suppressed because it is too large
+ 0 - 1
app/SH3/public/js/main.js


+ 73 - 0
app/src/component/hostList.js

@@ -0,0 +1,73 @@
+/**
+ * @author oldj
+ * @blog http://oldj.net
+ */
+
+'use strict';
+
+exports.Component = Vue.component('host-list', {
+    //el: '#momolist',
+    props: ['host', 'hosts'],
+    data: function () {
+        return {
+            current_host: null
+        };
+    },
+    methods: {
+        selectHost: function (host) {
+            this.$dispatch('select-host', host);
+        },
+        toggleHost: function (host) {
+            this.$dispatch('toggle-host', host);
+        },
+        edit: function (host) {
+            this.$dispatch('edit-host-info', host);
+        },
+        sort: function (list, id, tag, data) {
+            var tmp = list[data.index];
+            list.splice(data.index, 1);
+            list.splice(id, 0, tmp);
+
+            this.$dispatch('do-save', 1);
+        }
+    },
+    // watch: {},
+    // ready: function () {
+    // },
+    // destroyed: function () {
+    // },
+    events: {
+        'current-host-change': function (current_host) {
+            this.current_host = current_host;
+        }
+    },
+    template: `<ul id="custom-list">
+            <li
+                v-for="host in hosts.list | filterBy mySearch"
+                @click="selectHost(host)"
+                v-draggable="{index: $index, dragged: 'dragged'}"
+                v-dropzone="sort(hosts.list, $index, $droptag, $dropdata)"
+                :class="{selected:host==current_host}">
+                <i class="iconfont switch" @click="toggleHost(host)"
+                    :class="{'icon-on':host.on, 'icon-off':!host.on}"></i>
+                <i class="iconfont icon-doc i-h"></i>
+                <span class="title">{{ host.title }}</span>
+                <i class="iconfont icon-edit btn-edit" @click="edit(host)"></i>
+            </li>
+        </ul>`
+    /*
+     <li v-cloak
+     v-for="host in hosts.list | filterBy mySearch"
+     @click="selectHost(host)"
+     v-draggable="{index: $index, dragged: 'dragged'}"
+     v-dropzone="sort(hosts.list, $index, $droptag, $dropdata)"
+     :class="{selected:host==current_host}">
+     <i class="iconfont switch" @click="switchHost(host)"
+     :class="{'icon-on':host.on, 'icon-off':!host.on}"></i>
+     <i class="iconfont icon-doc i-h"></i>
+     <span class="title">{{ host.title }}</span>
+     <i class="iconfont icon-edit btn-edit" @click="edit(host)"></i>
+     </li>
+     */
+});
+

+ 1 - 1
app/src/config.js

@@ -7,7 +7,7 @@
 
 module.exports = {
     VERSION: '3.1.2'
-    , bundle_version: 3241
+    , bundle_version: 3464
     , url_chk_version: 'http://oldj.github.io/SwitchHosts/v.txt'
     , url_homepage: 'http://oldj.github.io/SwitchHosts/'
     , url_feedback: 'https://github.com/oldj/SwitchHosts/issues'

+ 91 - 0
app/src/g_test.js

@@ -0,0 +1,91 @@
+/**
+ * @author oldj
+ * @blog http://oldj.net
+ *
+ * for testing
+ */
+
+'use strict';
+
+(function () {
+    if (typeof MacGap != 'undefined') {
+        return;
+    }
+
+    window.MacGap = {
+        homePath: '~'
+    };
+
+    MacGap.File = {
+        exists: function (fn) {
+            if (fn.indexOf('data.json') != -1) {
+                return false;
+            }
+            return true;
+        },
+        read: function (fn) {
+            console.log('read', fn);
+            if (fn == '/etc/hosts') {
+                return `# SwitchHosts!
+##
+# Host Database
+#
+# localhost is used to configure the loopback interface
+# when the system is booting.  Do not change this entry.
+##
+127.0.0.1	localhost
+255.255.255.255	broadcasthost
+::1             localhost`;
+            } else if (fn.indexOf('data.json') != -1) {
+                return '{}';
+            } else if (fn.indexOf('preferences.json') != -1) {
+                return '{"is_dock_icon_hidden":false}';
+            }
+            return '';
+        },
+        write: function () {
+
+        }
+    };
+
+    function Menu() {
+        this.submenu = this;
+    }
+
+    Menu.prototype = {
+        getItem: function (name) {
+            return new Menu();
+        },
+        addItem: function () {
+        },
+        addSeparator: function () {
+        }
+    };
+
+    MacGap.Menu = {
+        getItem: function (name) {
+            return new Menu();
+        },
+        create: function () {
+            return new Menu();
+        }
+    };
+
+    MacGap.Dock = {
+        showIcon: function () {}
+    };
+
+    MacGap.StatusItem = {
+        create: function () {
+
+        }
+    };
+
+    MacGap.Task = {
+        create: function () {
+          return {
+              launch: function () {}
+          };
+        }
+    };
+})();

+ 1 - 1
app/src/lang.js

@@ -53,7 +53,7 @@ var languages = {
         , host_title: 'host 方案名'
         , host_title_cant_be_empty: 'Host 方案名不能为空!'
         , sys_host_title: '系统 Hosts'
-        , input_sudo_pswd: '请输入管理员密码'
+        , input_sudo_pswd: '请输入您的开机密码'
         , sudo_pswd: '密码'
         , del_host: '删除当前 host'
         , confirm_del: '确定要删除此 host 吗?'

+ 24 - 8
app/src/main.js

@@ -8,6 +8,9 @@
 /* global Vue */
 
 var config = require('./config');
+// $-FOR-TEST
+require('./g_test');
+// $-END
 //Vue.config.debug = true;
 var dnd = require('./vue_dnd');
 Vue.use(dnd);
@@ -18,6 +21,8 @@ var lang = require('./lang').getLang(navigator.language);
 var stat = require('./stat');
 var tray_obj;
 
+require('./component/hostList');
+
 var app = new Vue({
     el: '#sh-app',
     data: {
@@ -245,8 +250,9 @@ var app = new Vue({
         },
         selectHost: function (host) {
             this.current_host = host;
+            this.$broadcast('current-host-change', host);
         },
-        switchHost: function (host) {
+        toggleHost: function (host) {
             if (!host) return;
             this._to_switch_host = host;
             if (!host.is_sys) {
@@ -276,6 +282,7 @@ var app = new Vue({
                 is_editable: false,
                 where: 'sys'
             };
+            this.$broadcast('current-host-change', this.current_host);
         },
         getShowHosts: function () {
             var list = [];
@@ -415,13 +422,6 @@ var app = new Vue({
             this.caculateHosts();
             this.doSave(1);
         },
-        sort: function (list, id, tag, data) {
-            var tmp = list[data.index];
-            list.splice(data.index, 1);
-            list.splice(id, 0, tmp);
-
-            this.doSave(1);
-        },
         move: function (from, to, id, tag, data) {
             var tmp = from[data.index];
             from.splice(data.index, 1);
@@ -455,6 +455,8 @@ var app = new Vue({
         },
 
         mySearch: function (item) {
+            if (!item) return false;
+            
             var kw = this.search_keyword;
             var r = this.search_regexp;
             item._is_show = true;
@@ -501,6 +503,20 @@ var app = new Vue({
             agent.log(obj);
             return 1;
         }
+    },
+    events: {
+        'select-host': function (host) {
+            this.selectHost(host);
+        },
+        'toggle-host': function (host) {
+            this.toggleHost(host);
+        },
+        'edit-host-info': function (host) {
+            this.edit(host);
+        },
+        'do-save': function (now) {
+            this.doSave(now);
+        }
     }
 });
 

+ 1 - 1
app/src/menu.js

@@ -58,7 +58,7 @@ function initTray(app) {
                 on: !!host.on,
                 index: idx + 2
             }, function () {
-                app.switchHost(host);
+                app.toggleHost(host);
             });
         });
 

+ 29 - 14
gulpfile.js

@@ -15,6 +15,8 @@ const uglify = require('gulp-uglify');
 const browserify = require('gulp-browserify');
 const header = require('gulp-header');
 // const stylus = require('gulp-stylus');
+const babel = require('gulp-babel');
+const replace = require('gulp-replace-task');
 const args = require('yargs').argv;
 const moment = require('moment');
 
@@ -93,22 +95,35 @@ gulp.task('ver', function () {
 
 gulp.task('js', ['ver'], function () {
     const config = require('./app/src/config');
-    
-    gulp.src(['app/src/main.js'])
-        .pipe(shell(TPL_FILE_INFO))
-        //.pipe(sourcemaps.init())
-        .pipe(browserify({
-            debug: IS_DEBUG
+
+    let s = gulp.src(['app/src/**/*.js'])
+        .pipe(babel({
+            presets: ['es2015']
         }))
-        .pipe(gulpif(!IS_DEBUG, uglify({
-            output: output,
-            compress: {
-                drop_console: !IS_DEBUG
-            }
+        .pipe(gulpif(!IS_DEBUG, replace({
+            patterns: [{
+                match: /\/\/\s*\$-FOR-TEST[\s\S]*?\/\/\s*\$-END/ig,
+                replacement: ''
+            }]
         })))
-        .pipe(header(`/* ${moment().format('YYYY-MM-DD HH:mm:ss')} v${config.bundle_version} */\n`))
-        .pipe(gulp.dest('app/SH3/public/js'))
-    ;
+        .pipe(gulp.dest('tmp/'));
+
+    s.on('end', () => {
+        gulp.src(['tmp/main.js'])
+            .pipe(shell(TPL_FILE_INFO))
+            .pipe(browserify({
+                debug: IS_DEBUG
+            }))
+            .pipe(gulpif(!IS_DEBUG, uglify({
+                output: output,
+                compress: {
+                    drop_console: true
+                }
+            })))
+            .pipe(header(`/* ${moment().format('YYYY-MM-DD HH:mm:ss')} v${config.bundle_version} */\n`))
+            .pipe(gulp.dest('app/SH3/public/js'))
+        ;
+    });
 });
 
 gulp.task('default', function () {

+ 7 - 4
package.json

@@ -3,15 +3,18 @@
   "version": "1.0.0",
   "description": "",
   "main": "gulpfile.js",
-  "dependencies": {
-    "electron-packager": "^5.1.1"
-  },
+  "dependencies": {},
   "devDependencies": {
+    "babel-preset-es2015": "^6.6.0",
     "codemirror": "~5.9.0",
+    "electron-packager": "^7.0.1",
+    "esutils": "^2.0.2",
     "gulp": "~3.9.0",
+    "gulp-babel": "^6.1.2",
     "gulp-browserify": "~0.5.1",
     "gulp-header": "^1.7.1",
     "gulp-if": "~2.0.0",
+    "gulp-replace-task": "^0.11.0",
     "gulp-shell": "~0.5.1",
     "gulp-stylus": "~2.1.1",
     "gulp-uglify": "~1.5.1",
@@ -25,4 +28,4 @@
   },
   "author": "",
   "license": "ISC"
-}
+}

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