Skip to content

Commit

Permalink
Added macOS file association
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-calmejane committed Jul 20, 2023
1 parent 8d3c6b5 commit b1915f5
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
Binary file added resources/macOS/Icon_ANS.icns
Binary file not shown.
Binary file added resources/macOS/Icon_AVE.icns
Binary file not shown.
31 changes: 31 additions & 0 deletions resources/macOS/Info.plist.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,36 @@
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
<key>SUPublicEDKey</key>
<string>${HIVE_DSA_PUB_KEY}</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>ave</string>
</array>
<key>CFBundleTypeName</key>
<string>ATDECC Virtual Entity</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeIconFile</key>
<string>Icon_AVE.icns</string>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>ans</string>
</array>
<key>CFBundleTypeName</key>
<string>ATDECC Network State</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleTypeIconFile</key>
<string>Icon_ANS.icns</string>
<key>LSHandlerRank</key>
<string>Owner</string>
</dict>
</array>
</dict>
</plist>
3 changes: 3 additions & 0 deletions resources/macOS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Example of how to generate the icon files
- Get the PNG file of your icon (256 or 512)
- Create the icns file using [image2icon by Shiny Frog](https://apps.apple.com/fr/app/image2icon/id992115977) or any other software
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ if(WIN32)
find_package(BugTrap REQUIRED)
set(BUGREPORTER_LINK_LIBRARIES "BugTrap")
elseif(APPLE)
# Main icon
set(ICON_FILE Icon.icns)
set(ICON_PATH ${HIVE_RESOURCES_FOLDER}/macOS/${ICON_FILE})
set_source_files_properties(${ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
list(APPEND RESOURCE_FILES
${ICON_PATH}
)
# Add other icons
set_source_files_properties(${HIVE_RESOURCES_FOLDER}/macOS/Icon_AVE.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties(${HIVE_RESOURCES_FOLDER}/macOS/Icon_ANS.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
list(APPEND RESOURCE_FILES
${HIVE_RESOURCES_FOLDER}/macOS/Icon_AVE.icns
${HIVE_RESOURCES_FOLDER}/macOS/Icon_ANS.icns
)
endif()

set(HEADER_FILES_GENERATED
Expand Down
9 changes: 4 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,13 @@ int main(int argc, char* argv[])
filesToLoad.append(value);
}

#ifdef _WIN32
// If we have a single file to load, we want to forward it to any already running instance
if (filesToLoad.size() == 1 && instanceInfo.isAlreadyRunning)
{
[[maybe_unused]] auto const data = filesToLoad[0].toUtf8();
[[maybe_unused]] auto const dataLength = data.size();
auto const data = filesToLoad[0].toUtf8();
auto const dataLength = data.size();

// Notify the other instance (OS-dependant code)
#ifdef _WIN32
// On windows, we send a custom message to the main window of the other instance
// First we need to get the main window handle of the other instance (using its process ID)
static auto mainWindowHandle = HWND{ 0u };
Expand Down Expand Up @@ -230,8 +229,8 @@ int main(int argc, char* argv[])
SendMessageA(mainWindowHandle, WM_COPYDATA, 0, reinterpret_cast<LPARAM>(&cds));
return 0;
}
#endif // _WIN32
}
#endif // _WIN32

// Check if another instance is already running and the single instance option was specified
if (instanceInfo.isAlreadyRunning && parser.isSet(singleOption))
Expand Down
25 changes: 22 additions & 3 deletions src/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ extern "C"

Q_DECLARE_METATYPE(la::avdecc::protocol::ProtocolInterface::Type)

class MainWindowImpl final : public QObject, public Ui::MainWindow, public settings::SettingsManager::Observer, public QAbstractNativeEventFilter
class MainWindowImpl final : public QObject, public Ui::MainWindow, public settings::SettingsManager::Observer
#ifdef _WIN32
, public QAbstractNativeEventFilter
#endif // _WIN32
{
Q_OBJECT
public:
Expand All @@ -112,7 +115,10 @@ class MainWindowImpl final : public QObject, public Ui::MainWindow, public setti
// Setup the current profile
setupProfile();

#ifdef _WIN32
qApp->installNativeEventFilter(this);
#endif // _WIN32
qApp->installEventFilter(this);

// Force creation of the MC Domain Manager here, since it was removed from the ControllerModel (it registers to the ControllerManager events so we need to create it before entities are discovered)
// (Will be completely removed in the future)
Expand Down Expand Up @@ -146,8 +152,10 @@ class MainWindowImpl final : public QObject, public Ui::MainWindow, public setti
void showChangeLog(QString const title, QString const versionString);
void showNewsFeed(QString const& news);
void updateStyleSheet(qtMate::material::color::Name const colorName, QString const& filename);
#ifdef _WIN32
virtual bool nativeEventFilter(QByteArray const& eventType, void* message, qintptr*) override;

#endif // _WIN32
virtual bool eventFilter(QObject *watched, QEvent *event) override;
// settings::SettingsManager::Observer overrides
virtual void onSettingChanged(settings::SettingsManager::Setting const& name, QVariant const& value) noexcept override;

Expand Down Expand Up @@ -1277,9 +1285,9 @@ void MainWindowImpl::updateStyleSheet(qtMate::material::color::Name const colorN
}
}

#ifdef _WIN32
bool MainWindowImpl::nativeEventFilter(QByteArray const& eventType, void* message, qintptr*)
{
#ifdef _WIN32
if (eventType == "windows_generic_MSG")
{
auto const* const msg = static_cast<MSG const*>(message);
Expand All @@ -1303,7 +1311,18 @@ bool MainWindowImpl::nativeEventFilter(QByteArray const& eventType, void* messag
return true;
}
}
return false;
}
#endif // _WIN32

bool MainWindowImpl::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::FileOpen)
{
auto const* const fileEvent = static_cast<QFileOpenEvent const*>(event);
loadFile(fileEvent->file(), false);
return true;
}
return false;
}

Expand Down

0 comments on commit b1915f5

Please sign in to comment.