Hide "QR-code" button from config import menu for Android devices without camera

This commit is contained in:
albexk 2024-01-20 18:16:45 +03:00
parent 3e02dfef63
commit 2b61c48303
6 changed files with 25 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import android.content.Intent
import android.content.Intent.EXTRA_MIME_TYPES
import android.content.Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
import android.content.ServiceConnection
import android.content.pm.PackageManager
import android.net.Uri
import android.net.VpnService
import android.os.Bundle
@ -418,6 +419,9 @@ class AmneziaActivity : QtActivity() {
Log.v(TAG, "Set notification text")
}
@Suppress("unused")
fun isCameraPresent(): Boolean = applicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)
@Suppress("unused")
fun startQrCodeReader() {
Log.v(TAG, "Start camera")

View file

@ -191,6 +191,11 @@ void AndroidController::setNotificationText(const QString &title, const QString
(jint) timerSec);
}
bool AndroidController::isCameraPresent()
{
return callActivityMethod<jboolean>("isCameraPresent", "()Z");
}
void AndroidController::startQrReaderActivity()
{
callActivityMethod("startQrCodeReader", "()V");

View file

@ -33,6 +33,7 @@ public:
void setNotificationText(const QString &title, const QString &message, int timerSec);
void saveFile(const QString &fileName, const QString &data);
QString openFile(const QString &filter);
bool isCameraPresent();
void startQrReaderActivity();
void setSaveLogs(bool enabled);
void exportLogsFile(const QString &fileName);

View file

@ -206,3 +206,14 @@ void SettingsController::toggleScreenshotsEnabled(bool enable)
});
#endif
}
bool SettingsController::isCameraPresent()
{
#if defined Q_OS_IOS
return true;
#elif defined Q_OS_ANDROID
return AndroidController::instance()->isCameraPresent();
#else
return false;
#endif
}

View file

@ -59,6 +59,8 @@ public slots:
bool isScreenshotsEnabled();
void toggleScreenshotsEnabled(bool enable);
bool isCameraPresent();
signals:
void primaryDnsChanged();
void secondaryDnsChanged();

View file

@ -90,7 +90,7 @@ It's okay as long as it's from someone you trust.")
LabelWithButtonType {
Layout.fillWidth: true
visible: GC.isMobile()
visible: SettingsController.isCameraPresent()
text: qsTr("QR-code")
rightImageSource: "qrc:/images/controls/chevron-right.svg"
@ -105,7 +105,7 @@ It's okay as long as it's from someone you trust.")
}
DividerType {
visible: GC.isMobile()
visible: SettingsController.isCameraPresent()
}
LabelWithButtonType {