Skip to content

Commit

Permalink
Stop the camera when the app looses focus, not when the window does
Browse files Browse the repository at this point in the history
Closes: #871
  • Loading branch information
rgriebl committed Apr 29, 2024
1 parent 96313e0 commit 08e9f53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/desktop/itemscannerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QMediaDevices>
#include <QCameraDevice>
#include <QQmlApplicationEngine>
#include <QGuiApplication>

#include "bricklink/core.h"
#include "bricklink/item.h"
Expand Down Expand Up @@ -176,6 +177,16 @@ ItemScannerDialog::ItemScannerDialog(QWidget *parent)
if (!m_pinWindow->isChecked())
accept();
});

connect(qApp, &QGuiApplication::applicationStateChanged,
this, [this](Qt::ApplicationState state) {
if (m_selectCamera->currentIndex() != -1) {
auto activeState = (state == Qt::ApplicationActive)
? Scanner::Capture::ActiveState::Active
: Scanner::Capture::ActiveState::SoonInactive;
m_capture->setVideoOutputActiveState(activeState);
}
});
}

ItemScannerDialog::~ItemScannerDialog()
Expand Down Expand Up @@ -244,13 +255,8 @@ void ItemScannerDialog::updateItemTypeFilters()

void ItemScannerDialog::changeEvent(QEvent *e)
{
if ((e->type() == QEvent::ActivationChange) && (m_selectCamera->currentIndex() != -1)) {
auto activeState = isActiveWindow() ? Scanner::Capture::ActiveState::Active
: Scanner::Capture::ActiveState::SoonInactive;
m_capture->setVideoOutputActiveState(activeState);
} else if (e->type() == QEvent::LanguageChange) {
if (e->type() == QEvent::LanguageChange)
languageChange();
}
QDialog::changeEvent(e);
}

Expand Down
2 changes: 1 addition & 1 deletion src/scanner/capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Capture::Capture(QObject *parent)
setState(State::Idle);
});

d->cameraStopTimer.setInterval(10s);
d->cameraStopTimer.setInterval(5s);
d->cameraStopTimer.setSingleShot(true);
connect(&d->cameraStopTimer, &QTimer::timeout, this, [this]() {
if (state() == State::SoonInactive)
Expand Down

0 comments on commit 08e9f53

Please sign in to comment.