From 6ad0e8d61a3511494dd2fc1c8ffa1ab051ea273c Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Mon, 23 Aug 2021 10:27:03 +0200 Subject: [PATCH] macOS: Allow opening ROMs with melonDS from Finder. --- melon.plist.in | 12 ++++++++++++ src/frontend/qt_sdl/main.cpp | 19 +++++++++++++++++-- src/frontend/qt_sdl/main.h | 14 ++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/melon.plist.in b/melon.plist.in index 5b774a62..1057c474 100644 --- a/melon.plist.in +++ b/melon.plist.in @@ -22,5 +22,17 @@ NSMicrophoneUsageDescription We need microphone access so you can use the emulated DS microphone + CFBundleDocumentTypes + + + CFBundleTypeExtensions + + nds + srl + + CFBundleTypeRole + Viewer + + diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index 272df3cc..e2ee89ad 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -2726,7 +2726,23 @@ void emuStop() OSD::AddMessage(0xFFC040, "Shutdown"); } +MelonApplication::MelonApplication(int& argc, char** argv) + : QApplication(argc, argv) +{ + setWindowIcon(QIcon(":/melon-icon")); +} +bool MelonApplication::event(QEvent *event) +{ + if (event->type() == QEvent::FileOpen) + { + QFileOpenEvent *openEvent = static_cast(event); + printf("%s\n", openEvent->file().toUtf8().constData()); + mainWindow->loadROM(openEvent->file()); + } + + return QApplication::event(event); +} int main(int argc, char** argv) { @@ -2737,8 +2753,7 @@ int main(int argc, char** argv) Platform::Init(argc, argv); - QApplication melon(argc, argv); - melon.setWindowIcon(QIcon(":/melon-icon")); + MelonApplication melon(argc, argv); // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h index 4d570a31..2b935434 100644 --- a/src/frontend/qt_sdl/main.h +++ b/src/frontend/qt_sdl/main.h @@ -19,6 +19,7 @@ #ifndef MAIN_H #define MAIN_H +#include #include #include #include @@ -189,6 +190,14 @@ private: GLuint screenTexture; }; +class MelonApplication : public QApplication +{ + Q_OBJECT + +public: + MelonApplication(int &argc, char** argv); + bool event(QEvent* event) override; +}; class MainWindow : public QMainWindow { @@ -201,6 +210,9 @@ public: bool hasOGL; QOpenGLContext* getOGLContext(); + void loadROM(QString filename); + void loadROM(QByteArray *romData, QString archiveFileName, QString romFileName); + void onAppStateChanged(Qt::ApplicationState state); protected: @@ -278,8 +290,6 @@ private: QList recentFileList; QMenu *recentMenu; void updateRecentFilesMenu(); - void loadROM(QString filename); - void loadROM(QByteArray *romData, QString archiveFileName, QString romFileName); QString pickAndExtractFileFromArchive(QString archiveFileName, QByteArray *romBuffer);