2014-07-08 10:24:21 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-01-10 06:05:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-07-08 10:24:21 +00:00
|
|
|
*/
|
2017-03-05 22:43:35 +00:00
|
|
|
#include "platform/linux/specific_linux.h"
|
2014-07-08 10:24:21 +00:00
|
|
|
|
2021-09-15 10:21:45 +00:00
|
|
|
#include "base/random.h"
|
2022-11-11 11:49:50 +00:00
|
|
|
#include "base/options.h"
|
2020-07-10 12:51:30 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
#include "platform/linux/linux_desktop_environment.h"
|
2020-11-11 23:18:18 +00:00
|
|
|
#include "platform/linux/linux_wayland_integration.h"
|
2022-11-21 04:38:14 +00:00
|
|
|
#include "platform/platform_launcher.h"
|
2021-01-10 04:53:11 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "mainwindow.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2021-02-22 02:41:26 +00:00
|
|
|
#include "core/sandbox.h"
|
|
|
|
#include "core/application.h"
|
2022-11-11 11:49:50 +00:00
|
|
|
#include "core/local_url_handlers.h"
|
2021-02-22 02:41:26 +00:00
|
|
|
#include "core/core_settings.h"
|
2018-08-30 07:14:36 +00:00
|
|
|
#include "core/update_checker.h"
|
2020-11-08 06:47:51 +00:00
|
|
|
#include "window/window_controller.h"
|
2021-11-06 12:23:46 +00:00
|
|
|
#include "webview/platform/linux/webview_linux_webkit2gtk.h"
|
2015-03-02 12:34:16 +00:00
|
|
|
|
2021-02-28 02:34:41 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-09-10 21:55:28 +00:00
|
|
|
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
2021-02-28 02:34:41 +00:00
|
|
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
2021-03-24 04:59:04 +00:00
|
|
|
#include "base/platform/linux/base_linux_xdp_utilities.h"
|
2021-02-28 02:34:41 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
|
2019-09-08 20:15:42 +00:00
|
|
|
#include <QtWidgets/QApplication>
|
2022-04-21 19:33:27 +00:00
|
|
|
#include <QtWidgets/QSystemTrayIcon>
|
2019-09-08 20:15:42 +00:00
|
|
|
#include <QtCore/QStandardPaths>
|
|
|
|
#include <QtCore/QProcess>
|
2022-09-28 16:01:59 +00:00
|
|
|
|
|
|
|
#include <kshell.h>
|
|
|
|
#include <ksandbox.h>
|
2021-09-14 16:43:00 +00:00
|
|
|
|
2021-09-10 21:55:28 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-02-28 02:34:41 +00:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <giomm.h>
|
2021-09-10 21:55:28 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-08-06 11:47:50 +00:00
|
|
|
|
2014-07-14 05:16:21 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2022-03-08 08:23:59 +00:00
|
|
|
#include <sys/un.h>
|
2014-07-14 05:16:21 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
2014-07-24 16:00:35 +00:00
|
|
|
#include <pwd.h>
|
2014-07-14 05:16:21 +00:00
|
|
|
|
2015-01-15 14:22:15 +00:00
|
|
|
#include <iostream>
|
2016-11-11 07:51:53 +00:00
|
|
|
|
2016-06-16 17:20:58 +00:00
|
|
|
using namespace Platform;
|
2020-11-11 23:18:18 +00:00
|
|
|
using Platform::internal::WaylandIntegration;
|
2015-01-15 14:22:15 +00:00
|
|
|
|
2022-11-11 11:49:50 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
typedef GApplication TDesktopApplication;
|
|
|
|
typedef GApplicationClass TDesktopApplicationClass;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(
|
|
|
|
TDesktopApplication,
|
|
|
|
t_desktop_application,
|
|
|
|
G_TYPE_APPLICATION)
|
|
|
|
|
|
|
|
static void t_desktop_application_class_init(
|
|
|
|
TDesktopApplicationClass *klass) {
|
|
|
|
const auto application_class = G_APPLICATION_CLASS(klass);
|
|
|
|
|
|
|
|
application_class->before_emit = [](
|
|
|
|
GApplication *application,
|
|
|
|
GVariant *platformData) {
|
|
|
|
if (Platform::IsWayland()) {
|
|
|
|
static const auto keys = {
|
|
|
|
"activation-token",
|
|
|
|
"desktop-startup-id",
|
|
|
|
};
|
2022-11-21 04:39:14 +00:00
|
|
|
for (const auto &key : keys) {
|
2022-11-11 11:49:50 +00:00
|
|
|
const char *token = nullptr;
|
|
|
|
g_variant_lookup(platformData, key, "&s", &token);
|
|
|
|
if (token) {
|
|
|
|
qputenv("XDG_ACTIVATION_TOKEN", token);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
application_class->add_platform_data = [](
|
|
|
|
GApplication *application,
|
|
|
|
GVariantBuilder *builder) {
|
|
|
|
if (Platform::IsWayland()) {
|
|
|
|
const auto token = qgetenv("XDG_ACTIVATION_TOKEN");
|
|
|
|
if (!token.isEmpty()) {
|
|
|
|
g_variant_builder_add(
|
|
|
|
builder,
|
|
|
|
"{sv}",
|
|
|
|
"activation-token",
|
|
|
|
g_variant_new_string(token.constData()));
|
2022-11-25 12:53:14 +00:00
|
|
|
qunsetenv("XDG_ACTIVATION_TOKEN");
|
2022-11-11 11:49:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static void t_desktop_application_init(TDesktopApplication *application) {
|
|
|
|
}
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
2020-03-30 08:18:50 +00:00
|
|
|
namespace Platform {
|
2018-03-18 08:51:14 +00:00
|
|
|
namespace {
|
|
|
|
|
2022-11-11 13:37:42 +00:00
|
|
|
constexpr auto kDesktopFile = ":/misc/org.telegram.desktop.desktop"_cs;
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2020-08-08 12:07:13 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-06-26 21:51:32 +00:00
|
|
|
void PortalAutostart(bool start, bool silent) {
|
2020-08-07 06:34:06 +00:00
|
|
|
if (cExeName().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-01 20:27:02 +00:00
|
|
|
try {
|
|
|
|
const auto connection = Gio::DBus::Connection::get_sync(
|
2022-11-03 09:41:18 +00:00
|
|
|
Gio::DBus::BusType::SESSION);
|
2021-03-01 20:27:02 +00:00
|
|
|
|
|
|
|
const auto parentWindowId = [&]() -> Glib::ustring {
|
2021-05-10 08:53:34 +00:00
|
|
|
const auto activeWindow = Core::App().activeWindow();
|
|
|
|
if (!activeWindow) {
|
2022-04-14 00:24:48 +00:00
|
|
|
return {};
|
2020-11-08 06:47:51 +00:00
|
|
|
}
|
2021-05-10 08:53:34 +00:00
|
|
|
|
2022-04-14 00:24:48 +00:00
|
|
|
return base::Platform::XDP::ParentWindowID(
|
|
|
|
activeWindow->widget()->windowHandle());
|
2021-03-01 20:27:02 +00:00
|
|
|
}();
|
|
|
|
|
|
|
|
const auto handleToken = Glib::ustring("tdesktop")
|
2021-09-15 10:21:45 +00:00
|
|
|
+ std::to_string(base::RandomValue<uint>());
|
2021-03-01 20:27:02 +00:00
|
|
|
|
2022-11-21 04:38:14 +00:00
|
|
|
std::vector<Glib::ustring> commandline;
|
|
|
|
commandline.push_back(cExeName().toStdString());
|
|
|
|
if (Core::Sandbox::Instance().customWorkingDir()) {
|
|
|
|
commandline.push_back("-workdir");
|
|
|
|
commandline.push_back(cWorkingDir().toStdString());
|
|
|
|
}
|
|
|
|
commandline.push_back("-autostart");
|
|
|
|
|
2021-03-01 20:27:02 +00:00
|
|
|
std::map<Glib::ustring, Glib::VariantBase> options;
|
|
|
|
options["handle_token"] = Glib::Variant<Glib::ustring>::create(
|
|
|
|
handleToken);
|
|
|
|
options["reason"] = Glib::Variant<Glib::ustring>::create(
|
|
|
|
tr::lng_settings_auto_start(tr::now).toStdString());
|
|
|
|
options["autostart"] = Glib::Variant<bool>::create(start);
|
2022-11-21 04:38:14 +00:00
|
|
|
options["commandline"] = base::Platform::MakeGlibVariant(commandline);
|
2021-03-01 20:27:02 +00:00
|
|
|
options["dbus-activatable"] = Glib::Variant<bool>::create(false);
|
|
|
|
|
|
|
|
auto uniqueName = connection->get_unique_name();
|
|
|
|
uniqueName.erase(0, 1);
|
|
|
|
uniqueName.replace(uniqueName.find('.'), 1, 1, '_');
|
|
|
|
|
|
|
|
const auto requestPath = Glib::ustring(
|
|
|
|
"/org/freedesktop/portal/desktop/request/")
|
|
|
|
+ uniqueName
|
|
|
|
+ '/'
|
|
|
|
+ handleToken;
|
2021-03-04 15:29:01 +00:00
|
|
|
|
2022-05-19 07:36:13 +00:00
|
|
|
const auto loop = Glib::MainLoop::create();
|
2021-03-01 20:27:02 +00:00
|
|
|
|
|
|
|
const auto signalId = connection->signal_subscribe(
|
|
|
|
[&](
|
|
|
|
const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
|
|
|
const Glib::ustring &sender_name,
|
|
|
|
const Glib::ustring &object_path,
|
|
|
|
const Glib::ustring &interface_name,
|
|
|
|
const Glib::ustring &signal_name,
|
2022-07-26 00:42:22 +00:00
|
|
|
Glib::VariantContainerBase parameters) {
|
2021-03-01 20:27:02 +00:00
|
|
|
try {
|
|
|
|
const auto response = base::Platform::GlibVariantCast<
|
2022-07-26 00:42:22 +00:00
|
|
|
uint>(parameters.get_child(0));
|
2021-03-04 15:29:01 +00:00
|
|
|
|
2021-03-01 20:27:02 +00:00
|
|
|
if (response && !silent) {
|
|
|
|
LOG(("Portal Autostart Error: Request denied"));
|
|
|
|
}
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
if (!silent) {
|
|
|
|
LOG(("Portal Autostart Error: %1").arg(
|
|
|
|
QString::fromStdString(e.what())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-26 21:51:32 +00:00
|
|
|
loop->quit();
|
2021-03-01 20:27:02 +00:00
|
|
|
},
|
2022-04-14 00:24:48 +00:00
|
|
|
std::string(base::Platform::XDP::kService),
|
2021-03-01 20:27:02 +00:00
|
|
|
"org.freedesktop.portal.Request",
|
|
|
|
"Response",
|
|
|
|
requestPath);
|
|
|
|
|
2021-03-06 22:29:38 +00:00
|
|
|
const auto signalGuard = gsl::finally([&] {
|
|
|
|
if (signalId != 0) {
|
|
|
|
connection->signal_unsubscribe(signalId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-01 20:27:02 +00:00
|
|
|
connection->call_sync(
|
2022-04-14 00:24:48 +00:00
|
|
|
std::string(base::Platform::XDP::kObjectPath),
|
2021-03-01 20:27:02 +00:00
|
|
|
"org.freedesktop.portal.Background",
|
|
|
|
"RequestBackground",
|
|
|
|
base::Platform::MakeGlibVariant(std::tuple{
|
|
|
|
parentWindowId,
|
|
|
|
options,
|
|
|
|
}),
|
2022-04-14 00:24:48 +00:00
|
|
|
std::string(base::Platform::XDP::kService));
|
2021-03-01 20:27:02 +00:00
|
|
|
|
|
|
|
if (signalId != 0) {
|
2022-05-19 07:36:13 +00:00
|
|
|
QWidget window;
|
|
|
|
window.setAttribute(Qt::WA_DontShowOnScreen);
|
|
|
|
window.setWindowModality(Qt::ApplicationModal);
|
|
|
|
window.show();
|
2021-06-26 21:51:32 +00:00
|
|
|
loop->run();
|
2021-03-01 20:27:02 +00:00
|
|
|
}
|
2022-11-03 09:41:18 +00:00
|
|
|
} catch (const std::exception &e) {
|
2021-03-01 20:27:02 +00:00
|
|
|
if (!silent) {
|
|
|
|
LOG(("Portal Autostart Error: %1").arg(
|
|
|
|
QString::fromStdString(e.what())));
|
2020-11-08 06:47:51 +00:00
|
|
|
}
|
2020-01-30 17:03:20 +00:00
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
}
|
2022-11-11 11:49:50 +00:00
|
|
|
|
|
|
|
void LaunchGApplication() {
|
|
|
|
const auto connection = [] {
|
|
|
|
try {
|
|
|
|
return Gio::DBus::Connection::get_sync(
|
|
|
|
Gio::DBus::BusType::SESSION);
|
|
|
|
} catch (...) {
|
|
|
|
return Glib::RefPtr<Gio::DBus::Connection>();
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
using namespace base::Platform::DBus;
|
|
|
|
const auto activatableNames = [&] {
|
|
|
|
try {
|
|
|
|
if (connection) {
|
|
|
|
return ListActivatableNames(connection);
|
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::vector<Glib::ustring>();
|
|
|
|
}();
|
|
|
|
|
|
|
|
const auto freedesktopNotifications = [&] {
|
|
|
|
try {
|
|
|
|
if (connection && NameHasOwner(
|
|
|
|
connection,
|
|
|
|
"org.freedesktop.Notifications")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ranges::contains(
|
|
|
|
activatableNames,
|
|
|
|
"org.freedesktop.Notifications")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (OptionGApplication.value()
|
|
|
|
|| (KSandbox::isFlatpak() && !freedesktopNotifications())) {
|
|
|
|
Glib::signal_idle().connect_once([] {
|
|
|
|
const auto appId = QGuiApplication::desktopFileName()
|
|
|
|
.chopped(8)
|
|
|
|
.toStdString();
|
|
|
|
|
|
|
|
const auto app = Glib::wrap(
|
|
|
|
G_APPLICATION(
|
|
|
|
g_object_new(
|
|
|
|
t_desktop_application_get_type(),
|
|
|
|
"application-id",
|
|
|
|
Gio::Application::id_is_valid(appId)
|
|
|
|
? appId.c_str()
|
|
|
|
: nullptr,
|
|
|
|
"flags",
|
|
|
|
G_APPLICATION_HANDLES_OPEN,
|
|
|
|
nullptr)));
|
|
|
|
|
|
|
|
app->signal_startup().connect([=] {
|
2022-11-25 22:36:28 +00:00
|
|
|
// GNotification
|
|
|
|
InvokeQueued(qApp, [] {
|
|
|
|
Core::App().notifications().createManager();
|
|
|
|
});
|
|
|
|
|
2022-12-07 06:53:51 +00:00
|
|
|
QEventLoop().exec();
|
2022-11-11 11:49:50 +00:00
|
|
|
app->quit();
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
app->signal_activate().connect([] {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([] {
|
2022-11-30 13:28:09 +00:00
|
|
|
const auto window = Core::IsAppLaunched()
|
|
|
|
? Core::App().primaryWindow()
|
|
|
|
: nullptr;
|
|
|
|
if (window) {
|
|
|
|
window->activate();
|
2022-11-11 11:49:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
app->signal_open().connect([](
|
|
|
|
const Gio::Application::type_vec_files &files,
|
|
|
|
const Glib::ustring &hint) {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
2022-11-21 04:39:14 +00:00
|
|
|
for (const auto &file : files) {
|
2022-11-11 11:49:50 +00:00
|
|
|
if (file->get_uri_scheme() == "file") {
|
|
|
|
gSendPaths.append(
|
|
|
|
QString::fromStdString(file->get_path()));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto url = QString::fromStdString(
|
|
|
|
file->get_uri());
|
|
|
|
if (url.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (url.startsWith(qstr("interpret://"))) {
|
|
|
|
gSendPaths.append(url);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Core::StartUrlRequiresActivate(url)) {
|
2022-11-30 13:28:09 +00:00
|
|
|
const auto window = Core::IsAppLaunched()
|
|
|
|
? Core::App().primaryWindow()
|
|
|
|
: nullptr;
|
|
|
|
if (window) {
|
|
|
|
window->activate();
|
2022-11-11 11:49:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cSetStartUrl(url);
|
|
|
|
Core::App().checkStartUrl();
|
|
|
|
}
|
2022-11-30 13:28:09 +00:00
|
|
|
|
2022-11-11 11:49:50 +00:00
|
|
|
if (!cSendPaths().isEmpty()) {
|
2022-11-30 13:28:09 +00:00
|
|
|
Core::App().checkSendPaths();
|
2022-11-11 11:49:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
app->add_action("Quit", [] {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([] {
|
|
|
|
Core::Quit();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
using Window::Notifications::Manager;
|
|
|
|
using NotificationId = Manager::NotificationId;
|
2022-12-08 03:13:07 +00:00
|
|
|
using NotificationIdTuple = std::invoke_result_t<
|
|
|
|
decltype(&NotificationId::toTuple),
|
|
|
|
NotificationId*
|
|
|
|
>;
|
2022-11-11 11:49:50 +00:00
|
|
|
|
|
|
|
const auto notificationIdVariantType = [] {
|
|
|
|
try {
|
|
|
|
return base::Platform::MakeGlibVariant(
|
|
|
|
NotificationId().toTuple()).get_type();
|
|
|
|
} catch (...) {
|
|
|
|
return Glib::VariantType();
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
|
|
|
app->add_action_with_parameter(
|
|
|
|
"notification-reply",
|
|
|
|
notificationIdVariantType,
|
|
|
|
[](const Glib::VariantBase ¶meter) {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
try {
|
|
|
|
const auto &app = Core::App();
|
|
|
|
const auto ¬ifications = app.notifications();
|
|
|
|
notifications.manager().notificationActivated(
|
|
|
|
NotificationId::FromTuple(
|
|
|
|
base::Platform::GlibVariantCast<
|
|
|
|
NotificationIdTuple
|
|
|
|
>(parameter)));
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app->add_action_with_parameter(
|
|
|
|
"notification-mark-as-read",
|
|
|
|
notificationIdVariantType,
|
|
|
|
[](const Glib::VariantBase ¶meter) {
|
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
try {
|
|
|
|
const auto &app = Core::App();
|
|
|
|
const auto ¬ifications = app.notifications();
|
|
|
|
notifications.manager().notificationReplied(
|
|
|
|
NotificationId::FromTuple(
|
|
|
|
base::Platform::GlibVariantCast<
|
|
|
|
NotificationIdTuple
|
|
|
|
>(parameter)),
|
|
|
|
{});
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app->hold();
|
|
|
|
app->run(0, nullptr);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2020-02-25 02:39:14 +00:00
|
|
|
bool GenerateDesktopFile(
|
|
|
|
const QString &targetPath,
|
2022-11-21 06:57:24 +00:00
|
|
|
const QStringList &args = {},
|
2020-02-25 02:39:14 +00:00
|
|
|
bool silent = false) {
|
2020-08-07 06:34:06 +00:00
|
|
|
if (targetPath.isEmpty() || cExeName().isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-21 00:10:10 +00:00
|
|
|
DEBUG_LOG(("App Info: placing .desktop file to %1").arg(targetPath));
|
|
|
|
if (!QDir(targetPath).exists()) QDir().mkpath(targetPath);
|
|
|
|
|
2020-08-06 02:36:03 +00:00
|
|
|
const auto sourceFile = kDesktopFile.utf16();
|
2021-03-12 04:55:31 +00:00
|
|
|
const auto targetFile = targetPath + QGuiApplication::desktopFileName();
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2022-11-26 01:59:35 +00:00
|
|
|
const auto sourceText = [&] {
|
|
|
|
QFile source(sourceFile);
|
|
|
|
if (source.open(QIODevice::ReadOnly)) {
|
|
|
|
return source.readAll().toStdString();
|
|
|
|
}
|
|
|
|
return std::string();
|
|
|
|
}();
|
2022-11-30 13:28:09 +00:00
|
|
|
|
2022-11-26 01:59:35 +00:00
|
|
|
if (sourceText.empty()) {
|
2020-02-25 02:39:14 +00:00
|
|
|
if (!silent) {
|
|
|
|
LOG(("App Error: Could not open '%1' for read").arg(sourceFile));
|
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-21 06:57:24 +00:00
|
|
|
try {
|
|
|
|
const auto target = Glib::KeyFile::create();
|
|
|
|
target->load_from_data(
|
2022-11-26 01:59:35 +00:00
|
|
|
sourceText,
|
2022-11-21 06:57:24 +00:00
|
|
|
Glib::KeyFile::Flags::KEEP_COMMENTS
|
|
|
|
| Glib::KeyFile::Flags::KEEP_TRANSLATIONS);
|
|
|
|
|
|
|
|
for (const auto &group : target->get_groups()) {
|
|
|
|
if (target->has_key(group, "TryExec")) {
|
|
|
|
target->set_string(
|
|
|
|
group,
|
|
|
|
"TryExec",
|
|
|
|
KShell::joinArgs({ cExeDir() + cExeName() }).replace(
|
|
|
|
'\\',
|
|
|
|
qstr("\\\\")).toStdString());
|
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2022-11-21 06:57:24 +00:00
|
|
|
if (target->has_key(group, "Exec")) {
|
|
|
|
if (group == "Desktop Entry" && !args.isEmpty()) {
|
|
|
|
QStringList exec;
|
|
|
|
exec.append(cExeDir() + cExeName());
|
|
|
|
if (Core::Sandbox::Instance().customWorkingDir()) {
|
2022-11-29 21:46:36 +00:00
|
|
|
exec.append(u"-workdir"_q);
|
2022-11-21 06:57:24 +00:00
|
|
|
exec.append(cWorkingDir());
|
|
|
|
}
|
|
|
|
exec.append(args);
|
|
|
|
target->set_string(
|
|
|
|
group,
|
|
|
|
"Exec",
|
|
|
|
KShell::joinArgs(exec).replace(
|
|
|
|
'\\',
|
|
|
|
qstr("\\\\")).toStdString());
|
|
|
|
} else {
|
|
|
|
auto exec = KShell::splitArgs(
|
|
|
|
QString::fromStdString(
|
|
|
|
target->get_string(group, "Exec")
|
|
|
|
).replace(
|
|
|
|
qstr("\\\\"),
|
|
|
|
qstr("\\")));
|
|
|
|
|
|
|
|
if (!exec.isEmpty()) {
|
|
|
|
exec[0] = cExeDir() + cExeName();
|
|
|
|
if (Core::Sandbox::Instance().customWorkingDir()) {
|
2022-11-29 21:46:36 +00:00
|
|
|
exec.insert(1, u"-workdir"_q);
|
2022-11-21 06:57:24 +00:00
|
|
|
exec.insert(2, cWorkingDir());
|
|
|
|
}
|
|
|
|
target->set_string(
|
|
|
|
group,
|
|
|
|
"Exec",
|
|
|
|
KShell::joinArgs(exec).replace(
|
|
|
|
'\\',
|
|
|
|
qstr("\\\\")).toStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2022-11-21 06:57:24 +00:00
|
|
|
target->save_to_file(targetFile.toStdString());
|
|
|
|
}
|
|
|
|
} catch (const std::exception &e) {
|
2020-02-25 02:39:14 +00:00
|
|
|
if (!silent) {
|
2022-11-21 06:57:24 +00:00
|
|
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
2020-02-25 02:39:14 +00:00
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-11-21 06:57:24 +00:00
|
|
|
|
|
|
|
if (!Core::UpdaterDisabled()) {
|
|
|
|
DEBUG_LOG(("App Info: removing old .desktop files"));
|
2022-11-29 21:46:36 +00:00
|
|
|
QFile::remove(u"%1telegram.desktop"_q.arg(targetPath));
|
|
|
|
QFile::remove(u"%1telegramdesktop.desktop"_q.arg(targetPath));
|
2022-11-21 06:57:24 +00:00
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
const auto appimagePath = u"file://%1%2"_q.arg(
|
2022-11-21 06:57:24 +00:00
|
|
|
cExeDir(),
|
|
|
|
cExeName()).toUtf8();
|
|
|
|
|
|
|
|
char md5Hash[33] = { 0 };
|
|
|
|
hashMd5Hex(
|
|
|
|
appimagePath.constData(),
|
|
|
|
appimagePath.size(),
|
|
|
|
md5Hash);
|
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
QFile::remove(u"%1appimagekit_%2-%3.desktop"_q.arg(
|
2022-11-21 06:57:24 +00:00
|
|
|
targetPath,
|
|
|
|
md5Hash,
|
|
|
|
AppName.utf16().replace(' ', '_')));
|
2022-11-25 17:33:29 +00:00
|
|
|
|
|
|
|
const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath());
|
|
|
|
hashMd5Hex(d.constData(), d.size(), md5Hash);
|
|
|
|
|
|
|
|
if (!Core::Sandbox::Instance().customWorkingDir()) {
|
|
|
|
const auto exePath = QFile::encodeName(
|
|
|
|
cExeDir() + cExeName());
|
|
|
|
hashMd5Hex(exePath.constData(), exePath.size(), md5Hash);
|
|
|
|
}
|
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
QFile::remove(u"%1org.telegram.desktop.%2.desktop"_q.arg(
|
2022-11-25 17:33:29 +00:00
|
|
|
targetPath,
|
|
|
|
md5Hash));
|
2022-11-21 06:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-01-21 00:10:10 +00:00
|
|
|
}
|
2022-11-21 06:57:24 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2022-09-19 02:59:20 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void SetApplicationIcon(const QIcon &icon) {
|
|
|
|
QApplication::setWindowIcon(icon);
|
|
|
|
}
|
|
|
|
|
2021-09-03 15:49:48 +00:00
|
|
|
QString SingleInstanceLocalServerName(const QString &hash) {
|
2022-11-07 08:39:07 +00:00
|
|
|
return QDir::tempPath() + '/' + hash + '-' + cGUIDStr();
|
2021-09-03 15:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<bool> IsDarkMode() {
|
2022-03-23 18:58:35 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-07-13 17:51:07 +00:00
|
|
|
[[maybe_unused]] static const auto Inited = [] {
|
2021-05-27 19:54:57 +00:00
|
|
|
using XDPSettingWatcher = base::Platform::XDP::SettingWatcher;
|
2022-03-23 18:58:35 +00:00
|
|
|
static const XDPSettingWatcher Watcher(
|
2021-09-03 15:49:48 +00:00
|
|
|
[=](
|
|
|
|
const Glib::ustring &group,
|
|
|
|
const Glib::ustring &key,
|
|
|
|
const Glib::VariantBase &value) {
|
2022-03-23 18:58:35 +00:00
|
|
|
if (group == "org.freedesktop.appearance"
|
|
|
|
&& key == "color-scheme") {
|
2022-04-19 20:35:23 +00:00
|
|
|
try {
|
|
|
|
const auto ivalue = base::Platform::GlibVariantCast<uint>(value);
|
|
|
|
|
|
|
|
crl::on_main([=] {
|
|
|
|
Core::App().settings().setSystemDarkMode(ivalue == 1);
|
|
|
|
});
|
|
|
|
} catch (...) {
|
|
|
|
}
|
2021-09-03 15:49:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-05-27 19:54:57 +00:00
|
|
|
return true;
|
|
|
|
}();
|
|
|
|
|
2021-09-03 15:49:48 +00:00
|
|
|
try {
|
2022-03-23 18:58:35 +00:00
|
|
|
const auto result = base::Platform::XDP::ReadSetting(
|
|
|
|
"org.freedesktop.appearance",
|
|
|
|
"color-scheme");
|
|
|
|
|
|
|
|
if (result.has_value()) {
|
|
|
|
const auto value = base::Platform::GlibVariantCast<uint>(*result);
|
2022-04-19 20:35:23 +00:00
|
|
|
return value == 1;
|
2021-05-27 19:54:57 +00:00
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
|
2022-03-23 18:58:35 +00:00
|
|
|
return std::nullopt;
|
2020-07-14 16:36:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 17:49:39 +00:00
|
|
|
bool AutostartSupported() {
|
2022-11-25 16:36:11 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-08-04 05:32:04 +00:00
|
|
|
// snap sandbox doesn't allow creating files
|
|
|
|
// in folders with names started with a dot
|
2020-05-29 17:49:39 +00:00
|
|
|
// and doesn't provide any api to add an app to autostart
|
|
|
|
// thus, autostart isn't supported in snap
|
2022-09-19 02:17:37 +00:00
|
|
|
return !KSandbox::isSnap();
|
2022-11-25 16:36:11 +00:00
|
|
|
#else // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
return false;
|
|
|
|
#endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-05-29 17:49:39 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 08:35:34 +00:00
|
|
|
void AutostartToggle(bool enabled, Fn<void(bool)> done) {
|
2022-11-21 06:57:24 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-11-04 08:35:34 +00:00
|
|
|
const auto guard = gsl::finally([&] {
|
2021-11-05 05:52:02 +00:00
|
|
|
if (done) {
|
|
|
|
done(enabled);
|
|
|
|
}
|
2021-11-04 08:35:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const auto silent = !done;
|
2022-09-19 02:17:37 +00:00
|
|
|
if (KSandbox::isFlatpak()) {
|
2021-11-04 08:35:34 +00:00
|
|
|
PortalAutostart(enabled, silent);
|
|
|
|
} else {
|
|
|
|
const auto autostart = QStandardPaths::writableLocation(
|
|
|
|
QStandardPaths::GenericConfigLocation)
|
2022-11-29 21:46:36 +00:00
|
|
|
+ u"/autostart/"_q;
|
2021-11-04 08:35:34 +00:00
|
|
|
|
|
|
|
if (enabled) {
|
2022-11-29 21:46:36 +00:00
|
|
|
GenerateDesktopFile(autostart, { u"-autostart"_q }, silent);
|
2021-11-04 08:35:34 +00:00
|
|
|
} else {
|
|
|
|
QFile::remove(autostart + QGuiApplication::desktopFileName());
|
|
|
|
}
|
|
|
|
}
|
2022-11-21 06:57:24 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-11-04 08:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AutostartSkip() {
|
|
|
|
return !cAutoStart();
|
|
|
|
}
|
|
|
|
|
2020-07-22 12:10:17 +00:00
|
|
|
bool TrayIconSupported() {
|
2022-01-21 16:51:43 +00:00
|
|
|
return QSystemTrayIcon::isSystemTrayAvailable();
|
2020-07-22 12:10:17 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 03:02:05 +00:00
|
|
|
bool SkipTaskbarSupported() {
|
2021-05-13 02:38:30 +00:00
|
|
|
if (const auto integration = WaylandIntegration::Instance()) {
|
|
|
|
return integration->skipTaskbarSupported();
|
|
|
|
}
|
|
|
|
|
2021-02-22 13:41:25 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
2021-05-13 02:38:30 +00:00
|
|
|
if (IsX11()) {
|
|
|
|
return base::Platform::XCB::IsSupportedByWM(
|
2022-05-20 13:11:31 +00:00
|
|
|
base::Platform::XCB::GetConnectionFromQt(),
|
2021-05-13 02:38:30 +00:00
|
|
|
"_NET_WM_STATE_SKIP_TASKBAR");
|
|
|
|
}
|
2021-02-22 13:41:25 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
|
|
|
|
|
|
|
return false;
|
2020-10-16 03:02:05 +00:00
|
|
|
}
|
|
|
|
|
2017-08-15 17:12:57 +00:00
|
|
|
} // namespace Platform
|
|
|
|
|
2014-07-08 10:24:21 +00:00
|
|
|
void psActivateProcess(uint64 pid) {
|
|
|
|
// objc_activateProgram();
|
|
|
|
}
|
|
|
|
|
2014-12-04 09:48:46 +00:00
|
|
|
QString psAppDataPath() {
|
2016-10-18 10:32:33 +00:00
|
|
|
// Previously we used ~/.TelegramDesktop, so look there first.
|
|
|
|
// If we find data there, we should still use it.
|
2021-09-10 21:55:28 +00:00
|
|
|
auto home = QDir::homePath();
|
2016-10-18 10:32:33 +00:00
|
|
|
if (!home.isEmpty()) {
|
2022-11-29 21:46:36 +00:00
|
|
|
auto oldPath = home + u"/.TelegramDesktop/"_q;
|
|
|
|
auto oldSettingsBase = oldPath + u"tdata/settings"_q;
|
2020-11-06 10:21:19 +00:00
|
|
|
if (QFile::exists(oldSettingsBase + '0')
|
|
|
|
|| QFile::exists(oldSettingsBase + '1')
|
|
|
|
|| QFile::exists(oldSettingsBase + 's')) {
|
2016-10-18 10:32:33 +00:00
|
|
|
return oldPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + '/';
|
2014-07-08 10:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void psDoCleanup() {
|
|
|
|
try {
|
2021-11-04 08:35:34 +00:00
|
|
|
Platform::AutostartToggle(false);
|
2014-07-18 10:37:34 +00:00
|
|
|
psSendToMenu(false, true);
|
2014-07-08 10:24:21 +00:00
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int psCleanup() {
|
|
|
|
psDoCleanup();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void psDoFixPrevious() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int psFixPrevious() {
|
|
|
|
psDoFixPrevious();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace Platform {
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void start() {
|
2022-11-11 13:37:42 +00:00
|
|
|
const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath());
|
|
|
|
char h[33] = { 0 };
|
|
|
|
hashMd5Hex(d.constData(), d.size(), h);
|
|
|
|
|
|
|
|
QGuiApplication::setDesktopFileName([&] {
|
2022-11-07 09:29:35 +00:00
|
|
|
if (KSandbox::isFlatpak()) {
|
2022-11-29 21:46:36 +00:00
|
|
|
return qEnvironmentVariable("FLATPAK_ID") + u".desktop"_q;
|
2022-11-07 09:29:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KSandbox::isSnap()) {
|
|
|
|
return qEnvironmentVariable("SNAP_INSTANCE_NAME")
|
|
|
|
+ '_'
|
|
|
|
+ cExeName()
|
2022-11-29 21:46:36 +00:00
|
|
|
+ u".desktop"_q;
|
2022-11-07 09:29:35 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 13:37:42 +00:00
|
|
|
if (!Core::UpdaterDisabled()) {
|
2022-11-21 04:38:14 +00:00
|
|
|
QByteArray md5Hash(h);
|
|
|
|
if (!Launcher::Instance().customWorkingDir()) {
|
|
|
|
const auto exePath = QFile::encodeName(
|
|
|
|
cExeDir() + cExeName());
|
|
|
|
|
|
|
|
hashMd5Hex(
|
|
|
|
exePath.constData(),
|
|
|
|
exePath.size(),
|
|
|
|
md5Hash.data());
|
|
|
|
}
|
|
|
|
|
2022-12-07 18:30:33 +00:00
|
|
|
return u"org.telegram.desktop._%1.desktop"_q.arg(
|
|
|
|
md5Hash.constData());
|
2022-09-04 20:15:59 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
return u"org.telegram.desktop.desktop"_q;
|
2022-09-04 20:15:59 +00:00
|
|
|
}());
|
|
|
|
|
2021-03-12 04:55:31 +00:00
|
|
|
LOG(("Launcher filename: %1").arg(QGuiApplication::desktopFileName()));
|
2020-03-30 08:18:50 +00:00
|
|
|
|
2022-11-25 12:53:34 +00:00
|
|
|
if (!qEnvironmentVariableIsSet("XDG_ACTIVATION_TOKEN")
|
|
|
|
&& qEnvironmentVariableIsSet("DESKTOP_STARTUP_ID")) {
|
|
|
|
qputenv("XDG_ACTIVATION_TOKEN", qgetenv("DESKTOP_STARTUP_ID"));
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:24:13 +00:00
|
|
|
qputenv("PULSE_PROP_application.name", AppName.utf8());
|
2022-09-19 02:58:27 +00:00
|
|
|
qputenv("PULSE_PROP_application.icon_name", base::IconName().toLatin1());
|
2020-03-03 01:24:13 +00:00
|
|
|
|
2021-09-10 21:55:28 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-11-28 19:15:51 +00:00
|
|
|
Glib::init();
|
|
|
|
Gio::init();
|
|
|
|
|
2021-03-18 03:37:06 +00:00
|
|
|
Glib::set_prgname(cExeName().toStdString());
|
2022-11-03 09:41:18 +00:00
|
|
|
Glib::set_application_name(AppName.data());
|
2021-03-18 03:37:06 +00:00
|
|
|
|
2020-08-01 12:33:45 +00:00
|
|
|
#ifdef DESKTOP_APP_USE_PACKAGED_RLOTTIE
|
|
|
|
g_warning(
|
|
|
|
"Application has been built with foreign rlottie, "
|
|
|
|
"animated emojis won't be colored to the selected pack.");
|
|
|
|
#endif // DESKTOP_APP_USE_PACKAGED_RLOTTIE
|
|
|
|
|
|
|
|
#ifdef DESKTOP_APP_USE_PACKAGED_FONTS
|
|
|
|
g_warning(
|
|
|
|
"Application was built without embedded fonts, "
|
|
|
|
"this may lead to font issues.");
|
|
|
|
#endif // DESKTOP_APP_USE_PACKAGED_FONTS
|
2020-11-01 01:03:50 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-09-10 21:55:28 +00:00
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
Webview::WebKit2Gtk::SetSocketPath(u"%1/%2-%3-webview-%4"_q.arg(
|
2021-11-28 19:15:51 +00:00
|
|
|
QDir::tempPath(),
|
|
|
|
h,
|
|
|
|
cGUIDStr(),
|
2022-11-29 21:46:36 +00:00
|
|
|
u"%1"_q).toStdString());
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
void finish() {
|
|
|
|
}
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2020-11-01 10:55:19 +00:00
|
|
|
void InstallLauncher(bool force) {
|
2022-11-21 06:57:24 +00:00
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2021-02-15 13:22:44 +00:00
|
|
|
static const auto DisabledByEnv = !qEnvironmentVariableIsEmpty(
|
|
|
|
"DESKTOPINTEGRATION");
|
2020-03-07 05:54:47 +00:00
|
|
|
|
2020-02-25 02:39:14 +00:00
|
|
|
// don't update desktop file for alpha version or if updater is disabled
|
2020-11-01 10:55:19 +00:00
|
|
|
if ((cAlphaVersion() || Core::UpdaterDisabled() || DisabledByEnv)
|
|
|
|
&& !force) {
|
2018-08-30 07:14:36 +00:00
|
|
|
return;
|
2020-11-01 10:55:19 +00:00
|
|
|
}
|
2014-12-04 09:48:46 +00:00
|
|
|
|
2020-01-21 00:10:10 +00:00
|
|
|
const auto applicationsPath = QStandardPaths::writableLocation(
|
|
|
|
QStandardPaths::ApplicationsLocation) + '/';
|
|
|
|
|
2022-11-21 06:57:24 +00:00
|
|
|
GenerateDesktopFile(applicationsPath);
|
2016-10-18 10:32:33 +00:00
|
|
|
|
2020-08-04 05:32:04 +00:00
|
|
|
const auto icons = QStandardPaths::writableLocation(
|
2022-11-29 21:46:36 +00:00
|
|
|
QStandardPaths::GenericDataLocation) + u"/icons/"_q;
|
2014-12-04 09:48:46 +00:00
|
|
|
|
2020-01-21 00:10:10 +00:00
|
|
|
if (!QDir(icons).exists()) QDir().mkpath(icons);
|
2016-10-18 10:32:33 +00:00
|
|
|
|
2022-11-29 21:46:36 +00:00
|
|
|
const auto icon = icons + base::IconName() + u".png"_q;
|
2020-11-06 10:21:19 +00:00
|
|
|
auto iconExists = QFile::exists(icon);
|
2021-07-23 16:39:31 +00:00
|
|
|
if (Local::oldSettingsVersion() < 2008012 && iconExists) {
|
2020-01-21 00:10:10 +00:00
|
|
|
// Icon was changed.
|
2020-11-06 10:21:19 +00:00
|
|
|
if (QFile::remove(icon)) {
|
2020-01-21 00:10:10 +00:00
|
|
|
iconExists = false;
|
|
|
|
}
|
2016-10-18 10:32:33 +00:00
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
if (!iconExists) {
|
2022-11-29 21:46:36 +00:00
|
|
|
if (QFile::copy(u":/gui/art/logo_256.png"_q, icon)) {
|
2020-02-25 02:39:14 +00:00
|
|
|
DEBUG_LOG(("App Info: Icon copied to '%1'").arg(icon));
|
2016-10-18 10:32:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2021-03-07 04:50:21 +00:00
|
|
|
QProcess::execute("update-desktop-database", {
|
2020-08-06 03:48:11 +00:00
|
|
|
applicationsPath
|
|
|
|
});
|
2022-11-21 06:57:24 +00:00
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2020-08-06 11:47:50 +00:00
|
|
|
}
|
2020-01-21 00:10:10 +00:00
|
|
|
|
2018-12-23 12:08:48 +00:00
|
|
|
PermissionStatus GetPermissionStatus(PermissionType type) {
|
2018-09-30 15:42:50 +00:00
|
|
|
return PermissionStatus::Granted;
|
|
|
|
}
|
|
|
|
|
2018-12-23 12:08:48 +00:00
|
|
|
void RequestPermission(PermissionType type, Fn<void(PermissionStatus)> resultCallback) {
|
2018-10-17 06:09:59 +00:00
|
|
|
resultCallback(PermissionStatus::Granted);
|
2018-09-30 15:42:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-23 12:08:48 +00:00
|
|
|
void OpenSystemSettingsForPermission(PermissionType type) {
|
|
|
|
}
|
|
|
|
|
2019-01-05 11:08:02 +00:00
|
|
|
bool OpenSystemSettings(SystemSettingsType type) {
|
|
|
|
if (type == SystemSettingsType::Audio) {
|
2020-11-04 15:50:17 +00:00
|
|
|
struct Command {
|
|
|
|
QString command;
|
|
|
|
QStringList arguments;
|
|
|
|
};
|
|
|
|
auto options = std::vector<Command>();
|
|
|
|
const auto add = [&](const char *option, const char *arg = nullptr) {
|
|
|
|
auto command = Command{ .command = option };
|
|
|
|
if (arg) {
|
|
|
|
command.arguments.push_back(arg);
|
|
|
|
}
|
|
|
|
options.push_back(std::move(command));
|
2019-01-11 10:07:56 +00:00
|
|
|
};
|
2022-01-06 19:24:21 +00:00
|
|
|
for (const auto &type : DesktopEnvironment::Get()) {
|
|
|
|
using DesktopEnvironment::Type;
|
|
|
|
if (type == Type::Unity) {
|
|
|
|
add("unity-control-center", "sound");
|
|
|
|
} else if (type == Type::KDE) {
|
|
|
|
add("kcmshell5", "kcm_pulseaudio");
|
|
|
|
add("kcmshell4", "phonon");
|
|
|
|
} else if (type == Type::Gnome) {
|
|
|
|
add("gnome-control-center", "sound");
|
|
|
|
} else if (type == Type::Cinnamon) {
|
|
|
|
add("cinnamon-settings", "sound");
|
|
|
|
} else if (type == Type::MATE) {
|
|
|
|
add("mate-volume-control");
|
|
|
|
}
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
2020-01-22 13:02:27 +00:00
|
|
|
add("pavucontrol-qt");
|
2019-01-11 10:07:56 +00:00
|
|
|
add("pavucontrol");
|
|
|
|
add("alsamixergui");
|
2020-11-04 15:50:17 +00:00
|
|
|
return ranges::any_of(options, [](const Command &command) {
|
2021-03-02 10:22:50 +00:00
|
|
|
return QProcess::startDetached(
|
|
|
|
command.command,
|
|
|
|
command.arguments);
|
2020-05-18 19:33:14 +00:00
|
|
|
});
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-01 06:44:23 +00:00
|
|
|
void NewVersionLaunched(int oldVersion) {
|
|
|
|
if (oldVersion > 0
|
|
|
|
&& oldVersion <= 4000002
|
|
|
|
&& qEnvironmentVariableIsSet("WAYLAND_DISPLAY")
|
|
|
|
&& DesktopEnvironment::IsGnome()
|
2022-11-29 21:46:36 +00:00
|
|
|
&& !QFile::exists(cWorkingDir() + u"tdata/nowayland"_q)) {
|
|
|
|
QFile f(cWorkingDir() + u"tdata/nowayland"_q);
|
2022-09-01 06:44:23 +00:00
|
|
|
if (f.open(QIODevice::WriteOnly)) {
|
|
|
|
f.write("1");
|
|
|
|
f.close();
|
|
|
|
Core::Restart(); // restart with X backend
|
|
|
|
}
|
|
|
|
}
|
2022-09-01 06:44:47 +00:00
|
|
|
if (oldVersion <= 4001001 && cAutoStart()) {
|
|
|
|
AutostartToggle(true);
|
|
|
|
}
|
2022-09-01 06:44:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-18 08:51:14 +00:00
|
|
|
namespace ThirdParty {
|
|
|
|
|
|
|
|
void start() {
|
2021-08-12 20:03:32 +00:00
|
|
|
LOG(("Icon theme: %1").arg(QIcon::themeName()));
|
|
|
|
LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName()));
|
2022-11-11 11:49:50 +00:00
|
|
|
|
|
|
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
|
|
|
LaunchGApplication();
|
|
|
|
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
2018-03-18 08:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void finish() {
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ThirdParty
|
|
|
|
|
|
|
|
} // namespace Platform
|
|
|
|
|
2014-07-18 10:37:34 +00:00
|
|
|
void psSendToMenu(bool send, bool silent) {
|
|
|
|
}
|
2014-09-29 02:47:30 +00:00
|
|
|
|
2015-06-03 18:13:01 +00:00
|
|
|
bool linuxMoveFile(const char *from, const char *to) {
|
|
|
|
FILE *ffrom = fopen(from, "rb"), *fto = fopen(to, "wb");
|
|
|
|
if (!ffrom) {
|
|
|
|
if (fto) fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!fto) {
|
|
|
|
fclose(ffrom);
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-01 12:54:38 +00:00
|
|
|
static const int BufSize = 65536;
|
|
|
|
char buf[BufSize];
|
|
|
|
while (size_t size = fread(buf, 1, BufSize, ffrom)) {
|
|
|
|
fwrite(buf, 1, size, fto);
|
|
|
|
}
|
2015-06-03 18:13:01 +00:00
|
|
|
|
|
|
|
struct stat fst; // from http://stackoverflow.com/questions/5486774/keeping-fileowner-and-permissions-after-copying-file-in-c
|
|
|
|
//let's say this wont fail since you already worked OK on that fp
|
|
|
|
if (fstat(fileno(ffrom), &fst) != 0) {
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//update to the same uid/gid
|
|
|
|
if (fchown(fileno(fto), fst.st_uid, fst.st_gid) != 0) {
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//update the permissions
|
|
|
|
if (fchmod(fileno(fto), fst.st_mode) != 0) {
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(ffrom);
|
|
|
|
fclose(fto);
|
|
|
|
|
|
|
|
if (unlink(from)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-17 16:37:21 +00:00
|
|
|
|
2019-06-21 12:27:46 +00:00
|
|
|
bool psLaunchMaps(const Data::LocationPoint &point) {
|
2016-02-17 16:37:21 +00:00
|
|
|
return false;
|
|
|
|
}
|