Can't build GUI-optional (CLI mode) app because of qode.

Đang mở
#986 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp, javascript, node.js
Lĩnh vực
cli, desktop

Hướng nghiên cứu

Start with the supplied starter-repo reproduction and compare node dist --cli with qode dist --cli, including the version where the GUI branch is removed. Trace qode's event-loop initialization and determine how to defer it until NodeGUI is used; done means the CLI process exits after its work while the GUI path remains alive.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug
I want to create an app that can work with gui by default but optionally allow to pass some cli flags to skip the GUI.

But qode injects stuff into node.js event loop, causing simple console.log(123); app to run forever (until I forcibly quit it with ctrl+c or process.exit() in the code).

Creating a "starter script", that will try to decide if I should run the app with node or qode (and replace static imports with dynamic imports of nodegui) is no perfect, because sometimes I want to do cli only background job, but sometimes I want to popup a window to let user decide about something.

Adding process.exit(0) at the end of my script isn't too perfect again, because I'd have to keep track of all started background tasks somehow, to be sure if that's the right moment to call process.exit();

Is there a way to rework qode that it will only start to inject event loop stuff on demand, when a first QT stuff is created?

This way node can close the app automatically when all the background stuff ends.

To Reproduce
Steps to reproduce the behavior:

  1. Use this code in the starter repo:
const action = process.argv[2];

if (action === "--cli") {
  console.log("doing stuff via cli");
}
else {
  (async () => {
    const { QMainWindow, QLabel } = await import("@nodegui/nodegui")
    const win = new QMainWindow();
    win.setWindowTitle("Hello World");

    const label = new QLabel();
    label.setText("Do stuff via GUI");
    win.setCentralWidget(label);
    win.show();

    (global as any).win = win;
  })();
}

Run node dist --cli - this is how node is behaving - it will quit the app after console log
Run qode dist --cli - qode will keep app running forever, even if no nodegui stuff is ever used (you can even remove the else)

Expected behavior
With above code app should quit automatically with qode when run with --cli flag. It should not without the flag of course to let GUI live.

Screenshots
no screenshots

Desktop (please complete the following information):

  • OS: Linux
  • NodeGUI version: 0.58.0-rc2
  • OS Version: Mint 21.1 Cinnamon

Additional context
It's all written in the top.

Ngôn ngữ chính
C++
Star
9.2k
Fork
315
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nodegui/nodegui

Tất cả issue của nodegui/nodegui

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.