mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-13 04:37:11 +02:00
Handle tonsite:// links from the system.
This commit is contained in:
parent
fb9ce6d3a8
commit
bb6c94ef4f
5 changed files with 37 additions and 18 deletions
|
@ -37,6 +37,9 @@
|
|||
<Extensions>
|
||||
<uap3:Extension Category="windows.protocol">
|
||||
<uap3:Protocol Name="tg" Parameters="-- "%1"" />
|
||||
<uap3:Extension Category="windows.protocol">
|
||||
</uap3:Extension>
|
||||
<uap3:Protocol Name="tonsite" Parameters="-- "%1"" />
|
||||
</uap3:Extension>
|
||||
<desktop:Extension
|
||||
Category="windows.startupTask"
|
||||
|
|
|
@ -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,13 +1085,17 @@ void Application::checkSendPaths() {
|
|||
}
|
||||
|
||||
void Application::checkStartUrl() {
|
||||
if (!cStartUrl().isEmpty()
|
||||
&& _lastActivePrimaryWindow
|
||||
&& !_lastActivePrimaryWindow->locked()) {
|
||||
if (!cStartUrl().isEmpty()) {
|
||||
const auto url = cStartUrl();
|
||||
cSetStartUrl(QString());
|
||||
if (!openLocalUrl(url, {})) {
|
||||
cSetStartUrl(url);
|
||||
if (url.startsWith("tonsite://", Qt::CaseInsensitive)) {
|
||||
cSetStartUrl(QString());
|
||||
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() {
|
||||
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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>tg</string>
|
||||
<string>tonsite</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
|
|
Loading…
Add table
Reference in a new issue