From 82a22b2a87c3ff4c58d85c65901add1116ee2670 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 28 Feb 2023 18:49:32 +0100 Subject: [PATCH] Add vscode detection on macOS --- .../CodeEditors/VisualStudioCodeEditor.cpp | 30 +++++++++++++++++++ Source/Engine/Platform/Mac/MacPlatform.cpp | 28 +++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Scripting/CodeEditors/VisualStudioCodeEditor.cpp b/Source/Editor/Scripting/CodeEditors/VisualStudioCodeEditor.cpp index 435673abd..1ea5bb59f 100644 --- a/Source/Editor/Scripting/CodeEditors/VisualStudioCodeEditor.cpp +++ b/Source/Editor/Scripting/CodeEditors/VisualStudioCodeEditor.cpp @@ -10,6 +10,9 @@ #include "Engine/Platform/Win32/IncludeWindowsHeaders.h" #if PLATFORM_LINUX #include +#elif PLATFORM_MAC +#include "Engine/Platform/Mac/MacUtils.h" +#include #endif VisualStudioCodeEditor::VisualStudioCodeEditor(const String& execPath, const bool isInsiders) @@ -80,6 +83,33 @@ void VisualStudioCodeEditor::FindEditors(Array* output) return; } } +#elif PLATFORM_MAC + // System installed app + NSURL* AppURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:@"com.microsoft.VSCode"]; + if (AppURL != nullptr) + { + const String path = MacUtils::ToString((CFStringRef)[AppURL path]); + output->Add(New(path, false)); + return; + } + + // Predefined locations + String userFolder; + FileSystem::GetSpecialFolderPath(SpecialFolder::Documents, userFolder); + String paths[3] = + { + TEXT("/Applications/Visual Studio Code.app"), + userFolder + TEXT("/../Visual Studio Code.app"), + userFolder + TEXT("/../Downloads/Visual Studio Code.app"), + }; + for (const String& path : paths) + { + if (FileSystem::DirectoryExists(path)) + { + output->Add(New(path, false)); + break; + } + } #endif } diff --git a/Source/Engine/Platform/Mac/MacPlatform.cpp b/Source/Engine/Platform/Mac/MacPlatform.cpp index 61588c5a1..ab0efedac 100644 --- a/Source/Engine/Platform/Mac/MacPlatform.cpp +++ b/Source/Engine/Platform/Mac/MacPlatform.cpp @@ -699,8 +699,32 @@ int32 MacProcess(const StringView& cmdLine, const StringView& workingDir, const int32 MacPlatform::StartProcess(const StringView& filename, const StringView& args, const StringView& workingDir, bool hiddenWindow, bool waitForEnd) { // hiddenWindow has hardly any meaning on UNIX/Linux/OSX as the program that is called decides whether it has a GUI or not - String cmdLine(filename); - if (args.HasChars()) cmdLine = cmdLine + TEXT(" ") + args; + + // Special case if filename points to the app package (use actual executable) + String exePath = filename; + { + NSString* processPath = (NSString*)MacUtils::ToString(filename); + if (![[NSFileManager defaultManager] fileExistsAtPath: processPath]) + { + NSString* appName = [[processPath lastPathComponent] stringByDeletingPathExtension]; + processPath = [[NSWorkspace sharedWorkspace] fullPathForApplication:appName]; + } + if ([[NSFileManager defaultManager] fileExistsAtPath: processPath]) + { + if([[NSWorkspace sharedWorkspace] isFilePackageAtPath: processPath]) + { + NSBundle* bundle = [NSBundle bundleWithPath:processPath]; + if (bundle != nil) + { + processPath = [bundle executablePath]; + if (processPath != nil) + exePath = MacUtils::ToString((CFStringRef)processPath); + } + } + } + } + + String cmdLine = String::Format(TEXT("\"{0}\" {1}"), exePath, args); return MacProcess(cmdLine, workingDir, Dictionary(), waitForEnd, false); }