mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04: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
3 changed files with 22 additions and 10 deletions
|
@ -13,6 +13,11 @@ extern "C" {
|
||||||
|
|
||||||
void initializeOSXExtras();
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -49,6 +49,16 @@ void initializeOSXExtras() {
|
||||||
[[BarItemsManager sharedInstance] setupAppBarItems];
|
[[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
|
@implementation BarItemsManager
|
||||||
+ (instancetype)sharedInstance {
|
+ (instancetype)sharedInstance {
|
||||||
static BarItemsManager *stub;
|
static BarItemsManager *stub;
|
||||||
|
|
|
@ -271,20 +271,18 @@ void System_ShowFileInFolder(const char *path) {
|
||||||
SHOpenFolderAndSelectItems(pidl, 0, NULL, 0);
|
SHOpenFolderAndSelectItems(pidl, 0, NULL, 0);
|
||||||
CoTaskMemFree(pidl);
|
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();
|
pid_t pid = fork();
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
#if PPSSPP_PLATFORM(MAC)
|
|
||||||
execlp("open", "open", path, nullptr);
|
|
||||||
#else
|
|
||||||
execlp("xdg-open", "xdg-open", path, nullptr);
|
execlp("xdg-open", "xdg-open", path, nullptr);
|
||||||
#endif
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* PPSSPP_PLATFORM(WINDOWS) */
|
||||||
}
|
}
|
||||||
|
|
||||||
void System_LaunchUrl(LaunchUrlType urlType, const char *url) {
|
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);
|
std::wstring wurl = ConvertUTF8ToWString(url);
|
||||||
ShellExecute(NULL, L"open", wurl.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
ShellExecute(NULL, L"open", wurl.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
std::string command = std::string("open ") + url;
|
OSXOpenURL(url);
|
||||||
system(command.c_str());
|
|
||||||
#else
|
#else
|
||||||
std::string command = std::string("xdg-open ") + url;
|
std::string command = std::string("xdg-open ") + url;
|
||||||
int err = system(command.c_str());
|
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);
|
std::wstring mailto = std::wstring(L"mailto:") + ConvertUTF8ToWString(url);
|
||||||
ShellExecute(NULL, L"open", mailto.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
ShellExecute(NULL, L"open", mailto.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
std::string command = std::string("open mailto:") + url;
|
std::string mailToURL = std::string("mailto:") + url;
|
||||||
system(command.c_str());
|
OSXOpenURL(mailToURL.c_str());
|
||||||
#else
|
#else
|
||||||
std::string command = std::string("xdg-email ") + url;
|
std::string command = std::string("xdg-email ") + url;
|
||||||
int err = system(command.c_str());
|
int err = system(command.c_str());
|
||||||
|
|
Loading…
Add table
Reference in a new issue