blob: cd47ff50984d22ab4512fa58cb02aa204afd84e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// Copyright 2005-2019 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include "mumble_pch.hpp"
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
static bool appNapSuppressed = false;
#endif
void MUSuppressAppNap(bool suppress) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
if (![processInfo respondsToSelector:@selector(disableAutomaticTermination:)]) {
return;
}
if (suppress == appNapSuppressed) {
qWarning("AppNap: attempt to set AppNap suppression state to %s while already in that state.", suppress ? "true" : "false");
return;
}
QString translatedReason = QApplication::tr("Mumble is currently connected to a server");
NSString *reason = const_cast<NSString *>(reinterpret_cast<const NSString *>(CFStringCreateWithCharacters(kCFAllocatorDefault, reinterpret_cast<const UniChar *>(translatedReason.unicode()), translatedReason.length())));
if (suppress) {
[[NSProcessInfo processInfo] disableAutomaticTermination:reason];
qWarning("AppNap: suppressed with reason: '%s'", qPrintable(translatedReason));
} else {
[[NSProcessInfo processInfo] enableAutomaticTermination:reason];
qWarning("AppNap: re-enabled, was suppressed with reason: '%s'", qPrintable(translatedReason));
}
appNapSuppressed = suppress;
[reason release];
#else
Q_UNUSED(suppress);
#endif
}
|