example 'wear-os-gps': add 'qt:keep-screen-on' for iOS

This commit is contained in:
pls.153 2022-07-25 15:25:38 +02:00
parent 1cf838c35c
commit dddb5a5758
6 changed files with 27 additions and 10 deletions

View file

@ -69,10 +69,14 @@ android {
ios {
DEFINES -= DESKTOP_APP
DEFINES += QT_EXTENSION
INCLUDEPATH = $$(ECL_IOS)/include
LIBS = -L$$(ECL_IOS)/lib -lecl
LIBS += -leclatomic -leclffi -leclgc -leclgmp
LIBS += -L../../../platforms/ios/lib
LIBS += -framework UIKit # for 'qt:keep-screen-on'
HEADERS += cpp/qt.h
SOURCES += cpp/qt.mm
QMAKE_INFO_PLIST = platforms/ios/Info.plist
}

View file

@ -20,7 +20,7 @@ QVariant QT::keepScreenOn(const QVariant& on) {
env->ExceptionClear();
}
});
return QVariant();
return on;
}
QT_END_NAMESPACE

View file

@ -0,0 +1,12 @@
#include "qt.h"
#import <UIKit/UIKit.h>
QT_BEGIN_NAMESPACE
QVariant QT::keepScreenOn(const QVariant& on) {
[UIApplication sharedApplication].idleTimerDisabled = on.toBool() ? YES : NO;
return on;
}
QT_END_NAMESPACE

View file

@ -6,9 +6,10 @@
(defun run ()
(qt:ini)
#+android
#+mobile
(progn
(qlater (lambda () (qt:keep-screen-on qt:*cpp*))) ; delay until UI is loaded (see 'Settings.qml')
#+android
(ensure-permissions :access-fine-location))
(q> |ready| ui:*position-source* t))
@ -66,7 +67,7 @@
(round* (distance))))))
(defun always-on-changed (on) ; called from QML
#+android
#+mobile
(qt:keep-screen-on qt:*cpp* on))
(defun set-max-speed () ; called from QML

View file

@ -10,7 +10,7 @@
(defvar *cpp* nil)
(defun ini ()
#+android
#+mobile
(progn
(setf *cpp* (qfind-child nil "QT"))
(let ((*package* (find-package :qt)))

View file

@ -3,13 +3,13 @@
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<string>GPS</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>${ASSETCATALOG_COMPILER_APPICON_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
@ -26,6 +26,10 @@
<string>${IPHONEOS_DEPLOYMENT_TARGET}</string>
<key>NOTE</key>
<string>This file was generated by Qt/QMake.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>To display speed and distance.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>To display speed and distance.</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UISupportedInterfaceOrientations</key>
@ -35,9 +39,5 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>To display speed and distance.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>To display speed and distance.</string>
</dict>
</plist>