Skip to content

Commit

Permalink
Update shared utils
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Apr 15, 2024
1 parent f51023c commit 3ed1451
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 166 deletions.
13 changes: 6 additions & 7 deletions src/NotificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ class NotificationManager : public QObject
Q_OBJECT

Q_PROPERTY(QString notification READ getNotification WRITE setNotificationShort NOTIFY notificationChanged)

Q_PROPERTY(bool permissionOS READ hasPermissionOS NOTIFY permissionsChanged)

static NotificationManager *instance;

NotificationManager();
~NotificationManager();

QString m_title;
QString m_message;
int m_channel = 0;
Expand All @@ -59,12 +53,17 @@ class NotificationManager : public QObject
UtilsIOSNotifications m_iosnotifier;
#endif

// Singleton
static NotificationManager *instance;
NotificationManager();
~NotificationManager();

private slots:
void updateNotificationAndroid();
void updateNotificationIOS();
void updateNotificationDesktop();

signals:
Q_SIGNALS:
void notificationChanged();
void permissionsChanged();

Expand Down
52 changes: 36 additions & 16 deletions src/thirdparty/AppUtils/AppUtils.pri
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

# Optional stuff (for macOS)
#CONFIG += UTILS_DOCK_ENABLED

# Optional stuff (for iOS)
#CONFIG += UTILS_NOTIFICATIONS_ENABLED
#CONFIG += UTILS_WIFI_ENABLED

# Generic utils
SOURCES += $${PWD}/utils_app.cpp \
$${PWD}/utils_bits.cpp \
Expand All @@ -7,7 +14,8 @@ SOURCES += $${PWD}/utils_app.cpp \
$${PWD}/utils_log.cpp \
$${PWD}/utils_maths.cpp \
$${PWD}/utils_screen.cpp \
$${PWD}/utils_sysinfo.cpp
$${PWD}/utils_sysinfo.cpp \
$${PWD}/utils_wifi.cpp

HEADERS += $${PWD}/utils_app.h \
$${PWD}/utils_bits.h \
Expand All @@ -17,13 +25,13 @@ HEADERS += $${PWD}/utils_app.h \
$${PWD}/utils_maths.h \
$${PWD}/utils_screen.h \
$${PWD}/utils_sysinfo.h \
$${PWD}/utils_versionchecker.h
$${PWD}/utils_versionchecker.h \
$${PWD}/utils_wifi.h

INCLUDEPATH += $${PWD}

versionAtLeast(QT_VERSION, 6.6) {
# RHI info
QT += gui-private
QT += gui-private # to get RHI info
}

# Linux OS utils
Expand All @@ -40,20 +48,26 @@ macx {
SOURCES += $${PWD}/utils_os_macos.mm
HEADERS += $${PWD}/utils_os_macos.h

# macOS dock click handler
LIBS += -framework AppKit
SOURCES += $${PWD}/utils_os_macos_dock.mm
HEADERS += $${PWD}/utils_os_macos_dock.h
# macOS dock click handler (optional)
UTILS_DOCK_ENABLED {
DEFINES += UTILS_DOCK_ENABLED
LIBS += -framework AppKit
SOURCES += $${PWD}/utils_os_macos_dock.mm
HEADERS += $${PWD}/utils_os_macos_dock.h
}
}

# Windows OS utils
win32 {
DEFINES += _USE_MATH_DEFINES
SOURCES += $${PWD}/utils_os_windows.cpp
HEADERS += $${PWD}/utils_os_windows.h
}

# Android OS utils
android {
DEFINES += UTILS_NOTIFICATIONS_ENABLED UTILS_WIFI_ENABLED

versionAtLeast(QT_VERSION, 6.0) {
QT += core-private

Expand All @@ -69,17 +83,23 @@ android {

# iOS utils
ios {
QT += quick

LIBS += -framework UIKit
SOURCES += $${PWD}/utils_os_ios.mm
HEADERS += $${PWD}/utils_os_ios.h

# iOS notifications
LIBS += -framework UserNotifications
SOURCES += $${PWD}/utils_os_ios_notif.mm
HEADERS += $${PWD}/utils_os_ios_notif.h
# iOS notifications (optional)
UTILS_NOTIFICATIONS_ENABLED {
DEFINES += UTILS_NOTIFICATIONS_ENABLED
LIBS += -framework UserNotifications
SOURCES += $${PWD}/utils_os_ios_notif.mm
HEADERS += $${PWD}/utils_os_ios_notif.h
}

# iOS WiFi SSID
#LIBS += -framework SystemConfiguration
# iOS WiFi SSID (optional)
UTILS_WIFI_ENABLED {
DEFINES += UTILS_WIFI_ENABLED
LIBS += -framework SystemConfiguration
SOURCES += $${PWD}/utils_os_ios_wifi.mm
HEADERS += $${PWD}/utils_os_ios_wifi.h
}
}
48 changes: 33 additions & 15 deletions src/thirdparty/AppUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)

#set(UTILS_DOCK_ENABLED true)
#set(UTILS_WIFI_ENABLED true)
#set(UTILS_NOTIFICATIONS_ENABLED true)

################################################################################

if(NOT QT_DEFAULT_MAJOR_VERSION)
Expand All @@ -19,7 +23,7 @@ find_package(Qt${QT_DEFAULT_MAJOR_VERSION} REQUIRED COMPONENTS ${CORE_COMPONENTS
set(CORE_LIBRARIES
Qt::Core
Qt::Gui
Qt::GuiPrivate
Qt::GuiPrivate # to get RHI infos
Qt::Qml
Qt::Quick
)
Expand All @@ -42,6 +46,8 @@ set(CORE_SOURCES
utils_screen.h
utils_sysinfo.cpp
utils_sysinfo.h
utils_wifi.cpp
utils_wifi.h
utils_versionchecker.h)

# OS specific sources & dependencies
Expand Down Expand Up @@ -82,26 +88,38 @@ endif()
if(APPLE AND NOT IOS)
set(PLATFORM_SOURCES
utils_os_macos.mm
utils_os_macos.h
utils_os_macos_dock.mm
utils_os_macos_dock.h)

set(PLATFORM_LIBRARIES "-framework AppKit" m)
utils_os_macos.h)

if(UTILS_DOCK_ENABLED)
set(PLATFORM_SOURCES ${PLATFORM_SOURCES}
utils_os_macos_dock.mm
utils_os_macos_dock.h)
set(PLATFORM_LIBRARIES "-framework AppKit" m) # dock control
endif()
endif()

if(IOS)
set(PLATFORM_SOURCES
utils_os_ios.mm
utils_os_ios.h
utils_os_ios_notif.mm
utils_os_ios_notif.h)

find_package(Qt${QT_DEFAULT_MAJOR_VERSION} REQUIRED COMPONENTS Quick)
set(PLATFORM_LIBRARIES Qt::Quick)
set(PLATFORM_LIBRARIES Qt::GuiPrivate)
set(PLATFORM_LIBRARIES "-framework UIKit" m)
set(PLATFORM_LIBRARIES "-framework UserNotifications" m) # show notifications
#set(PLATFORM_LIBRARIES "-framework SystemConfiguration" m) # get WiFi SSID

set(PLATFORM_SOURCES
utils_os_ios.mm
utils_os_ios.h)

if(UTILS_NOTIFICATIONS_ENABLED)
set(PLATFORM_SOURCES ${PLATFORM_SOURCES}
utils_os_ios_notif.mm
utils_os_ios_notif.h)
set(PLATFORM_LIBRARIES "-framework UserNotifications" m) # show notifications
endif()

if(UTILS_WIFI_ENABLED)
set(PLATFORM_SOURCES ${PLATFORM_SOURCES}
utils_os_ios_wifi.mm
utils_os_ios_wifi.h)
set(PLATFORM_LIBRARIES "-framework SystemConfiguration" m) # get WiFi SSID
endif()
endif()

################################################################################
Expand Down
29 changes: 7 additions & 22 deletions src/thirdparty/AppUtils/utils_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "utils_os_android.h"
#elif defined(Q_OS_IOS)
#include "utils_os_ios.h"
#if defined(UTILS_NOTIFICATIONS_ENABLED)
#include "utils_os_ios_notif.h"
#endif
#endif

#include <QDir>
Expand Down Expand Up @@ -342,24 +345,6 @@ void UtilsApp::vibrate(int ms)

/* ************************************************************************** */

QString UtilsApp::getMobileWifiSSID()
{
getMobileLocationPermission();

if (checkMobileLocationPermission())
{
#if defined(Q_OS_ANDROID)
return UtilsAndroid::getWifiSSID();
#elif defined(Q_OS_IOS)
return UtilsIOS::getWifiSSID();
#endif
}

return QString();
}

/* ************************************************************************** */

int UtilsApp::getAndroidSdkVersion()
{
#if defined(Q_OS_ANDROID)
Expand Down Expand Up @@ -616,8 +601,8 @@ bool UtilsApp::checkMobileNotificationPermission()
{
#if defined(Q_OS_ANDROID)
return UtilsAndroid::checkPermission_notification();
#elif defined(Q_OS_IOS)
return UtilsIOS::checkPermission_notification();
#elif defined(Q_OS_IOS) && defined(UTILS_NOTIFICATIONS_ENABLED)
return UtilsIOSNotifications::checkPermission_notification();
#endif

return true;
Expand All @@ -627,8 +612,8 @@ bool UtilsApp::getMobileNotificationPermission()
{
#if defined(Q_OS_ANDROID)
return UtilsAndroid::getPermission_notification();
#elif defined(Q_OS_IOS)
return UtilsIOS::getPermission_notification();
#elif defined(Q_OS_IOS) && defined(UTILS_NOTIFICATIONS_ENABLED)
return UtilsIOSNotifications::getPermission_notification();
#endif

return true;
Expand Down
2 changes: 0 additions & 2 deletions src/thirdparty/AppUtils/utils_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class UtilsApp : public QObject

static Q_INVOKABLE void vibrate(int ms);

static Q_INVOKABLE QString getMobileWifiSSID();

static Q_INVOKABLE bool checkMobileStoragePermissions();
static Q_INVOKABLE bool getMobileStoragePermissions();
static Q_INVOKABLE bool checkMobileStorageReadPermission();
Expand Down
6 changes: 3 additions & 3 deletions src/thirdparty/AppUtils/utils_os_android_qt5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool UtilsAndroid::gpsutils_isGpsEnabled()
if (appCtx.isValid())
{
jboolean verified = QAndroidJniObject::callStaticMethod<jboolean>(
"com/emeric/utils/QGpsUtils",
"io/emeric/utils/QGpsUtils",
"checkGpsEnabled",
"(Landroid/content/Context;)Z",
appCtx.object());
Expand All @@ -346,7 +346,7 @@ bool UtilsAndroid::gpsutils_forceGpsEnabled()
if (appCtx.isValid())
{
jboolean verified = QAndroidJniObject::callStaticMethod<jboolean>(
"com/emeric/utils/QGpsUtils",
"io/emeric/utils/QGpsUtils",
"forceGpsEnabled",
"(Landroid/content/Context;)Z",
appCtx.object());
Expand All @@ -370,7 +370,7 @@ void UtilsAndroid::gpsutils_openLocationSettings()
if (appCtx.isValid())
{
QAndroidJniObject intent = QAndroidJniObject::callStaticObjectMethod(
"com/emeric/utils/QGpsUtils",
"io/emeric/utils/QGpsUtils",
"openLocationSettings",
"()Landroid/content/Intent;",
appCtx.object());
Expand Down
6 changes: 3 additions & 3 deletions src/thirdparty/AppUtils/utils_os_android_qt6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ bool UtilsAndroid::gpsutils_isGpsEnabled()
bool status = false;

jboolean verified = QJniObject::callStaticMethod<jboolean>(
"com/emeric/utils/QGpsUtils",
"io/emeric/utils/QGpsUtils",
"checkGpsEnabled",
"(Landroid/content/Context;)Z",
QNativeInterface::QAndroidApplication::context());
Expand All @@ -479,7 +479,7 @@ bool UtilsAndroid::gpsutils_forceGpsEnabled()
bool status = false;

jboolean verified = QJniObject::callStaticMethod<jboolean>(
"com/emeric/utils/QGpsUtils",
"io/emeric/utils/QGpsUtils",
"forceGpsEnabled",
"(Landroid/content/Context;)Z",
QNativeInterface::QAndroidApplication::context());
Expand All @@ -498,7 +498,7 @@ void UtilsAndroid::gpsutils_openLocationSettings()
if (activity.isValid())
{
QJniObject intent = QJniObject::callStaticObjectMethod(
"com/emeric/utils/QGpsUtils",
"io/emeric/utils/QGpsUtils",
"openLocationSettings",
"()Landroid/content/Intent;",
activity.object<jobject>());
Expand Down
9 changes: 1 addition & 8 deletions src/thirdparty/AppUtils/utils_os_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define UTILS_OS_IOS_H

#include <QtGlobal>
#include <QString>

#if defined(Q_OS_IOS)
/* ************************************************************************** */
Expand All @@ -44,21 +45,13 @@ class UtilsIOS
*/
static bool getPermission_notification();

/* ********************************************************************** */

static void screenKeepOn(bool on);

static void screenLockOrientation(int orientation);

static void screenLockOrientation(int orientation, bool autoRotate);

/* ********************************************************************** */

static void vibrate(int milliseconds);

/* ********************************************************************** */

static QString getWifiSSID();
};

/* ************************************************************************** */
Expand Down
Loading

0 comments on commit 3ed1451

Please sign in to comment.