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>
<uap3:Extension Category="windows.protocol">
<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>
<desktop:Extension
Category="windows.startupTask"

View file

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

View file

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

View file

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

View file

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