From 36db566428bca52d606102527778281c1984c1bd Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:05:12 -0800 Subject: [PATCH] qt: Add support for opening files directly on macOS. (#7304) * Associate 3ds files with Citra in Info.plist * qt: Add support for opening files directly on macOS. --------- Co-authored-by: shinra-electric <50119606+shinra-electric@users.noreply.github.com> --- dist/apple/Info.plist.in | 32 ++++++++++++++++++++++++++++++++ src/citra_qt/main.cpp | 20 ++++++++++++++++++++ src/citra_qt/main.h | 14 ++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/dist/apple/Info.plist.in b/dist/apple/Info.plist.in index 684c7e722f..22cfab0715 100644 --- a/dist/apple/Info.plist.in +++ b/dist/apple/Info.plist.in @@ -26,6 +26,38 @@ LSApplicationCategoryType public.app-category.games + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + 3ds + 3dsx + cci + cxi + cia + + CFBundleTypeName + Nintendo 3DS File + CFBundleTypeRole + Viewer + LSHandlerRank + Default + + + CFBundleTypeExtensions + + elf + axf + + CFBundleTypeName + Unix Executable and Linkable Format + CFBundleTypeRole + Viewer + LSHandlerRank + Alternate + + NSCameraUsageDescription This app requires camera access to emulate the 3DS's cameras. NSMicrophoneUsageDescription diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 1476428263..0c723330ab 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -229,6 +229,7 @@ GMainWindow::GMainWindow(Core::System& system_) SetDefaultUIGeometry(); RestoreUIState(); + ConnectAppEvents(); ConnectMenuEvents(); ConnectWidgetEvents(); @@ -761,6 +762,21 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) { } } +bool GApplicationEventFilter::eventFilter(QObject* object, QEvent* event) { + if (event->type() == QEvent::FileOpen) { + emit FileOpen(static_cast(event)); + return true; + } + return false; +} + +void GMainWindow::ConnectAppEvents() { + const auto filter = new GApplicationEventFilter(); + QGuiApplication::instance()->installEventFilter(filter); + + connect(filter, &GApplicationEventFilter::FileOpen, this, &GMainWindow::OnFileOpen); +} + void GMainWindow::ConnectWidgetEvents() { connect(game_list, &GameList::GameChosen, this, &GMainWindow::OnGameListLoadFile); connect(game_list, &GameList::OpenDirectory, this, &GMainWindow::OnGameListOpenDirectory); @@ -2752,6 +2768,10 @@ bool GMainWindow::DropAction(QDropEvent* event) { return true; } +void GMainWindow::OnFileOpen(const QFileOpenEvent* event) { + BootGame(event->file()); +} + void GMainWindow::dropEvent(QDropEvent* event) { DropAction(event); } diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 678f8e04de..9aaea0a2a7 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -41,6 +41,7 @@ class LoadingScreen; class MicroProfileDialog; class MultiplayerState; class ProfilerWidget; +class QFileOpenEvent; template class QFutureWatcher; class QLabel; @@ -96,6 +97,8 @@ public: bool DropAction(QDropEvent* event); void AcceptDropEvent(QDropEvent* event); + void OnFileOpen(const QFileOpenEvent* event); + void UninstallTitles( const std::vector>& titles); @@ -137,6 +140,7 @@ private: void SyncMenuUISettings(); void RestoreUIState(); + void ConnectAppEvents(); void ConnectWidgetEvents(); void ConnectMenuEvents(); void UpdateMenuState(); @@ -382,5 +386,15 @@ protected: void mouseReleaseEvent(QMouseEvent* event) override; }; +class GApplicationEventFilter : public QObject { + Q_OBJECT + +signals: + void FileOpen(const QFileOpenEvent* event); + +protected: + bool eventFilter(QObject* object, QEvent* event) override; +}; + Q_DECLARE_METATYPE(std::size_t); Q_DECLARE_METATYPE(Service::AM::InstallStatus);