Try system font config once in snap build.

This commit is contained in:
John Preston 2020-03-30 12:18:50 +04:00
parent 86b9927965
commit 0d58f1c9fa
7 changed files with 80 additions and 20 deletions

View File

@ -52,6 +52,14 @@ void UiIntegration::activationFromTopPanel() {
Platform::IgnoreApplicationActivationRightNow();
}
void UiIntegration::startFontsBegin() {
Platform::FallbackFontConfigCheckBegin();
}
void UiIntegration::startFontsEnd() {
Platform::FallbackFontConfigCheckEnd();
}
std::shared_ptr<ClickHandler> UiIntegration::createLinkHandler(
EntityType type,
const QString &text,

View File

@ -23,6 +23,9 @@ public:
void textActionsUpdated() override;
void activationFromTopPanel() override;
void startFontsBegin() override;
void startFontsEnd() override;
std::shared_ptr<ClickHandler> createLinkHandler(
EntityType type,
const QString &text,

View File

@ -44,6 +44,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
using namespace Platform;
using Platform::File::internal::EscapeShell;
namespace Platform {
namespace {
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
@ -95,23 +96,27 @@ bool RunShellCommand(const QByteArray &command) {
return true;
}
void FallbackFontConfig() {
#ifdef TDESKTOP_USE_FONTCONFIG_FALLBACK
const auto custom = cWorkingDir() + "tdata/fc-custom-1.conf";
const auto finish = gsl::finally([&] {
if (QFile(custom).exists()) {
LOG(("Custom FONTCONFIG_FILE: ") + custom);
qputenv("FONTCONFIG_FILE", QFile::encodeName(custom));
}
});
[[nodiscard]] bool CheckFontConfigCrash() {
return InSnap();
}
[[nodiscard]] QString FallbackFontConfigCheckPath() {
return cWorkingDir() + "tdata/fc-check";
}
#ifdef TDESKTOP_USE_FONTCONFIG_FALLBACK
[[nodiscard]] bool BadFontConfigVersion() {
if (CheckFontConfigCrash()) {
return QFile(FallbackFontConfigCheckPath()).exists();
}
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start("fc-list", QStringList() << "--version");
process.waitForFinished();
if (process.exitCode() > 0) {
LOG(("App Error: Could not start fc-list. Process exited with code: %1.").arg(process.exitCode()));
return;
return false;
}
QString result(process.readAllStandardOutput());
@ -120,20 +125,31 @@ void FallbackFontConfig() {
QVersionNumber version = QVersionNumber::fromString(result.split("version ").last());
if (version.isNull()) {
LOG(("App Error: Could not get version from fc-list output."));
return;
return false;
}
LOG(("Fontconfig version: %1.").arg(version.toString()));
if (version < QVersionNumber::fromString("2.13")) {
if (qgetenv("TDESKTOP_FORCE_CUSTOM_FONTCONFIG").isEmpty()) {
return;
return false;
}
}
QFile(":/fc/fc-custom.conf").copy(custom);
#endif // TDESKTOP_USE_FONTCONFIG_FALLBACK
return true;
}
void FallbackFontConfig() {
if (BadFontConfigVersion()) {
const auto custom = cWorkingDir() + "tdata/fc-custom-1.conf";
QFile(":/fc/fc-custom.conf").copy(custom);
if (QFile(custom).exists()) {
LOG(("Custom FONTCONFIG_FILE: ") + custom);
qputenv("FONTCONFIG_FILE", QFile::encodeName(custom));
}
}
}
#endif // TDESKTOP_USE_FONTCONFIG_FALLBACK
bool GenerateDesktopFile(
const QString &targetPath,
const QString &args,
@ -208,8 +224,6 @@ bool GenerateDesktopFile(
} // namespace
namespace Platform {
void SetApplicationIcon(const QIcon &icon) {
QApplication::setWindowIcon(icon);
}
@ -405,6 +419,23 @@ std::optional<crl::time> LastUserInputTime() {
return std::nullopt;
}
void FallbackFontConfigCheckBegin() {
if (!CheckFontConfigCrash()) {
return;
}
auto file = QFile(FallbackFontConfigCheckPath());
if (file.open(QIODevice::WriteOnly)) {
file.write("1", 1);
}
}
void FallbackFontConfigCheckEnd() {
if (!CheckFontConfigCrash()) {
return;
}
QFile(FallbackFontConfigCheckPath()).remove();
}
} // namespace Platform
namespace {
@ -521,7 +552,10 @@ namespace Platform {
void start() {
LOG(("Launcher filename: %1").arg(GetLauncherFilename()));
#ifdef TDESKTOP_USE_FONTCONFIG_FALLBACK
FallbackFontConfig();
#endif // TDESKTOP_USE_FONTCONFIG_FALLBACK
qputenv("PULSE_PROP_application.name", AppName.utf8());
qputenv("PULSE_PROP_application.icon_name", GetIconName().toLatin1());
@ -529,9 +563,9 @@ void start() {
#ifdef TDESKTOP_FORCE_GTK_FILE_DIALOG
LOG(("Checking for XDG Desktop Portal..."));
// this can give us a chance to use a proper file dialog for current session
if(IsXDGDesktopPortalPresent()) {
if (IsXDGDesktopPortalPresent()) {
LOG(("XDG Desktop Portal is present!"));
if(UseXDGDesktopPortal()) {
if (UseXDGDesktopPortal()) {
LOG(("Usage of XDG Desktop Portal is enabled."));
qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal");
} else {

View File

@ -40,6 +40,9 @@ QString GetIconName();
inline void IgnoreApplicationActivationRightNow() {
}
void FallbackFontConfigCheckBegin();
void FallbackFontConfigCheckEnd();
} // namespace Platform
inline void psCheckLocalSocket(const QString &serverName) {

View File

@ -22,6 +22,12 @@ QString SingleInstanceLocalServerName(const QString &hash);
void RemoveQuarantine(const QString &path);
inline void FallbackFontConfigCheckBegin() {
}
inline void FallbackFontConfigCheckEnd() {
}
namespace ThirdParty {
inline void start() {

View File

@ -26,6 +26,12 @@ QString SingleInstanceLocalServerName(const QString &hash);
inline void IgnoreApplicationActivationRightNow() {
}
inline void FallbackFontConfigCheckBegin() {
}
inline void FallbackFontConfigCheckEnd() {
}
namespace ThirdParty {
void start();

@ -1 +1 @@
Subproject commit 23009b62add39f22cca27438a17f83762d8c2f94
Subproject commit 246aa24530ccc5a5ab06053109a030ceccdb9139