2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2019 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2019-07-12 13:40:00 +02:00
|
|
|
|
|
|
|
|
#include "webassemblyrunconfigurationaspects.h"
|
2022-09-30 20:34:56 +02:00
|
|
|
#include "webassemblytr.h"
|
2019-07-12 13:40:00 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/buildconfiguration.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
2022-10-24 23:44:24 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2021-11-03 17:54:53 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2019-07-12 13:40:00 +02:00
|
|
|
#include <QComboBox>
|
2022-04-22 13:55:55 +02:00
|
|
|
#include <QTextStream>
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
using namespace Utils;
|
2019-07-12 13:40:00 +02:00
|
|
|
|
|
|
|
|
namespace WebAssembly {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
static const char BROWSER_KEY[] = "WASM.WebBrowserSelectionAspect.Browser";
|
|
|
|
|
|
2022-01-12 22:55:10 +01:00
|
|
|
static WebBrowserEntries emrunBrowsers(ProjectExplorer::Target *target)
|
|
|
|
|
{
|
2022-09-30 20:34:56 +02:00
|
|
|
WebBrowserEntries result;
|
|
|
|
|
result.append(qMakePair(QString(), Tr::tr("Default Browser")));
|
2022-01-12 22:55:10 +01:00
|
|
|
if (auto bc = target->activeBuildConfiguration()) {
|
|
|
|
|
const Utils::Environment environment = bc->environment();
|
|
|
|
|
const Utils::FilePath emrunPath = environment.searchInPath("emrun");
|
|
|
|
|
|
|
|
|
|
QtcProcess browserLister;
|
|
|
|
|
browserLister.setEnvironment(environment);
|
|
|
|
|
browserLister.setCommand({emrunPath, {"--list_browsers"}});
|
|
|
|
|
browserLister.start();
|
|
|
|
|
|
|
|
|
|
if (browserLister.waitForFinished())
|
2023-02-14 12:53:28 +01:00
|
|
|
result.append(WebBrowserSelectionAspect::parseEmrunOutput(
|
|
|
|
|
browserLister.readAllRawStandardOutput()));
|
2019-07-12 13:40:00 +02:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WebBrowserSelectionAspect::WebBrowserSelectionAspect(ProjectExplorer::Target *target)
|
2022-01-12 22:55:10 +01:00
|
|
|
: m_availableBrowsers(emrunBrowsers(target))
|
2019-07-12 13:40:00 +02:00
|
|
|
{
|
2022-01-12 22:55:10 +01:00
|
|
|
if (!m_availableBrowsers.isEmpty()) {
|
|
|
|
|
const int defaultIndex = qBound(0, m_availableBrowsers.count() - 1, 1);
|
|
|
|
|
m_currentBrowser = m_availableBrowsers.at(defaultIndex).first;
|
|
|
|
|
}
|
2022-09-30 20:34:56 +02:00
|
|
|
setDisplayName(Tr::tr("Web Browser"));
|
2019-07-12 13:40:00 +02:00
|
|
|
setId("WebBrowserAspect");
|
|
|
|
|
setSettingsKey("RunConfiguration.WebBrowser");
|
2022-04-08 11:35:54 +02:00
|
|
|
|
|
|
|
|
addDataExtractor(this, &WebBrowserSelectionAspect::currentBrowser, &Data::currentBrowser);
|
2019-07-12 13:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 13:51:52 +01:00
|
|
|
void WebBrowserSelectionAspect::addToLayout(Layouting::LayoutBuilder &builder)
|
2019-07-12 13:40:00 +02:00
|
|
|
{
|
|
|
|
|
QTC_CHECK(!m_webBrowserComboBox);
|
2019-10-15 17:20:51 +02:00
|
|
|
m_webBrowserComboBox = new QComboBox;
|
2022-01-12 22:55:10 +01:00
|
|
|
for (const WebBrowserEntry &be : m_availableBrowsers)
|
|
|
|
|
m_webBrowserComboBox->addItem(be.second, be.first);
|
|
|
|
|
m_webBrowserComboBox->setCurrentIndex(m_webBrowserComboBox->findData(m_currentBrowser));
|
2022-07-19 22:51:32 +02:00
|
|
|
connect(m_webBrowserComboBox, &QComboBox::currentIndexChanged, this, [this] {
|
|
|
|
|
m_currentBrowser = m_webBrowserComboBox->currentData().toString();
|
|
|
|
|
emit changed();
|
|
|
|
|
});
|
2022-09-30 20:34:56 +02:00
|
|
|
builder.addItems({Tr::tr("Web browser:"), m_webBrowserComboBox});
|
2019-07-12 13:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebBrowserSelectionAspect::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2019-10-25 19:48:48 +02:00
|
|
|
if (!m_availableBrowsers.isEmpty())
|
2022-01-12 22:55:10 +01:00
|
|
|
m_currentBrowser = map.value(BROWSER_KEY, m_availableBrowsers.first().first).toString();
|
2019-07-12 13:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebBrowserSelectionAspect::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
|
|
|
|
map.insert(BROWSER_KEY, m_currentBrowser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString WebBrowserSelectionAspect::currentBrowser() const
|
|
|
|
|
{
|
|
|
|
|
return m_currentBrowser;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 12:53:28 +01:00
|
|
|
WebBrowserEntries WebBrowserSelectionAspect::parseEmrunOutput(const QByteArray &output)
|
2022-01-12 22:55:10 +01:00
|
|
|
{
|
2023-02-14 12:53:28 +01:00
|
|
|
WebBrowserEntries result;
|
|
|
|
|
QTextStream ts(output);
|
|
|
|
|
QString line;
|
|
|
|
|
static const QRegularExpression regExp(R"( - (.*):\s*(.*))"); // ' - firefox: Mozilla Firefox'
|
|
|
|
|
// ^__1__^ ^______2______^
|
|
|
|
|
while (ts.readLineInto(&line)) {
|
|
|
|
|
const QRegularExpressionMatch match = regExp.match(line);
|
|
|
|
|
if (match.hasMatch())
|
|
|
|
|
result.push_back({match.captured(1), match.captured(2)});
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2022-01-12 22:55:10 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-12 13:40:00 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Webassembly
|