Opt out of AppNap while progress bars are active

This commit is contained in:
Thomas Goyne 2013-10-01 16:27:33 -07:00
parent 9a21c13cbe
commit 91c31f646e
4 changed files with 38 additions and 6 deletions

View file

@ -17,6 +17,7 @@
#include "../config.h" #include "../config.h"
#include "libaegisub/util.h" #include "libaegisub/util.h"
#include "libaegisub/util_osx.h"
#include "libaegisub/exception.h" #include "libaegisub/exception.h"
@ -132,4 +133,12 @@ std::pair<size_t, size_t> ifind(std::string const& haystack, std::string const&
return ret; return ret;
} }
} } }
#ifndef __APPLE__
namespace osx {
AppNapDisabler::AppNapDisabler(std::string const& reason) { }
AppNapDisabler::~AppNapDisabler() { }
}
#endif
}

View file

@ -28,11 +28,17 @@
/// When linking with this library, be sure to add '-framework CoreFoundation' /// When linking with this library, be sure to add '-framework CoreFoundation'
/// to the GCC commandline. /// to the GCC commandline.
#ifdef __APPLE__
#include <string> #include <string>
namespace agi { namespace agi {
namespace osx {
class AppNapDisabler {
void *handle;
public:
AppNapDisabler(std::string const& reason);
~AppNapDisabler();
};
}
namespace util { namespace util {
/// @brief Get the full name of bundle. /// @brief Get the full name of bundle.
/// @return Full name of bundle. /// @return Full name of bundle.
@ -91,7 +97,5 @@ std::string OSX_GetBundleAuxillaryExecutablePath(std::string const& executableNa
/// @param location URI of file /// @param location URI of file
/// @note If this is a FILE or DIRECTORY the path must be ABSOLUTE no 'file://' /// @note If this is a FILE or DIRECTORY the path must be ABSOLUTE no 'file://'
void OSX_OpenLocation(std::string const& location); void OSX_OpenLocation(std::string const& location);
} // namespace io } // namespace util
} // namespace agi } // namespace agi
#endif

View file

@ -28,6 +28,22 @@ static std::string EmptyIfNil(NSString *string) {
} }
namespace agi { namespace agi {
namespace osx {
AppNapDisabler::AppNapDisabler(std::string const& reason) : handle(nullptr) {
auto processInfo = [NSProcessInfo processInfo];
if ([processInfo respondsToSelector:@selector(beginActivityWithOptions:reason:)])
handle = [[processInfo beginActivityWithOptions:NSActivityUserInitiatedAllowingIdleSystemSleep
reason:[NSString stringWithUTF8String:reason.c_str()]]
retain];
}
AppNapDisabler::~AppNapDisabler() {
auto processInfo = [NSProcessInfo processInfo];
if (handle && [processInfo respondsToSelector:@selector(endActivity:)])
[processInfo endActivity:(id)handle];
[(id)handle release];
}
}
namespace util { namespace util {
std::string OSX_GetBundlePath() { std::string OSX_GetBundlePath() {

View file

@ -26,6 +26,7 @@
#include <libaegisub/dispatch.h> #include <libaegisub/dispatch.h>
#include <libaegisub/exception.h> #include <libaegisub/exception.h>
#include <libaegisub/util_osx.h>
#include <atomic> #include <atomic>
#include <wx/button.h> #include <wx/button.h>
@ -115,7 +116,9 @@ void DialogProgress::Run(std::function<void(agi::ProgressSink*)> task, int prior
DialogProgressSink ps(this); DialogProgressSink ps(this);
this->ps = &ps; this->ps = &ps;
auto current_title = from_wx(title->GetLabelText());
agi::dispatch::Background().Async([=]{ agi::dispatch::Background().Async([=]{
agi::osx::AppNapDisabler app_nap_disabler(current_title);
try { try {
task(this->ps); task(this->ps);
} }