| 88 | namespace DevTools |
| 89 | { |
| 90 | void Initialize() |
| 91 | { |
| 92 | QString chromePath = settings.value(CHROME_LOCATION).toString(); |
| 93 | if (chromePath.isEmpty()) |
| 94 | { |
| 95 | for (auto [_, process] : GetAllProcesses()) |
| 96 | if (process && process->find(L"\\chrome.exe") != std::string::npos) chromePath = S(process.value()); |
| 97 | wchar_t programFiles[MAX_PATH + 100] = {}; |
| 98 | for (auto folder : { CSIDL_PROGRAM_FILESX86, CSIDL_PROGRAM_FILES, CSIDL_LOCAL_APPDATA }) |
| 99 | { |
| 100 | SHGetFolderPathW(NULL, folder, NULL, SHGFP_TYPE_CURRENT, programFiles); |
| 101 | wcscat_s(programFiles, L"/Google/Chrome/Application/chrome.exe"); |
| 102 | if (std::filesystem::exists(programFiles)) chromePath = S(programFiles); |
| 103 | } |
| 104 | } |
| 105 | auto chromePathEdit = new QLineEdit(chromePath); |
| 106 | static struct : QObject |
| 107 | { |
| 108 | bool eventFilter(QObject* object, QEvent* event) |
| 109 | { |
| 110 | if (auto mouseEvent = dynamic_cast<QMouseEvent*>(event)) |
| 111 | if (mouseEvent->button() == Qt::LeftButton) |
| 112 | if (QString chromePath = QFileDialog::getOpenFileName(nullptr, TRANSLATION_PROVIDER, "/", "Google Chrome (*.exe)"); !chromePath.isEmpty()) |
| 113 | ((QLineEdit*)object)->setText(chromePath); |
| 114 | return false; |
| 115 | } |
| 116 | } chromeSelector; |
| 117 | chromePathEdit->installEventFilter(&chromeSelector); |
| 118 | QObject::connect(chromePathEdit, &QLineEdit::textChanged, [chromePathEdit](QString path) { settings.setValue(CHROME_LOCATION, path); }); |
| 119 | display->addRow(CHROME_LOCATION, chromePathEdit); |
| 120 | auto headlessCheck = new QCheckBox(); |
| 121 | auto startButton = new QPushButton(START_DEVTOOLS), stopButton = new QPushButton(STOP_DEVTOOLS); |
| 122 | headlessCheck->setChecked(settings.value(HIDE_CHROME, true).toBool()); |
| 123 | QObject::connect(headlessCheck, &QCheckBox::clicked, [](bool headless) { settings.setValue(HIDE_CHROME, headless); }); |
| 124 | QObject::connect(startButton, &QPushButton::clicked, [chromePathEdit, headlessCheck] { Start(S(chromePathEdit->text()), headlessCheck->isChecked()); }); |
| 125 | QObject::connect(stopButton, &QPushButton::clicked, &Close); |
| 126 | auto buttons = new QHBoxLayout(); |
| 127 | buttons->addWidget(startButton); |
| 128 | buttons->addWidget(stopButton); |
| 129 | display->addRow(HIDE_CHROME, headlessCheck); |
| 130 | auto autoStartCheck = new QCheckBox(); |
| 131 | autoStartCheck->setChecked(settings.value(AUTO_START, false).toBool()); |
| 132 | QObject::connect(autoStartCheck, &QCheckBox::clicked, [](bool autoStart) { settings.setValue(AUTO_START, autoStart); }); |
| 133 | display->addRow(AUTO_START, autoStartCheck); |
| 134 | display->addRow(buttons); |
| 135 | statusLabel = new QLabel("Stopped"); |
| 136 | statusLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
| 137 | display->addRow(DEVTOOLS_STATUS, statusLabel); |
| 138 | if (autoStartCheck->isChecked()) QMetaObject::invokeMethod(startButton, &QPushButton::click, Qt::QueuedConnection); |
| 139 | } |
| 140 | |
| 141 | void Close() |
| 142 | { |