fix: 检测UOS开发者模式

This commit is contained in:
2022-12-29 11:55:36 +08:00
parent 2ab4ebc0e3
commit fc658f324d
6 changed files with 169 additions and 98 deletions

View File

@@ -10,6 +10,8 @@
DCORE_USE_NAMESPACE
DWIDGET_USE_NAMESPACE
#define UOSCheckFile "/var/lib/deepin/developer-mode/enabled"
int main(int argc, char *argv[])
{
// Get build time
@@ -67,6 +69,27 @@ int main(int argc, char *argv[])
qputenv("QT_QPA_PLATFORM", "dxcb");
}
// Check UOS developer mode.
QFile UOSDevelopFile(UOSCheckFile);
if (UOSDevelopFile.exists() && isDeepinOS)
{
config.setValue("UOS/isUOS", true);
QTextStream UOStextStream(&UOSDevelopFile);
QString lineData = UOStextStream.readLine();
bool devmode = lineData.toInt();
qDebug() << "UOS Developer Mode Status:" << devmode;
config.setValue("UOS/EnableDeveloperMode", devmode);
}
else
{
if (config.contains("UOS/isUOS"))
{
config.remove("UOS/isUOS");
config.remove("UOS/EnableDeveloperMode");
}
}
config.sync(); // 写入更改至 config.ini并同步最新内容
// 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE
qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE");
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-features=UseModernMediaControls");

View File

@@ -322,15 +322,36 @@ void MainWindow::updateUi(int now)
void MainWindow::on_pushButton_14_clicked()
{
QFile upgradeStatus("/tmp/spark-store/upgradeStatus.txt");
if (!upgradeStatus.exists())
// Check UOS
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
if (config.contains("UOS/EnableDeveloperMode") && !config.value("UOS/EnableDeveloperMode").toBool())
{
qDebug() << "UOS Developer Mode has not been enabled!";
QtConcurrent::run([=]
{
auto upgradeP = new QProcess();
upgradeP->startDetached("zenity", QStringList() << "--info"
<< "--text"
<< "UOS开发者模式未开启相关功能被禁用"
<< "--title"
<< "功能禁用提示"
);
upgradeP->waitForStarted();
upgradeP->waitForFinished(30);
upgradeP->deleteLater(); });
}
else
{
QFile upgradeStatus("/tmp/spark-store/upgradeStatus.txt");
if (!upgradeStatus.exists())
{
QtConcurrent::run([=]
{
auto upgradeP = new QProcess();
upgradeP->startDetached("/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade.sh", QStringList());
upgradeP->waitForStarted();
upgradeP->waitForFinished(-1);
upgradeP->deleteLater(); });
}
}
}
}

View File

@@ -89,81 +89,93 @@ void AppIntoPage::openUrl(QUrl url)
ui->d_contributor->setText(info["Contributor"].toString());
ui->label_2->setText(info["More"].toString());
QProcess isInstall;
bool isInstalled;
bool isUpdated;
QString packagename = info["Pkgname"].toString();
isInstall.start("dpkg", QStringList() << "-s" << info["Pkgname"].toString());
qDebug() << info["Pkgname"].toString();
isInstall.waitForFinished(180*1000); // 默认超时 3 分钟
int error = QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
if(error == 0)
// Check UOS
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
if (config.contains("UOS/EnableDeveloperMode") && !config.value("UOS/EnableDeveloperMode").toBool()){
qDebug() << "UOS Developer Mode has not been enabled!";
ui->downloadButton->setText(tr("Developer Mode Disabled"));
ui->downloadButton->setEnabled(false);
ui->downloadButton->show();
}
else // 非 UOS 或 UOS 已经开启开发者模式
{
isInstalled = true;
QProcess isInstall;
bool isInstalled;
bool isUpdated;
QString packagename = info["Pkgname"].toString();
isInstall.start("dpkg", QStringList() << "-s" << info["Pkgname"].toString());
qDebug() << info["Pkgname"].toString();
isInstall.waitForFinished(180 * 1000); // 默认超时 3 分钟
int error = QString::fromStdString(isInstall.readAllStandardError().toStdString()).length();
if (error == 0)
{
isInstalled = true;
QProcess isUpdate;
isUpdate.start("dpkg-query", QStringList() << "--showformat='${Version}'"
<< "--show" << info["Pkgname"].toString());
isUpdate.waitForFinished(180*1000); // 默认超时 3 分钟
QString localVersion = isUpdate.readAllStandardOutput();
localVersion.replace("'", "");
QProcess isUpdate;
isUpdate.start("dpkg-query", QStringList() << "--showformat='${Version}'"
<< "--show" << info["Pkgname"].toString());
isUpdate.waitForFinished(180 * 1000); // 默认超时 3 分钟
QString localVersion = isUpdate.readAllStandardOutput();
localVersion.replace("'", "");
isUpdate.start("dpkg", QStringList() << "--compare-versions" << localVersion << "ge" << info["Version"].toString());
isUpdate.waitForFinished(180*1000); // 默认超时 3 分钟
if(!isUpdate.exitCode())
{
isUpdated = true;
}
else
{
isUpdated = false;
}
isUpdate.start("dpkg", QStringList() << "--compare-versions" << localVersion << "ge" << info["Version"].toString());
isUpdate.waitForFinished(180 * 1000); // 默认超时 3 分钟
if (!isUpdate.exitCode())
{
isUpdated = true;
}
else
{
isInstalled = false;
isUpdated = false;
}
if(isInstalled)
{
if(isUpdated)
{
ui->downloadButton->setText(tr("Reinstall"));
ui->downloadButton->setEnabled(true);
ui->downloadButton->show();
ui->pushButton_3->show();
}
else
{
ui->downloadButton->setText(tr("Upgrade"));
isInstalled = false;
isUpdated = false;
}
if (isInstalled)
{
if (isUpdated)
{
ui->downloadButton->setText(tr("Reinstall"));
ui->downloadButton->setEnabled(true);
ui->downloadButton->show();
ui->pushButton_3->show();
}
else
{
ui->downloadButton->setText(tr("Upgrade"));
ui->downloadButton->setEnabled(true);
ui->downloadButton->show();
ui->pushButton_3->show();
}
}
else
{
ui->downloadButton->setText(tr("Download"));
isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString());
ui->downloadButton->setEnabled(true);
ui->downloadButton->show();
ui->pushButton_3->show();
}
}
else
{
ui->downloadButton->setText(tr("Download"));
isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString());
ui->downloadButton->setEnabled(true);
ui->downloadButton->show();
}
QStringList taglist = info["Tags"].toString().split(";");
QString tmp=info["img_urls"].toString();
qDebug()<<tmp;
if(tmp.left(2)=="[\"")
qDebug() << tmp;
if (tmp.left(2) == "[\"")
{
tmp.remove(0,2);
tmp.remove(0, 2);
}
if(tmp.right(2)=="\"]")
if (tmp.right(2) == "\"]")
{
tmp.remove(tmp.size()-2,tmp.size());
tmp.remove(tmp.size() - 2, tmp.size());
}
QStringList imglist = tmp.split("\",\"");
qDebug()<<imglist;
for(int i=0;i < imglist.size();i++)
qDebug() << imglist;
for (int i = 0; i < imglist.size(); i++)
{
QNetworkAccessManager *naManager;
QNetworkRequest request;