Handle tonsite:// links from the system.

This commit is contained in:
John Preston 2024-07-30 19:19:30 +02:00
parent fb9ce6d3a8
commit bb6c94ef4f
5 changed files with 37 additions and 18 deletions

View file

@ -37,6 +37,9 @@
<Extensions> <Extensions>
<uap3:Extension Category="windows.protocol"> <uap3:Extension Category="windows.protocol">
<uap3:Protocol Name="tg" Parameters="-- &quot;%1&quot;" /> <uap3:Protocol Name="tg" Parameters="-- &quot;%1&quot;" />
<uap3:Extension Category="windows.protocol">
</uap3:Extension>
<uap3:Protocol Name="tonsite" Parameters="-- &quot;%1&quot;" />
</uap3:Extension> </uap3:Extension>
<desktop:Extension <desktop:Extension
Category="windows.startupTask" Category="windows.startupTask"

View file

@ -683,7 +683,8 @@ bool Application::eventFilter(QObject *object, QEvent *e) {
if (const auto file = event->file(); !file.isEmpty()) { if (const auto file = event->file(); !file.isEmpty()) {
_filesToOpen.append(file); _filesToOpen.append(file);
_fileOpenTimer.callOnce(kFileOpenTimeoutMs); _fileOpenTimer.callOnce(kFileOpenTimeoutMs);
} else if (event->url().scheme() == u"tg"_q) { } else if (event->url().scheme() == u"tg"_q
|| event->url().scheme() == u"tonsite"_q) {
const auto url = QString::fromUtf8( const auto url = QString::fromUtf8(
event->url().toEncoded().trimmed()); event->url().toEncoded().trimmed());
cSetStartUrl(url.mid(0, 8192)); cSetStartUrl(url.mid(0, 8192));
@ -1084,13 +1085,17 @@ void Application::checkSendPaths() {
} }
void Application::checkStartUrl() { void Application::checkStartUrl() {
if (!cStartUrl().isEmpty() if (!cStartUrl().isEmpty()) {
&& _lastActivePrimaryWindow
&& !_lastActivePrimaryWindow->locked()) {
const auto url = cStartUrl(); const auto url = cStartUrl();
cSetStartUrl(QString()); if (url.startsWith("tonsite://", Qt::CaseInsensitive)) {
if (!openLocalUrl(url, {})) { cSetStartUrl(QString());
cSetStartUrl(url); iv().showTonSite(url, {});
} else if (_lastActivePrimaryWindow
&& !_lastActivePrimaryWindow->locked()) {
cSetStartUrl(QString());
if (!openLocalUrl(url, {})) {
cSetStartUrl(url);
}
} }
} }
} }
@ -1798,11 +1803,13 @@ void Application::startShortcuts() {
} }
void Application::RegisterUrlScheme() { void Application::RegisterUrlScheme() {
const auto arguments = Launcher::Instance().customWorkingDir()
? u"-workdir \"%1\""_q.arg(cWorkingDir())
: QString();
base::Platform::RegisterUrlScheme(base::Platform::UrlSchemeDescriptor{ base::Platform::RegisterUrlScheme(base::Platform::UrlSchemeDescriptor{
.executable = Platform::ExecutablePathForShortcuts(), .executable = Platform::ExecutablePathForShortcuts(),
.arguments = Launcher::Instance().customWorkingDir() .arguments = arguments,
? u"-workdir \"%1\""_q.arg(cWorkingDir())
: QString(),
.protocol = u"tg"_q, .protocol = u"tg"_q,
.protocolName = u"Telegram Link"_q, .protocolName = u"Telegram Link"_q,
.shortAppName = u"tdesktop"_q, .shortAppName = u"tdesktop"_q,
@ -1810,6 +1817,17 @@ void Application::RegisterUrlScheme() {
.displayAppName = AppName.utf16(), .displayAppName = AppName.utf16(),
.displayAppDescription = AppName.utf16(), .displayAppDescription = AppName.utf16(),
}); });
base::Platform::RegisterUrlScheme(base::Platform::UrlSchemeDescriptor{
.executable = Platform::ExecutablePathForShortcuts(),
.arguments = arguments,
.protocol = u"tonsite"_q,
.protocolName = u"TonSite Link"_q,
.shortAppName = u"tdesktop"_q,
.longAppName = QCoreApplication::applicationName(),
.displayAppName = AppName.utf16(),
.displayAppDescription = AppName.utf16(),
});
} }
bool IsAppLaunched() { bool IsAppLaunched() {

View file

@ -523,12 +523,10 @@ void Controller::createWebview(const Webview::StorageId &storageId) {
if (!script.isEmpty()) { if (!script.isEmpty()) {
_webview->eval(script); _webview->eval(script);
} }
//} else if (event == u"location_change"_q) { } else if (event == u"location_change"_q) {
// _index = object.value("index").toInt(); _index = object.value("index").toInt();
// _hash = object.value("hash").toString(); _hash = object.value("hash").toString();
// _back->toggle( _webview->refreshNavigationHistoryState();
// (object.value("position").toInt() > 0),
// anim::type::normal);
} }
}); });
}); });

View file

@ -1107,8 +1107,7 @@ void Instance::showTonSite(
case Type::OpenPage: case Type::OpenPage:
case Type::OpenLink: case Type::OpenLink:
if (urlChecked) { if (urlChecked) {
File::OpenUrl(event.url); UrlClickHandler::Open(event.url);
closeAll();
} else if (tonsite) { } else if (tonsite) {
showTonSite(event.url); showTonSite(event.url);
} }

View file

@ -38,6 +38,7 @@
<key>CFBundleURLSchemes</key> <key>CFBundleURLSchemes</key>
<array> <array>
<string>tg</string> <string>tg</string>
<string>tonsite</string>
</array> </array>
</dict> </dict>
</array> </array>