Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过配置隐藏子进程窗口 #3728

Closed
1 task done
ghost opened this issue May 27, 2019 · 10 comments · Fixed by eggjs/egg-cluster#92
Closed
1 task done

通过配置隐藏子进程窗口 #3728

ghost opened this issue May 27, 2019 · 10 comments · Fixed by eggjs/egg-cluster#92

Comments

@ghost
Copy link

ghost commented May 27, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

在windows上部署时,多个命令行窗口影响测试和客户部署操作,而且不够美观、简洁

What does the proposed API look like?

分别在下面两个位置添加上这个参数:windowsHide 可以达到隐藏 npm start 时打开的多个窗口,
1.

//egg-cluster\lib\master.js

forkAgentWorker() {
   this.agentStartTime = Date.now();

   const args = [ JSON.stringify(this.options) ];
   const opt = {
     windowsHide: true 
   };
//cfork\index.js
/**
 * fork worker with certain settings
 */
function forkWorker(settings) {
  if (settings) {
    settings.windowsHide = true;
    cluster.settings = settings;
    cluster.setupMaster();
  } else {
    cluster.setupMaster({ windowsHide: true });
  }
  return cluster.fork(attachedEnv);
}

我希望将这个功能编写到配置中

// config/config.default.js

// 通过配置cluster的windowsHide属性达到隐藏/显示   npm start 时打开的多个窗口
 config.cluster = {
    windowsHide: true,
  };

@qingdengyue
Copy link
Contributor

image
Node 9.4.0 新增了原生的支持,然而这个参数不起作用(至少在我的 Win10 上不起作用)。这个参数稳定了,就方便了。

@atian25
Copy link
Member

atian25 commented May 28, 2019

@ghost
Copy link
Author

ghost commented May 28, 2019 via email

@ghost
Copy link
Author

ghost commented May 28, 2019

  1. Node Version: v10.12.0
  2. Egg Version: v2.2.1
  3. Plugin Name:
  4. Plugin Version:
  5. Platform: Windows 10
  6. Mini Showcase Repository:
    api上有这一段 child_process.fork() 方法是 child_process.spawn()
    child_process.spawn()是支持这个参数的。
    我的理解是fork是从spawn上封装的,如果没有特意屏蔽额外参数,这个参数是可以传过去的

我在本机实验是有效的

image text

@atian25
Copy link
Member

atian25 commented May 28, 2019

你试试启动命令直接传递 --windows-hide 看看,应该可以传递进去的

@ghost
Copy link
Author

ghost commented May 28, 2019 via email

@qingdengyue
Copy link
Contributor

qingdengyue commented May 28, 2019

@atian25

@qingdengyue https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_child_process_fork_modulepath_args_options

fork 好像是不支持的,只有 spwan 等才有

fork的options参数最终会传递给spwan的options参数,没有对特殊字段进行处理,所以fork也支持这个windowsHide参数,文档里没写
https://github.com/nodejs/node/blob/master/lib/child_process.js

你试试启动命令直接传递 --windows-hide 看看,应该可以传递进去的

--windows-hide 方式的参数在 args 这个对象上 https://github.com/eggjs/egg-cluster/blob/d424239e56fec96d9e9c29e9bb1d96a46acc97b5/lib/master.js#L215,fork的options参数没有这个值

cfork目前没有支持windowsHide这个参数,所以可能也需要支持一下。cluster组件已经支持了这个参数。
https://nodejs.org/dist/latest-v12.x/docs/api/cluster.html#cluster_cluster_settings

@ghost
Copy link
Author

ghost commented May 28, 2019

@qingdengyue

厉害厉害

@atian25
Copy link
Member

atian25 commented May 30, 2019

欢迎提 PR

@qingdengyue
Copy link
Contributor

@atian25 修改好了,看看这样实现行不行~ 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants