Don't use QDesktopServices::openUrl on snap

This commit is contained in:
Ilya Fedin 2020-04-28 12:26:12 +04:00 committed by John Preston
parent 9828262a03
commit 95b4f56b86
13 changed files with 72 additions and 20 deletions

View file

@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/text/text_utilities.h"
#include "platform/platform_file_utilities.h"
#include "core/file_utilities.h"
#include "base/platform/base_platform_info.h"
#include "core/click_handler_types.h"
#include "core/update_checker.h"
@ -23,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QGuiApplication>
#include <QtGui/QClipboard>
#include <QtGui/QDesktopServices>
namespace {
@ -109,7 +108,7 @@ void AboutBox::showVersionHistory() {
Ui::show(Box<InformBox>("The link to the current private alpha version of Telegram Desktop was copied to the clipboard."));
} else {
QDesktopServices::openUrl(qsl("https://desktop.telegram.org/changelog"));
File::OpenUrl(qsl("https://desktop.telegram.org/changelog"));
}
}

View file

@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "observer_peer.h"
#include "storage/storage_databases.h"
#include "mainwidget.h"
#include "core/file_utilities.h"
#include "main/main_account.h"
#include "media/view/media_view_overlay_widget.h"
#include "mtproto/dc_options.h"
@ -300,7 +301,7 @@ void Application::showDocument(not_null<DocumentData*> document, HistoryItem *it
if (cUseExternalVideoPlayer()
&& document->isVideoFile()
&& document->loaded()) {
QDesktopServices::openUrl(QUrl("file:///" + document->location(false).fname));
File::Launch(document->location(false).fname);
} else {
_mediaView->showDocument(document, item);
_mediaView->activateWindow();

View file

@ -22,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "facades.h"
#include "app.h"
#include <QtGui/QDesktopServices>
#include <QtGui/QGuiApplication>
namespace {

View file

@ -118,6 +118,13 @@ QString filedialogNextFilename(
namespace File {
void OpenUrl(const QString &url) {
crl::on_main([=] {
Ui::PreventDelayedActivation();
Platform::File::UnsafeOpenUrl(url);
});
}
void OpenEmailLink(const QString &email) {
crl::on_main([=] {
Ui::PreventDelayedActivation();
@ -162,6 +169,10 @@ QString DefaultDownloadPath() {
namespace internal {
void UnsafeOpenUrlDefault(const QString &url) {
QDesktopServices::openUrl(url);
}
void UnsafeOpenEmailLinkDefault(const QString &email) {
auto url = QUrl(qstr("mailto:") + email);
QDesktopServices::openUrl(url);

View file

@ -30,6 +30,7 @@ QString filedialogNextFilename(
namespace File {
// Those functions are async wrappers to Platform::File::Unsafe* calls.
void OpenUrl(const QString &url);
void OpenEmailLink(const QString &email);
void OpenWith(const QString &filepath, QPoint menuPosition);
void Launch(const QString &filepath);
@ -43,6 +44,7 @@ inline QString UrlToLocalDefault(const QUrl &url) {
return url.toLocalFile();
}
void UnsafeOpenUrlDefault(const QString &url);
void UnsafeOpenEmailLinkDefault(const QString &email);
void UnsafeLaunchDefault(const QString &filepath);

View file

@ -143,7 +143,9 @@ bool UiIntegration::handleUrlClick(
Core::App().openInternalUrl(local, context);
return true;
}
return false;
File::OpenUrl(url);
return true;
}

View file

@ -8,13 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_location_manager.h"
#include "mainwidget.h"
#include "core/file_utilities.h"
#include "lang/lang_keys.h"
#include "ui/image/image.h"
#include "data/data_file_origin.h"
#include "platform/platform_specific.h"
#include <QtGui/QDesktopServices>
namespace {
constexpr auto kCoordPrecision = 8;
@ -32,7 +31,7 @@ QString LocationClickHandler::copyToClipboardContextItemText() const {
void LocationClickHandler::onClick(ClickContext context) const {
if (!psLaunchMaps(_point)) {
QDesktopServices::openUrl(_text);
File::OpenUrl(_text);
}
}

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/linux/linux_libs.h"
#include "platform/linux/linux_gdk_helper.h"
#include "platform/linux/specific_linux.h"
#include "core/application.h"
#include "mainwindow.h"
#include "boxes/abstract_box.h"
@ -18,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "facades.h"
#include <QtCore/QProcess>
#include <QtGui/QDesktopServices>
#ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
#include <private/qguiapplication_p.h>
@ -57,6 +59,44 @@ QByteArray EscapeShell(const QByteArray &content) {
} // namespace internal
void UnsafeOpenUrl(const QString &url) {
if (InSnap()) {
const QStringList arguments{
url
};
QProcess process;
process.startDetached(qsl("xdg-open"), arguments);
} else {
QDesktopServices::openUrl(url);
}
}
void UnsafeOpenEmailLink(const QString &email) {
const auto url = qstr("mailto:") + email;
if (InSnap()) {
const QStringList arguments{
url
};
QProcess process;
process.startDetached(qsl("xdg-open"), arguments);
} else {
QDesktopServices::openUrl(QUrl(url));
}
}
void UnsafeLaunch(const QString &filepath) {
if (InSnap()) {
const QStringList arguments{
QFileInfo(filepath).absoluteFilePath()
};
QProcess process;
process.startDetached(qsl("xdg-open"), arguments);
} else {
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
}
}
void UnsafeShowInFolder(const QString &filepath) {
// Hide mediaview to make other apps visible.
Ui::hideLayer(anim::type::instant);

View file

@ -33,10 +33,6 @@ inline QString UrlToLocal(const QUrl &url) {
return ::File::internal::UrlToLocalDefault(url);
}
inline void UnsafeOpenEmailLink(const QString &email) {
return ::File::internal::UnsafeOpenEmailLinkDefault(email);
}
inline bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition) {
return false;
}
@ -45,10 +41,6 @@ inline bool UnsafeShowOpenWith(const QString &filepath) {
return false;
}
inline void UnsafeLaunch(const QString &filepath) {
return ::File::internal::UnsafeLaunchDefault(filepath);
}
inline void PostprocessDownloaded(const QString &filepath) {
}

View file

@ -12,6 +12,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Platform {
namespace File {
inline void UnsafeOpenUrl(const QString &url) {
return ::File::internal::UnsafeOpenUrlDefault(url);
}
inline void UnsafeOpenEmailLink(const QString &email) {
return ::File::internal::UnsafeOpenEmailLinkDefault(email);
}

View file

@ -15,6 +15,7 @@ namespace File {
QString UrlToLocal(const QUrl &url);
// All these functions may enter a nested event loop. Use with caution.
void UnsafeOpenUrl(const QString &url);
void UnsafeOpenEmailLink(const QString &email);
bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition);
bool UnsafeShowOpenWith(const QString &filepath);

View file

@ -16,5 +16,9 @@ inline QString UrlToLocal(const QUrl &url) {
return url.toLocalFile();
}
inline void UnsafeOpenUrl(const QString &url) {
return ::File::internal::UnsafeOpenUrlDefault(url);
}
} // namespace File
} // namespace Platform

View file

@ -36,8 +36,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "app.h"
#include "styles/style_settings.h"
#include <QtGui/QDesktopServices>
namespace Settings {
void SetupLanguageButton(
@ -271,7 +269,7 @@ void SetupInterfaceScale(
}
void OpenFaq() {
QDesktopServices::openUrl(telegramFaqLink());
File::OpenUrl(telegramFaqLink());
}
void SetupFaq(not_null<Ui::VerticalLayout*> container, bool icon) {