mirror of https://github.com/procxx/kepka.git
Fix crash in macOS notifications manager init.
Regression was introduced in 1725927aea
.
Also create the thread only when it is first needed.
This commit is contained in:
parent
4e5c4a462b
commit
c10dee11e8
|
@ -214,8 +214,7 @@ private:
|
||||||
Manager::Private::Private(Manager *manager)
|
Manager::Private::Private(Manager *manager)
|
||||||
: _managerId(rand_value<uint64>())
|
: _managerId(rand_value<uint64>())
|
||||||
, _managerIdString(QString::number(_managerId))
|
, _managerIdString(QString::number(_managerId))
|
||||||
, _delegate([[NotificationDelegate alloc] initWithManager:manager managerId:_managerId])
|
, _delegate([[NotificationDelegate alloc] initWithManager:manager managerId:_managerId]) {
|
||||||
, _clearingThread([this] { clearingThreadLoop(); }) {
|
|
||||||
updateDelegate();
|
updateDelegate();
|
||||||
subscribe(Global::RefWorkMode(), [this](DBIWorkMode mode) {
|
subscribe(Global::RefWorkMode(), [this](DBIWorkMode mode) {
|
||||||
// We need to update the delegate _after_ the tray icon change was done in Qt.
|
// We need to update the delegate _after_ the tray icon change was done in Qt.
|
||||||
|
@ -309,6 +308,10 @@ void Manager::Private::clearingThreadLoop() {
|
||||||
|
|
||||||
template <typename Task>
|
template <typename Task>
|
||||||
void Manager::Private::putClearTask(Task task) {
|
void Manager::Private::putClearTask(Task task) {
|
||||||
|
if (!_clearingThread.joinable()) {
|
||||||
|
_clearingThread = std::thread([this] { clearingThreadLoop(); });
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(_clearingMutex);
|
std::unique_lock<std::mutex> lock(_clearingMutex);
|
||||||
_clearingTasks.push_back(task);
|
_clearingTasks.push_back(task);
|
||||||
_clearingCondition.notify_one();
|
_clearingCondition.notify_one();
|
||||||
|
@ -328,8 +331,10 @@ void Manager::Private::updateDelegate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::Private::~Private() {
|
Manager::Private::~Private() {
|
||||||
putClearTask(ClearFinish());
|
if (_clearingThread.joinable()) {
|
||||||
_clearingThread.join();
|
putClearTask(ClearFinish());
|
||||||
|
_clearingThread.join();
|
||||||
|
}
|
||||||
[_delegate release];
|
[_delegate release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue