From a87b1b3def57702b999daee21617d34780b723f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 24 Sep 2023 01:33:15 -0300 Subject: [PATCH] On macOS check the PATH defined in the shell and append all pending PATHs to the current environment. This should improve binary finding. Solves issue SpartanJ/ecode#63. Renamed MACOSX references to MACOS / macOS. --- include/eepp/config.hpp | 6 +- include/eepp/graphics/renderer/opengl.hpp | 4 +- include/eepp/window/keycodes.hpp | 2 +- include/eepp/window/windowcontext.hpp | 4 +- include/eepp/window/windowhandle.hpp | 2 +- projects/macos/ee.config | 1 - src/eepp/graphics/renderer/renderer.cpp | 4 +- src/eepp/network/platform/unix/socketimpl.cpp | 2 +- src/eepp/network/socket.cpp | 2 +- src/eepp/scene/eventdispatcher.cpp | 2 +- src/eepp/system/filesystem.cpp | 2 +- src/eepp/system/process.cpp | 2 +- src/eepp/system/sys.cpp | 18 +++-- src/eepp/window/backend/SDL2/backendsdl2.cpp | 2 +- .../backend/SDL2/joystickmanagersdl2.cpp | 2 +- src/eepp/window/backend/SDL2/windowsdl2.cpp | 4 +- src/eepp/window/backend/SDL2/windowsdl2.hpp | 2 +- src/eepp/window/backend/SDL2/wminfo.cpp | 6 +- src/eepp/window/window.cpp | 2 +- src/tools/ecode/ecode.cpp | 69 +++++++++++++++++-- src/tools/eterm/eterm.cpp | 2 +- src/tools/uieditor/uieditor.cpp | 2 +- 22 files changed, 102 insertions(+), 40 deletions(-) diff --git a/include/eepp/config.hpp b/include/eepp/config.hpp index 729134913..d9aab37d3 100644 --- a/include/eepp/config.hpp +++ b/include/eepp/config.hpp @@ -3,7 +3,7 @@ #define EE_PLATFORM_WIN 1 #define EE_PLATFORM_LINUX 2 -#define EE_PLATFORM_MACOSX 3 +#define EE_PLATFORM_MACOS 3 #define EE_PLATFORM_BSD 4 #define EE_PLATFORM_SOLARIS 5 #define EE_PLATFORM_HAIKU 6 @@ -32,7 +32,7 @@ ( defined( TARGET_IPHONE_SIMULATOR ) && TARGET_IPHONE_SIMULATOR ) #define EE_PLATFORM EE_PLATFORM_IOS #else -#define EE_PLATFORM EE_PLATFORM_MACOSX +#define EE_PLATFORM EE_PLATFORM_MACOS #endif #elif defined( __emscripten__ ) || defined( EMSCRIPTEN ) #define EE_PLATFORM EE_PLATFORM_EMSCRIPTEN @@ -192,7 +192,7 @@ #define EE_SHADERS_SUPPORTED #endif -#if ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || \ +#if ( EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOS || \ defined( EE_X11_PLATFORM ) ) && \ !defined( EE_GLES ) #define EE_GLEW_AVAILABLE diff --git a/include/eepp/graphics/renderer/opengl.hpp b/include/eepp/graphics/renderer/opengl.hpp index 4ff358c02..f1b335752 100644 --- a/include/eepp/graphics/renderer/opengl.hpp +++ b/include/eepp/graphics/renderer/opengl.hpp @@ -12,7 +12,7 @@ #ifndef EE_GLES //! GL2 and GL3 ( PC platform ) -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS #include #else #if EE_PLATFORM == EE_PLATFORM_WIN @@ -26,7 +26,7 @@ #ifndef EE_GLEW_AVAILABLE #if defined( EE_X11_PLATFORM ) #include -#elif EE_PLATFORM == EE_PLATFORM_MACOSX +#elif EE_PLATFORM == EE_PLATFORM_MACOS #include #endif #endif diff --git a/include/eepp/window/keycodes.hpp b/include/eepp/window/keycodes.hpp index 399fd1c75..50559ca42 100644 --- a/include/eepp/window/keycodes.hpp +++ b/include/eepp/window/keycodes.hpp @@ -690,7 +690,7 @@ enum KeyModTable { #define KEYMOD_META ( KEYMOD_LMETA | KEYMOD_RMETA ) #define KEYMOD_CTRL_SHIFT_ALT_META ( KEYMOD_CTRL | KEYMOD_SHIFT | KEYMOD_ALT | KEYMOD_META ) -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS #define KEYMOD_DEFAULT_MODIFIER KEYMOD_META #elif EE_PLATFORM == EE_PLATFORM_HAIKU #define KEYMOD_DEFAULT_MODIFIER KEYMOD_ALT diff --git a/include/eepp/window/windowcontext.hpp b/include/eepp/window/windowcontext.hpp index d550cb6d1..d503cf2f7 100644 --- a/include/eepp/window/windowcontext.hpp +++ b/include/eepp/window/windowcontext.hpp @@ -10,7 +10,7 @@ struct __glXContextRec; #else struct __GLXcontextRec; #endif -#elif EE_PLATFORM == EE_PLATFORM_MACOSX +#elif EE_PLATFORM == EE_PLATFORM_MACOS struct __AGLContextRec; #endif #endif @@ -32,7 +32,7 @@ typedef struct __GLXcontextRec* GLXContext; typedef GLXContext eeWindowContex; -#elif EE_PLATFORM == EE_PLATFORM_MACOSX +#elif EE_PLATFORM == EE_PLATFORM_MACOS typedef struct __AGLContextRec* AGLContext; diff --git a/include/eepp/window/windowhandle.hpp b/include/eepp/window/windowhandle.hpp index 3aa0c082a..cb601bb6f 100644 --- a/include/eepp/window/windowhandle.hpp +++ b/include/eepp/window/windowhandle.hpp @@ -22,7 +22,7 @@ typedef unsigned long X11Cursor; typedef struct _XDisplay* eeWindowHandle; -#elif EE_PLATFORM == EE_PLATFORM_MACOSX +#elif EE_PLATFORM == EE_PLATFORM_MACOS typedef void* eeWindowHandle; // NSWindow * #else typedef unsigned int eeWindowHandle; //! Fallback diff --git a/projects/macos/ee.config b/projects/macos/ee.config index f43f359f8..d8218324f 100644 --- a/projects/macos/ee.config +++ b/projects/macos/ee.config @@ -1,5 +1,4 @@ #define EE_SDL_VERSION_2 -#define EE_X11_PLATFORM #define EE_DEBUG #define EE_MEMORY_MANAGER #define EE_SHADERS_SUPPORTED diff --git a/src/eepp/graphics/renderer/renderer.cpp b/src/eepp/graphics/renderer/renderer.cpp index 189867c74..d74674c63 100644 --- a/src/eepp/graphics/renderer/renderer.cpp +++ b/src/eepp/graphics/renderer/renderer.cpp @@ -230,7 +230,7 @@ void Renderer::writeExtension( Uint8 Pos, Uint32 BitWrite ) { void Renderer::init() { #ifdef EE_GLEW_AVAILABLE -#if EE_PLATFORM != EE_PLATFORM_MACOSX +#if EE_PLATFORM != EE_PLATFORM_MACOS glewExperimental = 1; #endif bool glewOn = ( GLEW_OK == glewInit() ); @@ -377,7 +377,7 @@ std::string Renderer::getExtensions() { std::string exts; #if defined( EE_X11_PLATFORM ) || EE_PLATFORM == EE_PLATFORM_WIN || \ - EE_PLATFORM == EE_PLATFORM_MACOSX + EE_PLATFORM == EE_PLATFORM_MACOS if ( GLv_3 == version() || GLv_3CP == version() ) { static pglGetStringiFunc eeglGetStringiFunc = NULL; diff --git a/src/eepp/network/platform/unix/socketimpl.cpp b/src/eepp/network/platform/unix/socketimpl.cpp index cf30269d1..730a8a5fb 100644 --- a/src/eepp/network/platform/unix/socketimpl.cpp +++ b/src/eepp/network/platform/unix/socketimpl.cpp @@ -18,7 +18,7 @@ sockaddr_in SocketImpl::createAddress( Uint32 address, unsigned short port ) { addr.sin_family = AF_INET; addr.sin_port = htons( port ); -#if EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_IOS +#if EE_PLATFORM == EE_PLATFORM_MACOS || EE_PLATFORM == EE_PLATFORM_IOS addr.sin_len = sizeof( addr ); #endif diff --git a/src/eepp/network/socket.cpp b/src/eepp/network/socket.cpp index 410b73aff..9155cab3a 100644 --- a/src/eepp/network/socket.cpp +++ b/src/eepp/network/socket.cpp @@ -57,7 +57,7 @@ void Socket::create( SocketHandle handle ) { } // On Mac OS X, disable the SIGPIPE signal on disconnection -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS if ( setsockopt( mSocket, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast( &yes ), sizeof( yes ) ) == -1 ) { Log::error( "Failed to set socket option \"SO_NOSIGPIPE\"" ); diff --git a/src/eepp/scene/eventdispatcher.cpp b/src/eepp/scene/eventdispatcher.cpp index e861ac2dd..49dc60980 100644 --- a/src/eepp/scene/eventdispatcher.cpp +++ b/src/eepp/scene/eventdispatcher.cpp @@ -110,7 +110,7 @@ void EventDispatcher::update( const Time& time ) { sendMsg( mOverNode, NodeMessage::MouseDown, mInput->getPressTrigger() ); } } -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS else if ( NULL != mOverNode && mInput->getReleaseTrigger() && !( mInput->getPressTrigger() & mInput->getReleaseTrigger() ) && !( mInput->getLastPressTrigger() & mInput->getReleaseTrigger() ) ) { diff --git a/src/eepp/system/filesystem.cpp b/src/eepp/system/filesystem.cpp index 16ccf93aa..516f6e050 100644 --- a/src/eepp/system/filesystem.cpp +++ b/src/eepp/system/filesystem.cpp @@ -639,7 +639,7 @@ Int64 FileSystem::getDiskFreeSpace( const std::string& path ) { #if defined( EE_PLATFORM_POSIX ) struct statvfs data; statvfs( path.c_str(), &data ); -#if EE_PLATFORM != EE_PLATFORM_MACOSX +#if EE_PLATFORM != EE_PLATFORM_MACOS return (Int64)data.f_bsize * (Int64)data.f_bfree; #else return (Int64)data.f_frsize * (Int64)data.f_bfree; diff --git a/src/eepp/system/process.cpp b/src/eepp/system/process.cpp index 05207f6af..9bb97d942 100644 --- a/src/eepp/system/process.cpp +++ b/src/eepp/system/process.cpp @@ -7,7 +7,7 @@ #include #include -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS #define SUBPROCESS_USE_POSIX_SPAWN #endif #include diff --git a/src/eepp/system/sys.cpp b/src/eepp/system/sys.cpp index d5e6d4170..445726671 100644 --- a/src/eepp/system/sys.cpp +++ b/src/eepp/system/sys.cpp @@ -19,7 +19,7 @@ #include #endif -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS #include #include #include @@ -48,7 +48,7 @@ #include #endif -#if EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD || \ +#if EE_PLATFORM == EE_PLATFORM_MACOS || EE_PLATFORM == EE_PLATFORM_BSD || \ EE_PLATFORM == EE_PLATFORM_IOS #include #include @@ -386,7 +386,7 @@ std::string Sys::getPlatform() { return "Haiku"; #elif EE_PLATFORM == EE_PLATFORM_IOS return "iOS"; -#elif EE_PLATFORM == EE_PLATFORM_MACOSX +#elif EE_PLATFORM == EE_PLATFORM_MACOS return "macOS"; #elif EE_PLATFORM == EE_PLATFORM_SOLARIS return "Solaris"; @@ -485,7 +485,7 @@ void Sys::sleep( const Time& time ) { } static std::string sGetProcessPath() { -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS char pathbuf[PROC_PIDPATHINFO_MAXSIZE]; pid_t pid = getpid(); int ret = proc_pidpath (pid, pathbuf, sizeof(pathbuf)); @@ -674,7 +674,7 @@ std::string Sys::getConfigPath( const std::string& appname ) { _snprintf( path, EE_MAX_CFG_PATH_LEN, "%s\\%s", home, appname.c_str() ); #endif -#elif EE_PLATFORM == EE_PLATFORM_MACOSX +#elif EE_PLATFORM == EE_PLATFORM_MACOS char* home = getenv( "HOME" ); if ( NULL == home ) { @@ -771,7 +771,7 @@ int Sys::getCPUCount() { nprocs = sysconf( _SC_NPROCESSORS_ONLN ); #elif EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN return EM_ASM_INT( { return navigator.hardwareConcurrency; } ); -#elif EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD || \ +#elif EE_PLATFORM == EE_PLATFORM_MACOS || EE_PLATFORM == EE_PLATFORM_BSD || \ EE_PLATFORM == EE_PLATFORM_IOS int mib[2]; int maxproc = 1; @@ -967,7 +967,7 @@ std::vector Sys::getLogicalDrives() { } endmntent( file ); return ret; -#elif EE_PLATFORM == EE_PLATFORM_MACOSX || EE_PLATFORM == EE_PLATFORM_BSD || \ +#elif EE_PLATFORM == EE_PLATFORM_MACOS || EE_PLATFORM == EE_PLATFORM_BSD || \ EE_PLATFORM == EE_PLATFORM_IOS std::vector ret; struct statfs* mounts; @@ -1021,6 +1021,10 @@ std::vector Sys::getLogicalDrives() { #endif std::string Sys::which( const std::string& exeName, const std::vector& customSearchPaths ) { + if ( exeName.find_first_of( FileSystem::getOSSlash() ) != std::string::npos && + FileSystem::fileExists( exeName ) ) + return exeName; + std::vector PATHS = getEnvSplitted( "PATH" ); #if EE_PLATFORM == EE_PLATFORM_WIN static std::vector PATHEXTS = getEnvSplitted( "PATHEXT" ); diff --git a/src/eepp/window/backend/SDL2/backendsdl2.cpp b/src/eepp/window/backend/SDL2/backendsdl2.cpp index 866ce0402..27e6cd503 100644 --- a/src/eepp/window/backend/SDL2/backendsdl2.cpp +++ b/src/eepp/window/backend/SDL2/backendsdl2.cpp @@ -21,7 +21,7 @@ WindowBackendSDL2::WindowBackendSDL2() : WindowBackendLibrary() { } WindowBackendSDL2::~WindowBackendSDL2() { -#if EE_PLATFORM != EE_PLATFORM_MACOSX +#if EE_PLATFORM != EE_PLATFORM_MACOS SDL_Quit(); #endif } diff --git a/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp b/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp index 7fe2e85a8..fae90663c 100644 --- a/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp +++ b/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp @@ -6,7 +6,7 @@ namespace EE { namespace Window { namespace Backend { namespace SDL2 { void closeSubsystem() { -#if EE_PLATFORM != EE_PLATFORM_MACOSX && EE_PLATFORM != EE_PLATFORM_IOS +#if EE_PLATFORM != EE_PLATFORM_MACOS && EE_PLATFORM != EE_PLATFORM_IOS if ( SDL_WasInit( SDL_INIT_JOYSTICK ) ) SDL_QuitSubSystem( SDL_INIT_JOYSTICK ); #endif diff --git a/src/eepp/window/backend/SDL2/windowsdl2.cpp b/src/eepp/window/backend/SDL2/windowsdl2.cpp index 5538141ea..4762b7ec6 100644 --- a/src/eepp/window/backend/SDL2/windowsdl2.cpp +++ b/src/eepp/window/backend/SDL2/windowsdl2.cpp @@ -21,7 +21,7 @@ #include #endif -#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || \ +#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOS || \ defined( EE_X11_PLATFORM ) || EE_PLATFORM == EE_PLATFORM_IOS || \ EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN #define SDL2_THREADED_GLCONTEXT @@ -272,7 +272,7 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) { SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, mWindow.ContextConfig.Multisamples ); } -#if EE_PLATFORM != EE_PLATFORM_MACOSX && EE_PLATFORM != EE_PLATFORM_IOS && \ +#if EE_PLATFORM != EE_PLATFORM_MACOS && EE_PLATFORM != EE_PLATFORM_IOS && \ EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN mWindow.WindowConfig.Width *= mWindow.WindowConfig.PixelDensity; mWindow.WindowConfig.Height *= mWindow.WindowConfig.PixelDensity; diff --git a/src/eepp/window/backend/SDL2/windowsdl2.hpp b/src/eepp/window/backend/SDL2/windowsdl2.hpp index 5f97d72ff..4b2be4ed6 100644 --- a/src/eepp/window/backend/SDL2/windowsdl2.hpp +++ b/src/eepp/window/backend/SDL2/windowsdl2.hpp @@ -9,7 +9,7 @@ #include #include -#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || \ +#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOS || \ defined( EE_X11_PLATFORM ) || EE_PLATFORM == EE_PLATFORM_IOS || \ EE_PLATFORM == EE_PLATFORM_ANDROID #define EE_USE_WMINFO diff --git a/src/eepp/window/backend/SDL2/wminfo.cpp b/src/eepp/window/backend/SDL2/wminfo.cpp index 8b0cce5a5..af8a5e95a 100644 --- a/src/eepp/window/backend/SDL2/wminfo.cpp +++ b/src/eepp/window/backend/SDL2/wminfo.cpp @@ -2,7 +2,7 @@ #ifdef EE_BACKEND_SDL2 -#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOSX || \ +#if EE_PLATFORM == EE_PLATFORM_WIN || EE_PLATFORM == EE_PLATFORM_MACOS || \ defined( EE_X11_PLATFORM ) || EE_PLATFORM == EE_PLATFORM_IOS || \ EE_PLATFORM_ANDROID == EE_PLATFORM #define EE_WMINFO @@ -42,7 +42,7 @@ X11Window WMInfo::getWindow() { eeWindowHandle WMInfo::getWindowHandler() { #if EE_PLATFORM == EE_PLATFORM_WIN || defined( EE_X11_PLATFORM ) || \ - EE_PLATFORM == EE_PLATFORM_MACOSX + EE_PLATFORM == EE_PLATFORM_MACOS SDL_SysWMinfo* info = static_cast( mWMInfo ); #endif @@ -50,7 +50,7 @@ eeWindowHandle WMInfo::getWindowHandler() { return info->info.win.window; #elif defined( EE_X11_PLATFORM ) return info->info.x11.display; -#elif EE_PLATFORM == EE_PLATFORM_MACOSX +#elif EE_PLATFORM == EE_PLATFORM_MACOS return info->info.cocoa.window; #else return 0; diff --git a/src/eepp/window/window.cpp b/src/eepp/window/window.cpp index 3484cb503..200fd9cc2 100644 --- a/src/eepp/window/window.cpp +++ b/src/eepp/window/window.cpp @@ -490,7 +490,7 @@ std::string Window::getTitle() { eeWindowContex Window::getContext() const { #if defined( EE_GLEW_AVAILABLE ) && \ ( EE_PLATFORM == EE_PLATFORM_WIN || defined( EE_X11_PLATFORM ) || \ - EE_PLATFORM == EE_PLATFORM_MACOSX ) + EE_PLATFORM == EE_PLATFORM_MACOS ) return mWindow.Context; #else return 0; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index d877dade1..50a43bcdf 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -32,7 +32,7 @@ using json = nlohmann::json; #endif #include #endif -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS #include "macos/macos.hpp" #endif @@ -1822,7 +1822,7 @@ std::map App::getLocalKeybindings() { { { KEY_P, KeyMod::getDefaultModifier() }, "open-command-palette" }, { { KEY_F, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-global-search" }, { { KEY_L, KeyMod::getDefaultModifier() }, "go-to-line" }, -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS { { KEY_M, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "menu-toggle" }, #else { { KEY_M, KeyMod::getDefaultModifier() }, "menu-toggle" }, @@ -1865,7 +1865,7 @@ std::map App::getMigrateKeybindings() { { "switch-to-tab-6", "alt+6" }, { "switch-to-tab-7", "alt+7" }, { "switch-to-tab-8", "alt+8" }, { "switch-to-tab-9", "alt+9" }, { "switch-to-last-tab", "alt+0" }, -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS { "menu-toggle", "mod+shift+m" }, #endif }; @@ -3104,6 +3104,44 @@ void App::loadFolder( const std::string& path ) { mSplitter->getCurWidget()->setFocus(); } +static std::string getDefaultShell() { + std::string shell = Sys::getEnv( "SHELL" ); + if ( !shell.empty() ) + return shell; +#if EE_PLATFORM == EE_PLATFORM_WIN + return "cmd"; +#elif EE_PLATFORM == EE_PLATFORM_MACOS + return "zsh"; +#else + return "bash"; +#endif +} + +static std::string getShellEnv( const std::string& env, const std::string& defShell = "" ) { + std::string shell = defShell.empty() ? Sys::which( getDefaultShell() ) : defShell; + Process process; + if ( process.create( shell, "-c env", Process::getDefaultOptions() ) ) { + size_t envLen = env.size(); + std::string buf( 32 * 1024, '\0' ); + process.readAllStdOut( buf ); + auto pathPos = buf.find( "\n" + env + "=" ); + bool startsWithPath = false; + if ( pathPos == std::string::npos && buf.substr( 0, envLen + 1 ) == env + "=" ) + startsWithPath = true; + if ( pathPos != std::string::npos || startsWithPath ) { + pathPos += startsWithPath ? envLen + 1 : envLen + 2; // Remove \n + env + "=" + auto endPathPos = buf.find_first_of( "\r\n", pathPos ); + if ( endPathPos != std::string::npos ) { + size_t len = endPathPos - pathPos; + return buf.substr( pathPos, len ); + } else { + return buf.substr( pathPos ); + } + } + } + return ""; +} + FontTrueType* App::loadFont( const std::string& name, std::string fontPath, const std::string& fallback ) { if ( FileSystem::isRelativePath( fontPath ) ) @@ -3190,7 +3228,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe winSettings.Icon = mResPath + winSettings.Icon; } -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS mConfig.context = engine->createContextSettings( &mConfig.ini, "window", true ); #else mConfig.context = engine->createContextSettings( &mConfig.ini, "window", false ); @@ -3219,8 +3257,29 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe return; } #endif -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS macOS_CreateApplicationMenus(); + + mThreadPool->run( [this]() { + // Checks if the default shell path contains more paths + // than the current environment, and adds them to ensure + // that the environment is more friendly for any new user + std::string path( Sys::getEnv( "PATH" ) ); + std::string shellPath( getShellEnv( "PATH", mConfig.term.shell ) ); + if ( String::hash( path ) != String::hash( shellPath ) ) { + auto pathSpl = String::split( path, ':' ); + auto shellPathSpl = String::split( shellPath, ':' ); + std::vector paths; + for ( auto& path : pathSpl ) + paths.emplace_back( std::move( path ) ); + for ( auto& shellPath : shellPathSpl ) { + if ( std::find( paths.begin(), paths.end(), shellPath ) == paths.end() ) + paths.emplace_back( std::move( shellPath ) ); + } + std::string newPath = String::join( paths, ':' ); + setenv( "PATH", newPath.c_str(), 1 ); + } + } ); #endif Log::info( "Window creation took: %.2f ms", globalClock.getElapsedTime().asMilliseconds() ); diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index fbdce6dc1..d1a1396a0 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -183,7 +183,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { Display* currentDisplay = displayManager->getDisplayIndex( 0 ); std::string resPath = Sys::getProcessPath(); -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS if ( String::contains( resPath, "ecode.app" ) ) { resPath = FileSystem::getCurrentWorkingDirectory(); FileSystem::dirAddSlashAtEnd( resPath ); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 520b4ae9c..d5b2e01f8 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -1221,7 +1221,7 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st [this]( auto* window ) -> bool { return onCloseRequestCallback( window ); } ); mResPath = Sys::getProcessPath(); -#if EE_PLATFORM == EE_PLATFORM_MACOSX +#if EE_PLATFORM == EE_PLATFORM_MACOS if ( String::contains( mResPath, "eepp-UIEditor.app" ) ) { mResPath = FileSystem::getCurrentWorkingDirectory(); FileSystem::dirAddSlashAtEnd( mResPath );