mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Integrate GApplication with QFileOpenEvent and Core::Application::activate
This commit is contained in:
parent
54841de991
commit
6aef6d7f4e
3 changed files with 31 additions and 39 deletions
|
@ -107,6 +107,7 @@ namespace {
|
||||||
constexpr auto kQuitPreventTimeoutMs = crl::time(1500);
|
constexpr auto kQuitPreventTimeoutMs = crl::time(1500);
|
||||||
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
constexpr auto kAutoLockTimeoutLateMs = crl::time(3000);
|
||||||
constexpr auto kClearEmojiImageSourceTimeout = 10 * crl::time(1000);
|
constexpr auto kClearEmojiImageSourceTimeout = 10 * crl::time(1000);
|
||||||
|
constexpr auto kFileOpenTimeoutMs = crl::time(1000);
|
||||||
|
|
||||||
LaunchState GlobalLaunchState/* = LaunchState::Running*/;
|
LaunchState GlobalLaunchState/* = LaunchState::Running*/;
|
||||||
|
|
||||||
|
@ -161,7 +162,8 @@ Application::Application(not_null<Launcher*> launcher)
|
||||||
, _langCloudManager(std::make_unique<Lang::CloudManager>(langpack()))
|
, _langCloudManager(std::make_unique<Lang::CloudManager>(langpack()))
|
||||||
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
|
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
|
||||||
, _tray(std::make_unique<Tray>())
|
, _tray(std::make_unique<Tray>())
|
||||||
, _autoLockTimer([=] { checkAutoLock(); }) {
|
, _autoLockTimer([=] { checkAutoLock(); })
|
||||||
|
, _fileOpenTimer([=] { checkFileOpen(); }) {
|
||||||
Ui::Integration::Set(&_private->uiIntegration);
|
Ui::Integration::Set(&_private->uiIntegration);
|
||||||
|
|
||||||
_platformIntegration->init();
|
_platformIntegration->init();
|
||||||
|
@ -656,14 +658,21 @@ bool Application::eventFilter(QObject *object, QEvent *e) {
|
||||||
case QEvent::FileOpen: {
|
case QEvent::FileOpen: {
|
||||||
if (object == QCoreApplication::instance()) {
|
if (object == QCoreApplication::instance()) {
|
||||||
const auto event = static_cast<QFileOpenEvent*>(e);
|
const auto event = static_cast<QFileOpenEvent*>(e);
|
||||||
const auto url = QString::fromUtf8(
|
if (const auto file = event->file(); !file.isEmpty()) {
|
||||||
event->url().toEncoded().trimmed());
|
_filesToOpen.append(file);
|
||||||
if (url.startsWith(u"tg://"_q, Qt::CaseInsensitive)) {
|
_fileOpenTimer.callOnce(kFileOpenTimeoutMs);
|
||||||
|
} else if (event->url().scheme() == u"tg"_q) {
|
||||||
|
const auto url = QString::fromUtf8(
|
||||||
|
event->url().toEncoded().trimmed());
|
||||||
cSetStartUrl(url.mid(0, 8192));
|
cSetStartUrl(url.mid(0, 8192));
|
||||||
checkStartUrl();
|
checkStartUrl();
|
||||||
}
|
if (_lastActivePrimaryWindow
|
||||||
if (_lastActivePrimaryWindow && StartUrlRequiresActivate(url)) {
|
&& StartUrlRequiresActivate(url)) {
|
||||||
_lastActivePrimaryWindow->activate();
|
_lastActivePrimaryWindow->activate();
|
||||||
|
}
|
||||||
|
} else if (event->url().scheme() == u"interpret"_q) {
|
||||||
|
_filesToOpen.append(event->url().toString());
|
||||||
|
_fileOpenTimer.callOnce(kFileOpenTimeoutMs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
@ -1033,6 +1042,12 @@ bool Application::canApplyLangPackWithoutRestart() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::checkFileOpen() {
|
||||||
|
cSetSendPaths(_filesToOpen);
|
||||||
|
_filesToOpen.clear();
|
||||||
|
checkSendPaths();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::checkSendPaths() {
|
void Application::checkSendPaths() {
|
||||||
if (!cSendPaths().isEmpty()
|
if (!cSendPaths().isEmpty()
|
||||||
&& _lastActivePrimaryWindow
|
&& _lastActivePrimaryWindow
|
||||||
|
|
|
@ -263,6 +263,7 @@ public:
|
||||||
// Internal links.
|
// Internal links.
|
||||||
void checkStartUrl();
|
void checkStartUrl();
|
||||||
void checkSendPaths();
|
void checkSendPaths();
|
||||||
|
void checkFileOpen();
|
||||||
bool openLocalUrl(const QString &url, QVariant context);
|
bool openLocalUrl(const QString &url, QVariant context);
|
||||||
bool openInternalUrl(const QString &url, QVariant context);
|
bool openInternalUrl(const QString &url, QVariant context);
|
||||||
[[nodiscard]] QString changelogLink() const;
|
[[nodiscard]] QString changelogLink() const;
|
||||||
|
@ -437,6 +438,9 @@ private:
|
||||||
crl::time _shouldLockAt = 0;
|
crl::time _shouldLockAt = 0;
|
||||||
base::Timer _autoLockTimer;
|
base::Timer _autoLockTimer;
|
||||||
|
|
||||||
|
QStringList _filesToOpen;
|
||||||
|
base::Timer _fileOpenTimer;
|
||||||
|
|
||||||
std::optional<base::Timer> _saveSettingsTimer;
|
std::optional<base::Timer> _saveSettingsTimer;
|
||||||
|
|
||||||
struct LeaveFilter {
|
struct LeaveFilter {
|
||||||
|
|
|
@ -262,11 +262,8 @@ void LaunchGApplication() {
|
||||||
|
|
||||||
app->signal_activate().connect([] {
|
app->signal_activate().connect([] {
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([] {
|
||||||
const auto window = Core::IsAppLaunched()
|
if (Core::IsAppLaunched()) {
|
||||||
? Core::App().activePrimaryWindow()
|
Core::App().activate();
|
||||||
: nullptr;
|
|
||||||
if (window) {
|
|
||||||
window->activate();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, true);
|
}, true);
|
||||||
|
@ -276,33 +273,9 @@ void LaunchGApplication() {
|
||||||
const Glib::ustring &hint) {
|
const Glib::ustring &hint) {
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
for (const auto &file : files) {
|
for (const auto &file : files) {
|
||||||
if (file->get_uri_scheme() == "file") {
|
QFileOpenEvent e(
|
||||||
gSendPaths.append(
|
QUrl(QString::fromStdString(file->get_uri())));
|
||||||
QString::fromStdString(file->get_path()));
|
QGuiApplication::sendEvent(qApp, &e);
|
||||||
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)) {
|
|
||||||
const auto window = Core::IsAppLaunched()
|
|
||||||
? Core::App().activePrimaryWindow()
|
|
||||||
: nullptr;
|
|
||||||
if (window) {
|
|
||||||
window->activate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cSetStartUrl(url);
|
|
||||||
Core::App().checkStartUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cSendPaths().isEmpty()) {
|
|
||||||
Core::App().checkSendPaths();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, true);
|
}, true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue