| 269 | } |
| 270 | |
| 271 | void ProviderLauncher::launchProcess(Slot *slot) |
| 272 | { |
| 273 | const LaunchConfig &cfg = slot->cfg; |
| 274 | const QString command = expandVars(cfg.command, slot); |
| 275 | const QStringList args = expandVars(cfg.args, slot); |
| 276 | const QString cwd = cfg.cwd.isEmpty() ? QDir::homePath() : expandVars(cfg.cwd, slot); |
| 277 | const QString name = slot->name; |
| 278 | |
| 279 | auto *proc = new Utils::Process(this); |
| 280 | slot->process = proc; |
| 281 | |
| 282 | Utils::Environment env = Utils::Environment::systemEnvironment(); |
| 283 | env.set(QStringLiteral("PROVIDER_NAME"), slot->name); |
| 284 | for (auto it = cfg.env.constBegin(); it != cfg.env.constEnd(); ++it) |
| 285 | env.set(it.key(), it.value()); |
| 286 | proc->setEnvironment(env); |
| 287 | proc->setWorkingDirectory(Utils::FilePath::fromString(cwd)); |
| 288 | proc->setCommand(Utils::CommandLine{Utils::FilePath::fromString(command), args}); |
| 289 | |
| 290 | proc->setPtyData(Utils::Pty::Data{}); |
| 291 | |
| 292 | connect(proc, &Utils::Process::readyReadStandardOutput, this, [this, name] { |
| 293 | Slot *s = m_slots.value(name, nullptr); |
| 294 | if (!s || !s->process) return; |
| 295 | const QByteArray chunk = s->process->readAllRawStandardOutput(); |
| 296 | if (!chunk.isEmpty()) { |
| 297 | appendScrollback(s, chunk); |
| 298 | emit bytesReceived(s->name, chunk); |
| 299 | } |
| 300 | }); |
| 301 | connect(proc, &Utils::Process::readyReadStandardError, this, [this, name] { |
| 302 | Slot *s = m_slots.value(name, nullptr); |
| 303 | if (!s || !s->process) return; |
| 304 | const QByteArray chunk = s->process->readAllRawStandardError(); |
| 305 | if (!chunk.isEmpty()) { |
| 306 | appendScrollback(s, chunk); |
| 307 | emit bytesReceived(s->name, chunk); |
| 308 | } |
| 309 | }); |
| 310 | connect(proc, &Utils::Process::started, this, [this, name] { |
| 311 | Slot *s = m_slots.value(name, nullptr); |
| 312 | if (!s) |
| 313 | return; |
| 314 | s->started = true; |
| 315 | if (s->startTimer) { |
| 316 | s->startTimer->stop(); |
| 317 | s->startTimer->deleteLater(); |
| 318 | s->startTimer = nullptr; |
| 319 | } |
| 320 | if (s->state != Starting) |
| 321 | return; |
| 322 | if (s->cfg.readyUrl.isEmpty()) { |
| 323 | changeState(s, Ready); |
| 324 | return; |
| 325 | } |
| 326 | s->probeStart.start(); |
| 327 | changeState(s, Probing); |
| 328 | scheduleReadyProbe(s); |