mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-02 11:10:31 +03:00
Fix file associations in macOS.
This commit is contained in:
+6
-1
@@ -593,6 +593,10 @@ function build_link_configuration( package_name, use_ee_icon )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if os.is_real("macosx") then
|
||||||
|
linkoptions { "-weak_framework UniformTypeIdentifiers" }
|
||||||
|
end
|
||||||
|
|
||||||
if _OPTIONS["with-mold-linker"] then
|
if _OPTIONS["with-mold-linker"] then
|
||||||
if _OPTIONS.platform == "clang" or _OPTIONS.platform == "clang-analyzer" then
|
if _OPTIONS.platform == "clang" or _OPTIONS.platform == "clang-analyzer" then
|
||||||
linkoptions { "-fuse-ld=mold" }
|
linkoptions { "-fuse-ld=mold" }
|
||||||
@@ -1644,7 +1648,8 @@ solution "eepp"
|
|||||||
set_targetdir("libs/" .. os.get_real() .. "/")
|
set_targetdir("libs/" .. os.get_real() .. "/")
|
||||||
includedirs { "include", "src" }
|
includedirs { "include", "src" }
|
||||||
files { "src/eepp/ui/platform/macos/macosmenubar.mm",
|
files { "src/eepp/ui/platform/macos/macosmenubar.mm",
|
||||||
"src/eepp/window/platform/macos/platformhelper.mm" }
|
"src/eepp/window/platform/macos/platformhelper.mm",
|
||||||
|
"src/eepp/system/fileassociation_macos.mm" }
|
||||||
buildoptions { "-x objective-c++" }
|
buildoptions { "-x objective-c++" }
|
||||||
if not is_vs() then
|
if not is_vs() then
|
||||||
buildoptions{ "-std=c++20" }
|
buildoptions{ "-std=c++20" }
|
||||||
|
|||||||
+5
-1
@@ -538,6 +538,9 @@ function build_link_configuration( package_name, use_ee_icon )
|
|||||||
linkoptions { "-Wl,-rpath,'$$ORIGIN'" }
|
linkoptions { "-Wl,-rpath,'$$ORIGIN'" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
filter "system:macosx"
|
||||||
|
linkoptions { "-weak_framework UniformTypeIdentifiers" }
|
||||||
|
|
||||||
filter { "system:bsd" }
|
filter { "system:bsd" }
|
||||||
if package_name ~= "eepp" and package_name ~= "eepp-static" then
|
if package_name ~= "eepp" and package_name ~= "eepp-static" then
|
||||||
if type(userelativelinks) == "function" then
|
if type(userelativelinks) == "function" then
|
||||||
@@ -1675,7 +1678,8 @@ workspace "eepp"
|
|||||||
cppdialect "C++20"
|
cppdialect "C++20"
|
||||||
incdirs { "include", "src" }
|
incdirs { "include", "src" }
|
||||||
files { "src/eepp/ui/platform/macos/macosmenubar.mm",
|
files { "src/eepp/ui/platform/macos/macosmenubar.mm",
|
||||||
"src/eepp/window/platform/macos/platformhelper.mm" }
|
"src/eepp/window/platform/macos/platformhelper.mm",
|
||||||
|
"src/eepp/system/fileassociation_macos.mm" }
|
||||||
buildoptions { "-x objective-c++" }
|
buildoptions { "-x objective-c++" }
|
||||||
build_base_cpp_configuration( "eepp-macos-helper" )
|
build_base_cpp_configuration( "eepp-macos-helper" )
|
||||||
target_dir_lib( "" )
|
target_dir_lib( "" )
|
||||||
|
|||||||
@@ -21,6 +21,10 @@
|
|||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if EE_PLATFORM == EE_PLATFORM_MACOS
|
||||||
|
extern "C" CFStringRef eeppFileAssociationTypeIdentifierForExtension( const char* extension );
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace EE::System {
|
namespace EE::System {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -557,11 +561,19 @@ static CFStringRef cfString( const std::string& value ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CFStringRef typeForExtension( const std::string& extension ) {
|
static CFStringRef typeForExtension( const std::string& extension ) {
|
||||||
CFRef extensionString( cfString( extension ) );
|
return eeppFileAssociationTypeIdentifierForExtension( extension.c_str() );
|
||||||
if ( !extensionString.get() )
|
}
|
||||||
return nullptr;
|
|
||||||
return UTTypeCreatePreferredIdentifierForTag(
|
static CFStringRef applicationIdentifier( const FileAssociationApplication& application ) {
|
||||||
kUTTagClassFilenameExtension, static_cast<CFStringRef>( extensionString.get() ), nullptr );
|
/* Launch Services uses the bundle identifier from the registered bundle. The cross-platform
|
||||||
|
* application id is not necessarily that identifier (ecode, for example, uses ensoft.dev in
|
||||||
|
* its macOS Info.plist). Prefer the bundle metadata when this process is running from a bundle,
|
||||||
|
* and retain the supplied id as a fallback for non-bundled callers. */
|
||||||
|
if ( auto* bundle = CFBundleGetMainBundle() ) {
|
||||||
|
if ( auto identifier = CFBundleGetIdentifier( bundle ) )
|
||||||
|
return static_cast<CFStringRef>( CFRetain( identifier ) );
|
||||||
|
}
|
||||||
|
return cfString( application.id );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -621,7 +633,7 @@ std::vector<std::string> FileAssociation::getRegisteredExtensions(
|
|||||||
registered.emplace_back( extension );
|
registered.emplace_back( extension );
|
||||||
}
|
}
|
||||||
#elif EE_PLATFORM == EE_PLATFORM_MACOS
|
#elif EE_PLATFORM == EE_PLATFORM_MACOS
|
||||||
CFRef applicationId( cfString( mApplication.id ) );
|
CFRef applicationId( applicationIdentifier( mApplication ) );
|
||||||
if ( !applicationId.get() ) {
|
if ( !applicationId.get() ) {
|
||||||
mLastError = "The application identifier is not valid UTF-8.";
|
mLastError = "The application identifier is not valid UTF-8.";
|
||||||
return {};
|
return {};
|
||||||
@@ -656,7 +668,7 @@ bool FileAssociation::setRegisteredExtensions( const std::vector<std::string>& r
|
|||||||
const auto supported = normalizeExtensions( supportedExtensions );
|
const auto supported = normalizeExtensions( supportedExtensions );
|
||||||
const auto requested = normalizeExtensions( registeredExtensions );
|
const auto requested = normalizeExtensions( registeredExtensions );
|
||||||
std::vector<std::string> selected;
|
std::vector<std::string> selected;
|
||||||
selected.reserve( (std::min)( requested.size(), supported.size() ) );
|
selected.reserve( ( std::min )( requested.size(), supported.size() ) );
|
||||||
std::set_intersection( requested.begin(), requested.end(), supported.begin(), supported.end(),
|
std::set_intersection( requested.begin(), requested.end(), supported.begin(), supported.end(),
|
||||||
std::back_inserter( selected ) );
|
std::back_inserter( selected ) );
|
||||||
#if EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_BSD
|
#if EE_PLATFORM == EE_PLATFORM_LINUX || EE_PLATFORM == EE_PLATFORM_BSD
|
||||||
@@ -712,7 +724,7 @@ bool FileAssociation::setRegisteredExtensions( const std::vector<std::string>& r
|
|||||||
mLastError = "Launch Services could not register the application bundle.";
|
mLastError = "Launch Services could not register the application bundle.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CFRef applicationId( cfString( mApplication.id ) );
|
CFRef applicationId( applicationIdentifier( mApplication ) );
|
||||||
if ( !applicationId.get() ) {
|
if ( !applicationId.get() ) {
|
||||||
mLastError = "The application identifier is not valid UTF-8.";
|
mLastError = "The application identifier is not valid UTF-8.";
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include <eepp/config.hpp>
|
||||||
|
|
||||||
|
#if EE_PLATFORM == EE_PLATFORM_MACOS
|
||||||
|
|
||||||
|
#import <CoreServices/CoreServices.h>
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
||||||
|
|
||||||
|
extern "C" CFStringRef eeppFileAssociationTypeIdentifierForExtension( const char* extension ) {
|
||||||
|
if ( extension == nullptr )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
NSString* extensionString = [NSString stringWithUTF8String:extension];
|
||||||
|
if ( extensionString == nil )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
if ( @available( macOS 11.0, * ) ) {
|
||||||
|
UTType* type = [UTType typeWithFilenameExtension:extensionString];
|
||||||
|
if ( type == nil || type.identifier == nil )
|
||||||
|
return nullptr;
|
||||||
|
return CFStringCreateWithCString( kCFAllocatorDefault, type.identifier.UTF8String,
|
||||||
|
kCFStringEncodingUTF8 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
CFStringRef type = UTTypeCreatePreferredIdentifierForTag(
|
||||||
|
kUTTagClassFilenameExtension, static_cast<CFStringRef>( extensionString ), nullptr );
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user