Skip to content

Commit

Permalink
OSX: Omit preventing system entering sleep mode
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Holecek <[email protected]>
  • Loading branch information
hluk committed Jan 28, 2020
1 parent f0efa3f commit 9955cc4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
8 changes: 1 addition & 7 deletions src/platform/mac/macactivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ class QString;
class MacActivity
{
public:
enum ActivityType {
User,
Background
};

public:
MacActivity(ActivityType type, const QString &reason);
explicit MacActivity(const QString &reason);
~MacActivity();
private:
void *m_activity;
Expand Down
17 changes: 4 additions & 13 deletions src/platform/mac/macactivity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,16 @@

#include <Cocoa/Cocoa.h>

MacActivity::MacActivity(ActivityType type, const QString &reason) :
m_activity(0)
MacActivity::MacActivity(const QString &reason)
: m_activity(0)
{
NSActivityOptions options = NSActivityBackground;;
switch (type) {
case User:
options = NSActivityUserInitiated;
break;
case Background:
options = NSActivityBackground;
break;
}

const NSActivityOptions options = NSActivityBackground;;
id act = [[NSProcessInfo processInfo]
beginActivityWithOptions:options
reason:reason.toNSString()];
if (act) {
m_activity = reinterpret_cast<void*>(act);
::log(QString("Started %1 activity for: %2").arg(type == User ? "User": "Background").arg(reason), LogNote);
::log(QString("Started Background activity for: %1").arg(reason), LogNote);
} else {
::log("Failed to create activity", LogWarning);
}
Expand Down
14 changes: 7 additions & 7 deletions src/platform/mac/macplatform.mm
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ QString absoluteResourcesePath(const QString &path)
, public ApplicationExceptionHandler<QtApplication>
{
public:
Activity(int &argc, char **argv, ActivityType type, const QString &reason)
: MacActivity(type, reason)
Activity(int &argc, char **argv, const QString &reason)
: MacActivity(reason)
, ApplicationExceptionHandler<QtApplication>(argc, argv)
{
[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
Expand All @@ -178,7 +178,7 @@ QString absoluteResourcesePath(const QString &path)

QApplication *MacPlatform::createServerApplication(int &argc, char **argv)
{
QApplication *app = new Activity<ClipboardApplication>(argc, argv, MacActivity::Background, "CopyQ Server");
QApplication *app = new Activity<ClipboardApplication>(argc, argv, "CopyQ Server");

// Switch the app to foreground when in foreground
ForegroundBackgroundFilter::installFilter(app);
Expand All @@ -188,22 +188,22 @@ QString absoluteResourcesePath(const QString &path)

QGuiApplication *MacPlatform::createMonitorApplication(int &argc, char **argv)
{
return new Activity<ClipboardApplication>(argc, argv, MacActivity::Background, "CopyQ clipboard monitor");
return new Activity<ClipboardApplication>(argc, argv, "CopyQ clipboard monitor");
}

QGuiApplication *MacPlatform::createClipboardProviderApplication(int &argc, char **argv)
{
return new Activity<ClipboardApplication>(argc, argv, MacActivity::Background, "CopyQ clipboard provider");
return new Activity<ClipboardApplication>(argc, argv, "CopyQ clipboard provider");
}

QCoreApplication *MacPlatform::createClientApplication(int &argc, char **argv)
{
return new Activity<QCoreApplication>(argc, argv, MacActivity::User, "CopyQ Client");
return new Activity<QCoreApplication>(argc, argv, "CopyQ Client");
}

QGuiApplication *MacPlatform::createTestApplication(int &argc, char **argv)
{
return new Activity<QGuiApplication>(argc, argv, MacActivity::Background, "CopyQ Tests");
return new Activity<QGuiApplication>(argc, argv, "CopyQ Tests");
}

PlatformClipboardPtr MacPlatform::clipboard()
Expand Down

0 comments on commit 9955cc4

Please sign in to comment.