alixez 7 年之前
父节点
当前提交
d9b246db25
共有 5 个文件被更改,包括 37 次插入7 次删除
  1. 3 1
      .gitignore
  2. 6 0
      app/index.js
  3. 20 1
      app/tool/hexo-shell.js
  4. 3 1
      app/tool/thread_kill.js
  5. 5 4
      package.json

+ 3 - 1
.gitignore

@@ -41,4 +41,6 @@ jspm_packages
 .node_repl_history
 
 # Jetbrains IDEs
-.idea
+.idea
+
+package-lock.json

+ 6 - 0
app/index.js

@@ -20,6 +20,12 @@
 
 'use strict';
 
+// on darwin, to rewrite path
+if (process.platform === "darwin") {
+    const shellEnvs = require('shell-env').sync()
+    process.env.PATH = shellEnvs.PATH;
+}
+
 const app = require('electron').app,
       MoeditorApplication = require('./moe-app');
 

+ 20 - 1
app/tool/hexo-shell.js

@@ -42,10 +42,12 @@ var shellServer = (function () {
 
         execCmd(command) {
             let flagOK = false;
+            
             clearTimeout(_shellServer.timeID);
             _shellServer.closeMsg = false;
             _shellServer.lastWindow = require('electron').BrowserWindow.getFocusedWindow();
             _shellServer.isForce = false;
+            log.info("path:", process.env.PATH)
             log.info('Begin execute:', `[${moeApp.hexo.config.__basedir}] [${command}]`);
             _shellServer.shellProcess = exec(command, {cwd: moeApp.hexo.config.__basedir});
             _shellServer.sendConsole('<i class="fa fa-spinner fa-pulse fa-fw margin-bottom"></i>' + __("Executing"), 'info', 'ban');
@@ -58,7 +60,24 @@ var shellServer = (function () {
                 if (/INFO  Hexo is running at https?:\/+/.test(data)) {
                     flagOK = true;
                     _shellServer.sendConsole('<i class="fa fa-spinner fa-pulse fa-fw margin-bottom"></i>' + __('ServerStart'), 'info', 'stop');
-                    require('electron').shell.openExternal(data.match(/INFO  Hexo is running at (https?:\/+[^\/]+\/). Press Ctrl.C to stop./i)[1])
+
+                    // fix 这里会报异常
+                    const externalParams = function() {
+                        const d = data.match(/INFO  Hexo is running at (https?:\/+[^\/]+\/). Press Ctrl.C to stop./i);
+                        if (!d) {
+                            return null
+                        }
+
+                        if (d.length > 2) {
+                            return d[1]
+                        }
+
+                        return null
+                    }();
+                
+                    if (externalParams) {
+                        require('electron').shell.openExternal(externalParams)
+                    }
                 } else {
                     _shellServer.timeID = setTimeout(() => {
                         if (!flagOK) {

+ 3 - 1
app/tool/thread_kill.js

@@ -81,7 +81,9 @@ function killAll(tree, signal, callback){
     }
 
     if (callback) {
-        return callback();
+        if (typeof callback === 'function') {
+            return callback();
+        }
     }
 }
 

+ 5 - 4
package.json

@@ -51,10 +51,10 @@
           "path": "/Applications"
         }
       ],
-	  "window":{
-		"width": 480,
-		"height": 338
-	  }
+      "window": {
+        "width": 480,
+        "height": 338
+      }
     },
     "linux": {
       "target": [
@@ -119,6 +119,7 @@
     "qiniu": "^7.1.1",
     "raphael": "^2.2.1",
     "request": "^2.83.0",
+    "shell-env": "^2.0.1",
     "strip-indent": "^2.0.0",
     "swig": "^1.4.2",
     "swig-extras": "0.0.1",