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