21 #if defined(_X11) || defined(__APPLE__)
33 #define WIN32_LEAN_AND_MEAN
38 #elif defined(__ANDROID__)
39 #include <SDL2/SDL_system.h>
45 #define ERR_DU LOG_STREAM(err, log_desktop)
46 #define LOG_DU LOG_STREAM(info, log_desktop)
50 bool open_object([[maybe_unused]]
const std::string& path_or_url)
52 LOG_DU <<
"open_object(): requested object: " << path_or_url;
54 #if defined(_X11) || defined(__APPLE__)
57 LOG_DU <<
"open_object(): on X11, will use xdg-open";
58 const char launcher[] =
"xdg-open";
60 LOG_DU <<
"open_object(): on OS X, will use open";
61 const char launcher[] =
"open";
64 const pid_t child = fork();
67 ERR_DU <<
"open_object(): fork() failed";
69 }
else if(child == 0) {
70 execlp(launcher, launcher, path_or_url.c_str(),
nullptr);
74 std::thread
t { [child](){
int status; waitpid(child, &status, 0); } };
81 LOG_DU <<
"open_object(): on Win32, will use ShellExecute()";
83 std::wstring u16path = unicode_cast<std::wstring>(path_or_url);
85 const ptrdiff_t res =
reinterpret_cast<ptrdiff_t
>(ShellExecute(
nullptr, L
"open", u16path.c_str(),
nullptr,
nullptr, SW_SHOW));
87 ERR_DU <<
"open_object(): ShellExecute() failed (" << res <<
")";
93 #elif defined(__ANDROID__)
94 LOG_DU <<
"open_object(): on Android, will use Intent.GET_ACTION_VIEW with path as extra data. URL: " << path_or_url;
96 JNIEnv* env =
reinterpret_cast<JNIEnv*
>(SDL_AndroidGetJNIEnv());
97 jobject wesnoth_instance =
reinterpret_cast<jobject
>(SDL_AndroidGetActivity());
98 jclass wesnoth_activity(env->GetObjectClass(wesnoth_instance));
99 jmethodID open = env->GetMethodID(wesnoth_activity,
"open",
"(Ljava/lang/String;)V");
100 env->CallVoidMethod(wesnoth_instance, open, env->NewStringUTF(path_or_url.c_str()));
102 if(env->ExceptionCheck() == JNI_TRUE) {
103 env->ExceptionDescribe();
104 env->ExceptionClear();
107 env->DeleteLocalRef(wesnoth_instance);
108 env->DeleteLocalRef(wesnoth_activity);
113 ERR_DU <<
"open_object(): unsupported platform";
Standard logging facilities (interface).
bool open_object([[maybe_unused]] const std::string &path_or_url)
static lg::log_domain log_desktop("desktop")
Desktop environment interaction functions.