Skip to content

Commit

Permalink
Disable app nap on macOS, second try.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Karlsson authored and dotarmin committed Jun 25, 2020
1 parent baf7cb0 commit ae936e0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
2 changes: 0 additions & 2 deletions deploy/macx/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>NSAppSleepDisabled</key>
<true/>
<key>CFBundleIconFile</key>
<string>CasparCG.icns</string>
<key>CFBundlePackageType</key>
Expand Down
13 changes: 13 additions & 0 deletions src/Shell/Mac/AppNap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#import <objc/objc.h>

class AppNap
{
public:
explicit AppNap();
~AppNap();

private:
id activity;
};
16 changes: 16 additions & 0 deletions src/Shell/Mac/AppNap.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "AppNap.h"

#include <Foundation/Foundation.h>

AppNap::AppNap()
{
activity = [[NSProcessInfo processInfo] beginActivityWithOptions:NSActivityLatencyCritical | NSActivityUserInitiated
reason:@"Disable App Nap"];
[this->activity retain];
}

AppNap::~AppNap()
{
[[NSProcessInfo processInfo] endActivity:this->activity];
[this->activity release];
}
8 changes: 8 additions & 0 deletions src/Shell/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include "../Widgets/MainWindow.h"

#ifdef Q_OS_MAC
#include "Mac/AppNap.h"
#endif

#include <QtCore/QRegExp>
#include <QtCore/QDir>
#include <QtCore/QFile>
Expand Down Expand Up @@ -246,6 +250,10 @@ CommandLineParseResult parseCommandLine(QCommandLineParser& parser, CommandLineA

int main(int argc, char* argv[])
{
#ifdef Q_OS_MAC
AppNap appNap;
#endif

qInstallMessageHandler(messageHandler);

QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Expand Down
8 changes: 7 additions & 1 deletion src/Shell/Shell.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ TARGET = shell
TEMPLATE = app

HEADERS += \
Application.h
Application.h \
Mac/AppNap.h

SOURCES += \
Main.cpp \
Application.cpp

OBJECTIVE_SOURCES += \
Mac/AppNap.mm

FORMS += \
RESOURCES += \
Expand All @@ -41,6 +45,8 @@ OTHER_FILES += \
win32:RC_FILE = Windows.rc
else:macx:ICON = Images/CasparCG.icns

macx:LIBS += -framework Foundation

CONFIG(system-libqatemcontrol) {
LIBS += -lqatemcontrol
} else {
Expand Down

0 comments on commit ae936e0

Please sign in to comment.