mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-26 23:10:38 +00:00
fix open in folder on macOS, avoid spawning the open command to open URLs (#17342)
* fix open in folder on macOS, avoid spawning the open command to open URLs * fix indent * goober alert * no more goober * fix compiler failing on linux
This commit is contained in:
parent
4d4881fcde
commit
f87bfda8d3
@ -13,6 +13,11 @@ extern "C" {
|
||||
|
||||
void initializeOSXExtras();
|
||||
|
||||
/* Yes it is awkward to put this here but I don't feel like making an entire file for 2 functions */
|
||||
/* Prefixing with `OSX` to avoid any possible header collisions in the future */
|
||||
void OSXShowInFinder(const char *path);
|
||||
void OSXOpenURL(const char *url);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -49,6 +49,16 @@ void initializeOSXExtras() {
|
||||
[[BarItemsManager sharedInstance] setupAppBarItems];
|
||||
}
|
||||
|
||||
void OSXShowInFinder(const char *path) {
|
||||
NSURL *url = [NSURL fileURLWithPath:@(path)];
|
||||
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[url]];
|
||||
}
|
||||
|
||||
void OSXOpenURL(const char *url) {
|
||||
NSURL *nsURL = [NSURL URLWithString:@(url)];
|
||||
[NSWorkspace.sharedWorkspace openURL:nsURL];
|
||||
}
|
||||
|
||||
@implementation BarItemsManager
|
||||
+ (instancetype)sharedInstance {
|
||||
static BarItemsManager *stub;
|
||||
|
@ -271,20 +271,18 @@ void System_ShowFileInFolder(const char *path) {
|
||||
SHOpenFolderAndSelectItems(pidl, 0, NULL, 0);
|
||||
CoTaskMemFree(pidl);
|
||||
}
|
||||
#elif PPSSPP_PLATFORM(MAC) || (PPSSPP_PLATFORM(LINUX) && !PPSSPP_PLATFORM(ANDROID))
|
||||
#elif PPSSPP_PLATFORM(MAC)
|
||||
OSXShowInFinder(path);
|
||||
#elif (PPSSPP_PLATFORM(LINUX) && !PPSSPP_PLATFORM(ANDROID))
|
||||
pid_t pid = fork();
|
||||
if (pid < 0)
|
||||
return;
|
||||
|
||||
if (pid == 0) {
|
||||
#if PPSSPP_PLATFORM(MAC)
|
||||
execlp("open", "open", path, nullptr);
|
||||
#else
|
||||
execlp("xdg-open", "xdg-open", path, nullptr);
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
#endif /* PPSSPP_PLATFORM(WINDOWS) */
|
||||
}
|
||||
|
||||
void System_LaunchUrl(LaunchUrlType urlType, const char *url) {
|
||||
@ -303,8 +301,7 @@ void System_LaunchUrl(LaunchUrlType urlType, const char *url) {
|
||||
std::wstring wurl = ConvertUTF8ToWString(url);
|
||||
ShellExecute(NULL, L"open", wurl.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
#elif defined(__APPLE__)
|
||||
std::string command = std::string("open ") + url;
|
||||
system(command.c_str());
|
||||
OSXOpenURL(url);
|
||||
#else
|
||||
std::string command = std::string("xdg-open ") + url;
|
||||
int err = system(command.c_str());
|
||||
@ -322,8 +319,8 @@ void System_LaunchUrl(LaunchUrlType urlType, const char *url) {
|
||||
std::wstring mailto = std::wstring(L"mailto:") + ConvertUTF8ToWString(url);
|
||||
ShellExecute(NULL, L"open", mailto.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
#elif defined(__APPLE__)
|
||||
std::string command = std::string("open mailto:") + url;
|
||||
system(command.c_str());
|
||||
std::string mailToURL = std::string("mailto:") + url;
|
||||
OSXOpenURL(mailToURL.c_str());
|
||||
#else
|
||||
std::string command = std::string("xdg-email ") + url;
|
||||
int err = system(command.c_str());
|
||||
|
Loading…
Reference in New Issue
Block a user