Use KSandbox to check flatpak/snap environment
This commit is contained in:
		
							parent
							
								
									89879e355d
								
							
						
					
					
						commit
						5132fd5010
					
				
					 5 changed files with 16 additions and 31 deletions
				
			
		|  | @ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| 
 | 
 | ||||||
| #include <QtCore/QJsonDocument> | #include <QtCore/QJsonDocument> | ||||||
| #include <QtCore/QJsonObject> | #include <QtCore/QJsonObject> | ||||||
|  | #include <KSandbox> | ||||||
| 
 | 
 | ||||||
| extern "C" { | extern "C" { | ||||||
| #include <openssl/rsa.h> | #include <openssl/rsa.h> | ||||||
|  | @ -1634,16 +1635,14 @@ void UpdateApplication() { | ||||||
| 			return "https://www.microsoft.com/en-us/store/p/telegram-desktop/9nztwsqntd0s"; | 			return "https://www.microsoft.com/en-us/store/p/telegram-desktop/9nztwsqntd0s"; | ||||||
| #elif defined OS_MAC_STORE // OS_WIN_STORE
 | #elif defined OS_MAC_STORE // OS_WIN_STORE
 | ||||||
| 			return "https://itunes.apple.com/ae/app/telegram-desktop/id946399090"; | 			return "https://itunes.apple.com/ae/app/telegram-desktop/id946399090"; | ||||||
| #elif defined Q_OS_UNIX && !defined Q_OS_MAC // OS_WIN_STORE || OS_MAC_STORE
 | #else // OS_WIN_STORE || OS_MAC_STORE
 | ||||||
| 			if (Platform::InFlatpak()) { | 			if (KSandbox::isFlatpak()) { | ||||||
| 				return "https://flathub.org/apps/details/org.telegram.desktop"; | 				return "https://flathub.org/apps/details/org.telegram.desktop"; | ||||||
| 			} else if (Platform::InSnap()) { | 			} else if (KSandbox::isSnap()) { | ||||||
| 				return "https://snapcraft.io/telegram-desktop"; | 				return "https://snapcraft.io/telegram-desktop"; | ||||||
| 			} | 			} | ||||||
| 			return "https://desktop.telegram.org"; | 			return "https://desktop.telegram.org"; | ||||||
| #else // OS_WIN_STORE || OS_MAC_STORE || (defined Q_OS_UNIX && !defined Q_OS_MAC)
 | #endif // OS_WIN_STORE || OS_MAC_STORE
 | ||||||
| 			return "https://desktop.telegram.org"; |  | ||||||
| #endif // OS_WIN_STORE || OS_MAC_STORE || (defined Q_OS_UNIX && !defined Q_OS_MAC)
 |  | ||||||
| 		}(); | 		}(); | ||||||
| 		UrlClickHandler::Open(url); | 		UrlClickHandler::Open(url); | ||||||
| 	} else { | 	} else { | ||||||
|  |  | ||||||
|  | @ -15,13 +15,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "mtproto/mtproto_response.h" | #include "mtproto/mtproto_response.h" | ||||||
| #include "mtproto/mtproto_dc_options.h" | #include "mtproto/mtproto_dc_options.h" | ||||||
| #include "mtproto/connection_abstract.h" | #include "mtproto/connection_abstract.h" | ||||||
| #include "platform/platform_specific.h" |  | ||||||
| #include "base/random.h" | #include "base/random.h" | ||||||
| #include "base/qthelp_url.h" | #include "base/qthelp_url.h" | ||||||
| #include "base/openssl_help.h" | #include "base/openssl_help.h" | ||||||
| #include "base/unixtime.h" | #include "base/unixtime.h" | ||||||
| #include "base/platform/base_platform_info.h" | #include "base/platform/base_platform_info.h" | ||||||
| 
 | 
 | ||||||
|  | #include <KSandbox> | ||||||
| #include <zlib.h> | #include <zlib.h> | ||||||
| 
 | 
 | ||||||
| namespace MTP { | namespace MTP { | ||||||
|  | @ -86,15 +86,13 @@ using namespace details; | ||||||
| 		return u" Mac App Store"_q; | 		return u" Mac App Store"_q; | ||||||
| #elif defined OS_WIN_STORE // OS_MAC_STORE
 | #elif defined OS_WIN_STORE // OS_MAC_STORE
 | ||||||
| 		return u" Microsoft Store"_q; | 		return u" Microsoft Store"_q; | ||||||
| #elif defined Q_OS_UNIX && !defined Q_OS_MAC // OS_MAC_STORE || OS_WIN_STORE
 | #else // OS_MAC_STORE || OS_WIN_STORE
 | ||||||
| 		return Platform::InFlatpak() | 		return KSandbox::isFlatpak() | ||||||
| 			? u" Flatpak"_q | 			? u" Flatpak"_q | ||||||
| 			: Platform::InSnap() | 			: KSandbox::isSnap() | ||||||
| 			? u" Snap"_q | 			? u" Snap"_q | ||||||
| 			: QString(); | 			: QString(); | ||||||
| #else // OS_MAC_STORE || OS_WIN_STORE || (defined Q_OS_UNIX && !defined Q_OS_MAC)
 | #endif // OS_MAC_STORE || OS_WIN_STORE
 | ||||||
| 		return QString(); |  | ||||||
| #endif // OS_MAC_STORE || OS_WIN_STORE || (defined Q_OS_UNIX && !defined Q_OS_MAC)
 |  | ||||||
| 	})(); | 	})(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include <QtCore/QStandardPaths> | #include <QtCore/QStandardPaths> | ||||||
| #include <QtCore/QProcess> | #include <QtCore/QProcess> | ||||||
| #include <KShell> | #include <KShell> | ||||||
|  | #include <KSandbox> | ||||||
| 
 | 
 | ||||||
| #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION | #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION | ||||||
| #include <glibmm.h> | #include <glibmm.h> | ||||||
|  | @ -264,22 +265,12 @@ void SetApplicationIcon(const QIcon &icon) { | ||||||
| 	QApplication::setWindowIcon(icon); | 	QApplication::setWindowIcon(icon); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool InFlatpak() { |  | ||||||
| 	static const auto Result = QFileInfo::exists(qsl("/.flatpak-info")); |  | ||||||
| 	return Result; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| bool InSnap() { |  | ||||||
| 	static const auto Result = qEnvironmentVariableIsSet("SNAP"); |  | ||||||
| 	return Result; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| QString AppRuntimeDirectory() { | QString AppRuntimeDirectory() { | ||||||
| 	static const auto Result = [&] { | 	static const auto Result = [&] { | ||||||
| 		auto runtimeDir = QStandardPaths::writableLocation( | 		auto runtimeDir = QStandardPaths::writableLocation( | ||||||
| 			QStandardPaths::RuntimeLocation); | 			QStandardPaths::RuntimeLocation); | ||||||
| 
 | 
 | ||||||
| 		if (InFlatpak()) { | 		if (KSandbox::isFlatpak()) { | ||||||
| 			runtimeDir += qsl("/app/") + FlatpakID(); | 			runtimeDir += qsl("/app/") + FlatpakID(); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | @ -311,7 +302,7 @@ QString SingleInstanceLocalServerName(const QString &hash) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| QString GetIconName() { | QString GetIconName() { | ||||||
| 	static const auto Result = InFlatpak() | 	static const auto Result = KSandbox::isFlatpak() | ||||||
| 		? FlatpakID() | 		? FlatpakID() | ||||||
| 		: kIconName.utf16(); | 		: kIconName.utf16(); | ||||||
| 	return Result; | 	return Result; | ||||||
|  | @ -363,7 +354,7 @@ bool AutostartSupported() { | ||||||
| 	// in folders with names started with a dot
 | 	// in folders with names started with a dot
 | ||||||
| 	// and doesn't provide any api to add an app to autostart
 | 	// and doesn't provide any api to add an app to autostart
 | ||||||
| 	// thus, autostart isn't supported in snap
 | 	// thus, autostart isn't supported in snap
 | ||||||
| 	return !InSnap(); | 	return !KSandbox::isSnap(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void AutostartToggle(bool enabled, Fn<void(bool)> done) { | void AutostartToggle(bool enabled, Fn<void(bool)> done) { | ||||||
|  | @ -374,7 +365,7 @@ void AutostartToggle(bool enabled, Fn<void(bool)> done) { | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	const auto silent = !done; | 	const auto silent = !done; | ||||||
| 	if (InFlatpak()) { | 	if (KSandbox::isFlatpak()) { | ||||||
| #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION | #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION | ||||||
| 		PortalAutostart(enabled, silent); | 		PortalAutostart(enabled, silent); | ||||||
| #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
 | #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
 | ||||||
|  |  | ||||||
|  | @ -15,9 +15,6 @@ class LocationPoint; | ||||||
| 
 | 
 | ||||||
| namespace Platform { | namespace Platform { | ||||||
| 
 | 
 | ||||||
| bool InFlatpak(); |  | ||||||
| bool InSnap(); |  | ||||||
| 
 |  | ||||||
| QString AppRuntimeDirectory(); | QString AppRuntimeDirectory(); | ||||||
| QString GetIconName(); | QString GetIconName(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								cmake
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								cmake
									
										
									
									
									
								
							|  | @ -1 +1 @@ | ||||||
| Subproject commit c79563ea343075d97d30fe3a6598775538676515 | Subproject commit 152fc28f343aff610f5f9dbdff243bbdbda85bf0 | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Ilya Fedin
						Ilya Fedin