| 1 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
|
| 3 |
#include "macactivity.h" |
| 4 |
|
| 5 |
#include "common/log.h" |
| 6 |
|
| 7 |
#include <QString> |
| 8 |
|
| 9 |
#include <Cocoa/Cocoa.h> |
| 10 |
|
| 11 |
MacActivity::MacActivity(const QString &reason) |
| 12 |
: m_activity(0) |
| 13 |
{ |
| 14 |
const NSActivityOptions options = NSActivityBackground;; |
| 15 |
id act = [[NSProcessInfo processInfo] |
| 16 |
beginActivityWithOptions:options |
| 17 |
reason:reason.toNSString()]; |
| 18 |
if (act) { |
| 19 |
m_activity = reinterpret_cast<void*>(act); |
| 20 |
COPYQ_LOG_VERBOSE(QString("Started Background activity for: %1").arg(reason)); |
| 21 |
} else { |
| 22 |
::log("Failed to create activity", LogWarning); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
MacActivity::~MacActivity() { |
| 27 |
id act = reinterpret_cast<id>(m_activity); |
| 28 |
if (act) { |
| 29 |
[[NSProcessInfo processInfo] endActivity:act]; |
| 30 |
COPYQ_LOG_VERBOSE("Ended activity"); |
| 31 |
} else { |
| 32 |
::log("Failed to stop activity", LogWarning); |
| 33 |
} |
| 34 |
} |