1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt
index 1b86c2cd1..1d19b9474 100644
--- a/Telegram/CMakeLists.txt
+++ b/Telegram/CMakeLists.txt
@@ -1205,5 +1205,6 @@ if (LINUX AND DESKTOP_APP_USE_PACKAGED)
install(FILES "Resources/art/icon256.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME "kotatogram.png")
install(FILES "Resources/art/icon512.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/512x512/apps" RENAME "kotatogram.png")
install(FILES "../lib/xdg/kotatogramdesktop.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" RENAME "${TDESKTOP_LAUNCHER_BASENAME}.desktop")
+ install(FILES "../lib/xdg/autostart/kotatogramdesktop.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/KotatogramDesktop/autostart" RENAME "${TDESKTOP_LAUNCHER_BASENAME}.desktop")
install(FILES "../lib/xdg/kotatogramdesktop.appdata.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo" RENAME "${TDESKTOP_LAUNCHER_BASENAME}.appdata.xml")
endif()
diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp
index a085956ac..ec02c18af 100644
--- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp
+++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp
@@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h"
#include "core/crash_reports.h"
#include "core/update_checker.h"
+#include "base/openssl_help.h"
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
@@ -87,10 +88,108 @@ void FallbackFontConfig() {
#endif // !DESKTOP_APP_USE_PACKAGED
}
+bool GenerateDesktopFile(const QString &targetPath, const QString &args) {
+ DEBUG_LOG(("App Info: placing .desktop file to %1").arg(targetPath));
+ if (!QDir(targetPath).exists()) QDir().mkpath(targetPath);
+
+ QString path = cWorkingDir() + qsl("tdata/"),
+ file = path
+ + qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME) ".desktop");
+ QDir().mkpath(path);
+ QFile f(file);
+ if (f.open(QIODevice::WriteOnly)) {
+ QTextStream s(&f);
+ s.setCodec("UTF-8");
+ s << "[Desktop Entry]\n";
+ s << "Version=1.0\n";
+ s << "Name=" << str_const_toString(AppName) << "\n";
+ s << "Comment=Experimental Telegram Desktop fork\n";
+ s << "TryExec="
+ << EscapeShell(QFile::encodeName(cExeDir() + cExeName())) << "\n";
+ s << "Exec="
+ << EscapeShell(QFile::encodeName(cExeDir() + cExeName()))
+ << (args.isEmpty() ? QString() : ' ' + args) << "\n";
+ s << "Icon=kotatogram\n";
+ s << "Terminal=false\n";
+ s << "StartupWMClass="
+ << QCoreApplication::instance()->applicationName() << "\n";
+ s << "Type=Application\n";
+ s << "Categories=Chat;Network;InstantMessaging;Qt;\n";
+ s << "MimeType=x-scheme-handler/tg;\n";
+ s << "Keywords=tg;chat;im;messaging;messenger;sms;tdesktop;\n";
+ s << "X-GNOME-UsesNotifications=true\n";
+ f.close();
+
+ if (RunShellCommand("desktop-file-install --dir="
+ + EscapeShell(QFile::encodeName(targetPath))
+ + " --delete-original "
+ + EscapeShell(QFile::encodeName(file)))) {
+ DEBUG_LOG(("App Info: removing old .desktop file"));
+ QFile(qsl("%1kotatogram.desktop").arg(targetPath)).remove();
+
+ RunShellCommand("update-desktop-database "
+ + EscapeShell(QFile::encodeName(targetPath)));
+ RunShellCommand("xdg-mime default "
+ + QByteArrayLiteral(
+ MACRO_TO_STRING(TDESKTOP_LAUNCHER_FILENAME))
+ + ".desktop x-scheme-handler/tg");
+ }
+
+ return true;
+ } else {
+ LOG(("App Error: Could not open '%1' for write").arg(file));
+ return false;
+ }
+}
+
} // namespace
namespace Platform {
+#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
+SandboxAutostart::SandboxAutostart()
+: _handleToken(qsl("tdesktop")
+ + QString::number(openssl::RandomValue<uint>()))
+, _backgroundInterface(
+ qsl("org.freedesktop.portal.Desktop"),
+ qsl("/org/freedesktop/portal/desktop"),
+ qsl("org.freedesktop.portal.Background"))
+, _requestInterface(
+ qsl("org.freedesktop.portal.Desktop"),
+ qsl("/org/freedesktop/portal/desktop/request/")
+ + _backgroundInterface.connection().baseService()
+ + '/' + _handleToken,
+ qsl("org.freedesktop.portal.Background")) {
+ _options["handle_token"] = _handleToken;
+ _options["commandline"] = QStringList()
+ << cExeName()
+ << qsl("-autostart");
+ _options["dbus-activatable"] = false;
+
+ connect(&_requestInterface,
+ SIGNAL(Response(QString)),
+ this, SLOT(responseHandler(QString)));
+}
+
+void SandboxAutostart::enableAutostart() {
+ _options["reason"] = qsl("Add to autostart");
+ _options["autostart"] = true;
+
+ _backgroundInterface.call(qsl("RequestBackground"), QString(), _options);
+}
+
+void SandboxAutostart::disableAutostart() {
+ _options["reason"] = qsl("Remove from autostart");
+ _options["autostart"] = false;
+
+ _backgroundInterface.call(qsl("RequestBackground"), QString(), _options);
+}
+
+void SandboxAutostart::responseHandler(const QVariantMap &response) {
+ LOG(("background: %1, autostart: %2").arg(response["background"].toBool()).arg(response["autostart"].toBool()));
+}
+#endif
+
void SetApplicationIcon(const QIcon &icon) {
QApplication::setWindowIcon(icon);
}
@@ -263,58 +362,23 @@ void RegisterCustomScheme() {
return;
#ifndef TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
- DEBUG_LOG(("App Info: placing .desktop file"));
- if (QDir(home + qsl(".local/")).exists()) {
- QString apps = home + qsl(".local/share/applications/");
- QString icons = home + qsl(".local/share/icons/");
- if (!QDir(apps).exists()) QDir().mkpath(apps);
- if (!QDir(icons).exists()) QDir().mkpath(icons);
-
- QString path = cWorkingDir() + qsl("tdata/"), file = path + qsl("kotatogramdesktop.desktop");
- QDir().mkpath(path);
- QFile f(file);
- if (f.open(QIODevice::WriteOnly)) {
- QString icon = icons + qsl("kotatogram.png");
- auto iconExists = QFile(icon).exists();
- if (Local::oldSettingsVersion() < 10021 && iconExists) {
- // Icon was changed.
- if (QFile(icon).remove()) {
- iconExists = false;
- }
- }
- if (!iconExists) {
- if (QFile(qsl(":/gui/art/logo_256.png")).copy(icon)) {
- DEBUG_LOG(("App Info: Icon copied to 'tdata'"));
- }
- }
-
- QTextStream s(&f);
- s.setCodec("UTF-8");
- s << "[Desktop Entry]\n";
- s << "Version=1.0\n";
- s << "Name=Kotatogram Desktop\n";
- s << "Comment=Experimental Telegram Desktop fork\n";
- s << "TryExec=" << EscapeShell(QFile::encodeName(cExeDir() + cExeName())) << "\n";
- s << "Exec=" << EscapeShell(QFile::encodeName(cExeDir() + cExeName())) << " -- %u\n";
- s << "Icon=kotatogram\n";
- s << "Terminal=false\n";
- s << "StartupWMClass=KotatogramDesktop\n";
- s << "Type=Application\n";
- s << "Categories=Network;InstantMessaging;Qt;\n";
- s << "MimeType=x-scheme-handler/tg;\n";
- s << "Keywords=tg;chat;im;messaging;messenger;sms;tdesktop;\n";
- s << "X-GNOME-UsesNotifications=true\n";
- f.close();
-
- if (RunShellCommand("desktop-file-install --dir=" + EscapeShell(QFile::encodeName(home + qsl(".local/share/applications"))) + " --delete-original " + EscapeShell(QFile::encodeName(file)))) {
- DEBUG_LOG(("App Info: removing old .desktop file"));
- QFile(qsl("%1.local/share/applications/kotatogram.desktop").arg(home)).remove();
-
- RunShellCommand("update-desktop-database " + EscapeShell(QFile::encodeName(home + qsl(".local/share/applications"))));
- RunShellCommand("xdg-mime default kotatogramdesktop.desktop x-scheme-handler/tg");
- }
- } else {
- LOG(("App Error: Could not open '%1' for write").arg(file));
+ GenerateDesktopFile(home + qsl(".local/share/applications/"),
+ qsl("-- %u"));
+
+ QString icons = home + qsl(".local/share/icons/");
+ if (!QDir(icons).exists()) QDir().mkpath(icons);
+
+ QString icon = icons + qsl("kotatogram.png");
+ auto iconExists = QFile(icon).exists();
+ if (Local::oldSettingsVersion() < 10021 && iconExists) {
+ // Icon was changed.
+ if (QFile(icon).remove()) {
+ iconExists = false;
+ }
+ }
+ if (!iconExists) {
+ if (QFile(qsl(":/gui/art/logo_256.png")).copy(icon)) {
+ DEBUG_LOG(("App Info: Icon copied to 'tdata'"));
}
}
#endif // !TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION
@@ -324,38 +388,6 @@ void RegisterCustomScheme() {
RunShellCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/needs_terminal false");
RunShellCommand("gconftool-2 -t bool -s /desktop/gnome/url-handlers/tg/enabled true");
}
-
- DEBUG_LOG(("App Info: placing .protocol file"));
- QString services;
- if (QDir(home + qsl(".kde4/")).exists()) {
- services = home + qsl(".kde4/share/kde4/services/");
- } else if (QDir(home + qsl(".kde/")).exists()) {
- services = home + qsl(".kde/share/kde4/services/");
- }
- if (!services.isEmpty()) {
- if (!QDir(services).exists()) QDir().mkpath(services);
-
- QString path = services, file = path + qsl("tg.protocol");
- QFile f(file);
- if (f.open(QIODevice::WriteOnly)) {
- QTextStream s(&f);
- s.setCodec("UTF-8");
- s << "[Protocol]\n";
- s << "exec=" << QFile::decodeName(EscapeShell(QFile::encodeName(cExeDir() + cExeName()))) << " -- %u\n";
- s << "protocol=tg\n";
- s << "input=none\n";
- s << "output=none\n";
- s << "helper=true\n";
- s << "listing=false\n";
- s << "reading=false\n";
- s << "writing=false\n";
- s << "makedir=false\n";
- s << "deleting=false\n";
- f.close();
- } else {
- LOG(("App Error: Could not open '%1' for write").arg(file));
- }
- }
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
}
@@ -416,6 +448,44 @@ bool psShowOpenWithMenu(int x, int y, const QString &file) {
}
void psAutoStart(bool start, bool silent) {
+ auto home = getHomeDir();
+ if (home.isEmpty() || cAlphaVersion() || cExeName().isEmpty()) return;
+
+ if (InSandbox()) {
+#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
+ if (start) {
+ SandboxAutostart().enableAutostart();
+ } else {
+ SandboxAutostart().disableAutostart();
+ }
+#endif
+ } else {
+ if (start) {
+ QString autostartFilePath = cExeDir() + qsl("../share/")
+ + QCoreApplication::instance()->applicationName()
+ + qsl("/autostart/")
+ + qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME) ".desktop");
+ if (QFile(autostartFilePath).exists()) {
+ QString autostart = home + qsl(".config/autostart/");
+ if (!QDir(autostart).exists()) QDir().mkpath(autostart);
+
+ if (RunShellCommand("desktop-file-install --dir="
+ + EscapeShell(QFile::encodeName(autostart))
+ + ' '
+ + EscapeShell(QFile::encodeName(autostartFilePath)))) {
+ RunShellCommand("update-desktop-database "
+ + EscapeShell(QFile::encodeName(autostart)));
+ }
+ } else {
+ GenerateDesktopFile(home + qsl(".config/autostart/"),
+ qsl("-autostart"));
+ }
+ } else {
+ QFile::remove(home + qsl(".config/autostart/")
+ + qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)
+ ".desktop"));
+ }
+ }
}
void psSendToMenu(bool send, bool silent) {
diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h
index 7546f758a..79a2a5f5e 100644
--- a/Telegram/SourceFiles/platform/linux/specific_linux.h
+++ b/Telegram/SourceFiles/platform/linux/specific_linux.h
@@ -11,12 +11,42 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <signal.h>
+#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
+#include <QtDBus/QDBusInterface>
+#endif
+
namespace Data {
class LocationPoint;
} // namespace Data
namespace Platform {
+#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
+class SandboxAutostart : public QObject {
+ Q_OBJECT
+
+public:
+ SandboxAutostart();
+
+ SandboxAutostart(const SandboxAutostart &other) = delete;
+ SandboxAutostart &operator=(const SandboxAutostart &other) = delete;
+ SandboxAutostart(SandboxAutostart &&other) = delete;
+ SandboxAutostart &operator=(SandboxAutostart &&other) = delete;
+
+ void enableAutostart();
+ void disableAutostart();
+
+private:
+ QString _handleToken;
+ QDBusInterface _backgroundInterface;
+ QDBusInterface _requestInterface;
+ QVariantMap _options;
+
+private slots:
+ void responseHandler(const QVariantMap &response);
+};
+#endif
+
inline void SetWatchingMediaKeys(bool watching) {
}
diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp
index eb06cb7ba..3e613ee5a 100644
--- a/Telegram/SourceFiles/settings/settings_advanced.cpp
+++ b/Telegram/SourceFiles/settings/settings_advanced.cpp
@@ -358,7 +358,7 @@ void SetupTrayContent(not_null<Ui::VerticalLayout*> container) {
}
#ifndef OS_WIN_STORE
- if (Platform::IsWindows()) {
+ if (Platform::IsWindows() || Platform::IsLinux()) {
const auto minimizedToggled = [] {
return cStartMinimized() && !Global::LocalPasscode();
};
@@ -369,9 +369,6 @@ void SetupTrayContent(not_null<Ui::VerticalLayout*> container) {
const auto minimized = addSlidingCheckbox(
tr::ktg_settings_start_min(tr::now),
minimizedToggled());
- const auto sendto = addCheckbox(
- tr::ktg_settings_add_sendto(tr::now),
- cSendToMenu());
autostart->checkedChanges(
) | rpl::filter([](bool checked) {
@@ -408,6 +405,12 @@ void SetupTrayContent(not_null<Ui::VerticalLayout*> container) {
) | rpl::start_with_next([=] {
minimized->entity()->setChecked(minimizedToggled());
}, minimized->lifetime());
+ }
+
+ if (Platform::IsWindows()) {
+ const auto sendto = addCheckbox(
+ tr::ktg_settings_add_sendto(tr::now),
+ cSendToMenu());
sendto->checkedChanges(
) | rpl::filter([](bool checked) {
diff --git a/lib/xdg/autostart/kotatogramdesktop.desktop b/lib/xdg/autostart/kotatogramdesktop.desktop
new file mode 100644
index 000000000..daf2aee2a
--- /dev/null
+++ b/lib/xdg/autostart/kotatogramdesktop.desktop
@@ -0,0 +1,13 @@
+[Desktop Entry]
+Version=1.0
+Name=Kotatogram Desktop
+Comment=Experimental Telegram Desktop fork
+Exec=kotatogram-desktop -autostart
+Icon=kotatogram
+Terminal=false
+StartupWMClass=KotatogramDesktop
+Type=Application
+Categories=Chat;Network;InstantMessaging;Qt;
+MimeType=x-scheme-handler/tg;
+Keywords=tg;chat;im;messaging;messenger;sms;tdesktop;
+X-GNOME-UsesNotifications=true
|