mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Use GAppInfo instead of xdg-mime
This makes registering custom scheme distribution-compatible
This commit is contained in:
parent
95c0c400c7
commit
f56af090e0
3 changed files with 59 additions and 10 deletions
|
@ -48,6 +48,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#undef signals
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#define signals public
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -69,6 +75,7 @@ constexpr auto kIgnoreGtkIncompatibility = "TDESKTOP_I_KNOW_ABOUT_GTK_INCOMPATIB
|
||||||
|
|
||||||
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
|
constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs;
|
||||||
constexpr auto kIconName = "telegram"_cs;
|
constexpr auto kIconName = "telegram"_cs;
|
||||||
|
constexpr auto kHandlerTypeName = "x-scheme-handler/tg"_cs;
|
||||||
|
|
||||||
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
|
constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs;
|
||||||
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
|
constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs;
|
||||||
|
@ -1265,8 +1272,7 @@ void start() {
|
||||||
void finish() {
|
void finish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterCustomScheme(bool force) {
|
void InstallMainDesktopFile() {
|
||||||
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
|
||||||
const auto home = getHomeDir();
|
const auto home = getHomeDir();
|
||||||
if (home.isEmpty() || cExeName().isEmpty())
|
if (home.isEmpty() || cExeName().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -1275,8 +1281,7 @@ void RegisterCustomScheme(bool force) {
|
||||||
"TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION");
|
"TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION");
|
||||||
|
|
||||||
// don't update desktop file for alpha version or if updater is disabled
|
// don't update desktop file for alpha version or if updater is disabled
|
||||||
if ((cAlphaVersion() || Core::UpdaterDisabled() || DisabledByEnv)
|
if (cAlphaVersion() || Core::UpdaterDisabled() || DisabledByEnv)
|
||||||
&& !force)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto applicationsPath = QStandardPaths::writableLocation(
|
const auto applicationsPath = QStandardPaths::writableLocation(
|
||||||
|
@ -1306,12 +1311,54 @@ void RegisterCustomScheme(bool force) {
|
||||||
RunShellCommand("update-desktop-database", {
|
RunShellCommand("update-desktop-database", {
|
||||||
applicationsPath
|
applicationsPath
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
RunShellCommand("xdg-mime", {
|
void RegisterCustomScheme(bool force) {
|
||||||
"default",
|
#ifndef TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
||||||
GetLauncherFilename(),
|
GError *error = nullptr;
|
||||||
"x-scheme-handler/tg"
|
|
||||||
});
|
const auto actualCommandlineBuilder = qsl("%1 --")
|
||||||
|
.arg((IsStaticBinary() || InAppImage())
|
||||||
|
? cExeDir() + cExeName()
|
||||||
|
: cExeName());
|
||||||
|
|
||||||
|
const auto actualCommandline = qsl("%1 %u")
|
||||||
|
.arg(actualCommandlineBuilder);
|
||||||
|
|
||||||
|
auto currentAppInfo = g_app_info_get_default_for_type(
|
||||||
|
kHandlerTypeName.utf8(),
|
||||||
|
true);
|
||||||
|
|
||||||
|
if (currentAppInfo) {
|
||||||
|
const auto currentCommandline = QString(
|
||||||
|
g_app_info_get_commandline(currentAppInfo));
|
||||||
|
|
||||||
|
g_object_unref(currentAppInfo);
|
||||||
|
|
||||||
|
if (currentCommandline == actualCommandline) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto newAppInfo = g_app_info_create_from_commandline(
|
||||||
|
actualCommandlineBuilder.toUtf8(),
|
||||||
|
AppName.utf8(),
|
||||||
|
G_APP_INFO_CREATE_SUPPORTS_URIS,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (newAppInfo) {
|
||||||
|
g_app_info_set_as_default_for_type(
|
||||||
|
newAppInfo,
|
||||||
|
kHandlerTypeName.utf8(),
|
||||||
|
&error);
|
||||||
|
|
||||||
|
g_object_unref(newAppInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
LOG(("App Error: %1").arg(error->message));
|
||||||
|
g_error_free(error);
|
||||||
|
}
|
||||||
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,6 +1416,7 @@ void finish() {
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
||||||
void psNewVersion() {
|
void psNewVersion() {
|
||||||
|
Platform::InstallMainDesktopFile();
|
||||||
Platform::RegisterCustomScheme();
|
Platform::RegisterCustomScheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ void FallbackFontConfigCheckEnd();
|
||||||
|
|
||||||
bool GtkClipboardSupported();
|
bool GtkClipboardSupported();
|
||||||
void SetTrayIconSupported(bool supported);
|
void SetTrayIconSupported(bool supported);
|
||||||
|
void InstallMainDesktopFile();
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
# https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
# https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
option(TDESKTOP_USE_FONTCONFIG_FALLBACK "Use custom fonts.conf (Linux only)." OFF)
|
option(TDESKTOP_USE_FONTCONFIG_FALLBACK "Use custom fonts.conf (Linux only)." OFF)
|
||||||
option(TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME "Disable automatic 'tg://' URL scheme handler registration." ${DESKTOP_APP_USE_PACKAGED})
|
option(TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME "Disable automatic 'tg://' URL scheme handler registration." OFF)
|
||||||
option(TDESKTOP_DISABLE_NETWORK_PROXY "Disable all code for working through Socks5 or MTProxy." OFF)
|
option(TDESKTOP_DISABLE_NETWORK_PROXY "Disable all code for working through Socks5 or MTProxy." OFF)
|
||||||
option(TDESKTOP_DISABLE_GTK_INTEGRATION "Disable all code for GTK integration (Linux only)." OFF)
|
option(TDESKTOP_DISABLE_GTK_INTEGRATION "Disable all code for GTK integration (Linux only)." OFF)
|
||||||
option(TDESKTOP_USE_PACKAGED_TGVOIP "Find libtgvoip using CMake instead of bundled one." ${DESKTOP_APP_USE_PACKAGED})
|
option(TDESKTOP_USE_PACKAGED_TGVOIP "Find libtgvoip using CMake instead of bundled one." ${DESKTOP_APP_USE_PACKAGED})
|
||||||
|
|
Loading…
Add table
Reference in a new issue