Forráskód Böngészése

綁定python啓動

rambo 9 hónapja
szülő
commit
b4080e7b6c

+ 6 - 0
electron/config/bin.js

@@ -93,5 +93,11 @@ module.exports = {
       cmd: 'npm',
       args: ['-v'],
     },
+    python: {
+      directory: './python',
+      cmd: 'python',
+      args: ['./index.py', '--port=7074'],
+      stdio: "inherit", // ignore
+    },
   },   
 };

+ 27 - 15
electron/config/config.default.js

@@ -41,7 +41,7 @@ module.exports = (appInfo) => {
 
   /**
    * ee框架日志
-   */  
+   */
   config.logger = {
     encoding: 'utf8',
     level: 'INFO',
@@ -51,12 +51,12 @@ module.exports = (appInfo) => {
     rotator: 'day',
     appLogName: 'ee.log',
     coreLogName: 'ee-core.log',
-    errorLogName: 'ee-error.log' 
+    errorLogName: 'ee-error.log'
   }
 
   /**
    * 远程模式-web地址
-   */    
+   */
   config.remoteUrl = {
     enable: false,
     url: 'http://electron-egg.kaka996.com/'
@@ -64,7 +64,7 @@ module.exports = (appInfo) => {
 
   /**
    * 内置socket服务
-   */   
+   */
   config.socketServer = {
     enable: false,
     port: 7070,
@@ -82,11 +82,11 @@ module.exports = (appInfo) => {
 
   /**
    * 内置http服务
-   */     
+   */
   config.httpServer = {
     enable: false,
     https: {
-      enable: false, 
+      enable: false,
       key: '/public/ssl/localhost+1.key',
       cert: '/public/ssl/localhost+1.pem'
     },
@@ -102,7 +102,7 @@ module.exports = (appInfo) => {
       }
     },
     filterRequest: {
-      uris:  [
+      uris: [
         'favicon.ico'
       ],
       returnData: ''
@@ -111,11 +111,11 @@ module.exports = (appInfo) => {
 
   /**
    * 主进程
-   */     
+   */
   config.mainServer = {
     protocol: 'file://',
     indexPath: '/public/dist/index.html',
-  }; 
+  };
 
   /**
    * 硬件加速
@@ -138,7 +138,7 @@ module.exports = (appInfo) => {
    */
   config.jobs = {
     messageLog: true
-  };  
+  };
 
   /**
    * 插件功能
@@ -162,18 +162,30 @@ module.exports = (appInfo) => {
     },
     autoUpdater: {
       enable: true,
-      windows: false, 
-      macOS: false, 
+      windows: false,
+      macOS: false,
       linux: false,
       options: {
-        provider: 'generic', 
+        provider: 'generic',
         url: 'http://kodo.qiniu.com/'
       },
       force: false,
     }
   };
-
+  config.cross = {
+    python: {
+      enable: false,
+      // 程序名
+      name: "pyapp",
+      // 可执行程序路径
+      cmd: "./py/pyapp",
+      // 可执行程序目录
+      directory: "./py",
+      args: ["--port=7074"],
+      appExit: true,
+    },
+  };
   return {
     ...config
   };
-}
+}

+ 22 - 3
electron/config/config.local.js

@@ -23,9 +23,28 @@ module.exports = (appInfo) => {
    */
   config.jobs = {
     messageLog: true
-  };   
-
+  };
+  config.cross = {
+    python: {
+      // 应用运行时启动
+      enable: false,
+      // 程序名
+      name: "pyapp",
+      // 可执行程序路径,或本机的可执行命令
+      // 如果有cmd参数,则执行该命令且需要指定 directory
+      cmd: "python",
+      // 程序目录,如python代码所在目录
+      directory: "./python",
+      // 可执行程序参数,如果配置中的端口被占用,则框架会随机生成一个。
+      args: ["./index.py", "--port=7074"],
+      // 可能python web stdio与node.js stdio有冲突,忽略io。
+      // 如果想要查看控制台输出,请单独启动服务 npm run dev-python
+      stdio: "ignore",
+      // 程序退出时,是否退出electron应用
+      appExit: true,
+    },
+  };
   return {
     ...config
   };
-};
+};

+ 1 - 0
package.json

@@ -5,6 +5,7 @@
   "main": "main.js",
   "scripts": {
     "dev": "ee-bin dev",
+    "dev-python": "ee-bin exec --cmds=python",
     "dev-frontend": "ee-bin dev --serve=frontend",
     "dev-electron": "ee-bin dev --serve=electron",
     "build-frontend": "ee-bin build --cmds=frontend && ee-bin move --flag=frontend_dist",