diff --git a/.gitignore b/.gitignore
index a5c82c40..03c3adc3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,9 +31,6 @@
.pub/
/build/
-# Web related
-lib/generated_plugin_registrant.dart
-
# Symbolication related
app.*.symbols
@@ -50,8 +47,12 @@ app.*.map.json
# Ingore generated dart files
*.g.dart
-#sql-wasm
-web/sql-*
+#drif for the web
+web/drift_worker.js
+web/sqlite3.wasm
#test coverage
coverage
+
+#build output
+output
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 056ff74d..4cea42a8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
Lighthouse power management
-Copyright (C) 2020-2022 Jeroen1602
+Copyright (C) 2020-2023 Jeroen1602
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/README.md b/README.md
index b654106c..4cf54f67 100644
--- a/README.md
+++ b/README.md
@@ -4,10 +4,11 @@
Power management app to control the Valve Index® lighthouses from your phone.
-Inspired by [lighthouse-v2-manager](https://github.com/nouser2013/lighthouse-v2-manager) but that project is desktop only.
-And if your computer doesn't have a bluetooth adapter then it is useless. Sadly the Valve Index® doesn't provide it's bluetooth adapter
-to the system and thus can't be used for that. Fortunately most phones do have bluetooth support, so I made this app to
-easily change the power state of a Lighthouse.
+Inspired by [lighthouse-v2-manager](https://github.com/nouser2013/lighthouse-v2-manager) but that
+project is desktop only. And if your computer doesn't have a bluetooth adapter then it is useless.
+Sadly the Valve Index® doesn't provide it's bluetooth adapter to the system and thus can't be used
+for that. Fortunately most phones do have bluetooth support, so I made this app to easily change
+the power state of a Lighthouse.
The app also supports Vive Base stations.
@@ -16,11 +17,12 @@ The app also supports Vive Base stations.
**This project gives no warranty that you won't brick your lighthouses!**
It MOST probably won't actually brick your lighthouses, but I'm not liable in case that it does.
-Since the method used to change the power state of the lighthouses is the same as the one that
+Since the method used to change the power state of the lighthouses is the same as the one that
Valve uses it is very unlikely to actually brick the lighthouse.
-If for whatever reason your lighthouse does get bricked, please
-[create an issue](https://github.com/jeroen1602/lighthouse_pm/issues) so we can prevent other users from bricking theirs.
+If for whatever reason your lighthouse does get bricked, please
+[create an issue](https://github.com/jeroen1602/lighthouse_pm/issues) so we can prevent other users
+from bricking theirs.
## Installation
@@ -31,17 +33,18 @@ Almost all phones made after 2013 support this.
#### Android
- - Bluetooth low energy support (as stated above modern devices probably support it).
- - Android 4.4 (API level 19) and up.
+- Bluetooth low energy support (as stated above modern devices probably support it).
+- Android 4.4 (API level 19) and up.
### F-Droid
-**NOTE** F-Droid will build the app from sources so it may be up to 24 hours behind on a release from Github. Also F-Droid sings the app with their own key, so you can't upgrade from a Github/ Google Play release to an F-Droid release.
+**NOTE** F-Droid will build the app from sources so it may be up to 24 hours behind on a release
+from Github. Also F-Droid sings the app with their own key, so you can't upgrade from a Github/
+Google Play release to an F-Droid release.
-
### Google Play
**NOTE** The Google Play version may be behind by a version because of the approval process.
@@ -53,44 +56,56 @@ Almost all phones made after 2013 support this.
### Sideload
-Another way is to install the app using sideloading. Grab the `APK` from the [releases](https://github.com/jeroen1602/lighthouse_pm/releases) page and [sideload](https://www.howtogeek.com/313433/how-to-sideload-apps-on-android/) this onto your device.
+Another way is to install the app using sideloading. Grab the `APK` from
+the [releases](https://github.com/jeroen1602/lighthouse_pm/releases) page
+and [sideload](https://www.howtogeek.com/313433/how-to-sideload-apps-on-android/) this onto your
+device.
### iOS
Since the app is made in Flutter it should be able to run on iOS device with a minimal amount of
tweaking. I however don't have any Apple device so I can't test this.
-If there is anyone who does want to pick this up and support that part then please look at [contributing](CONTRIBUTING.md).
+If there is anyone who does want to pick this up and support that part then please look
+at [contributing](CONTRIBUTING.md).
-There has been a little bit of validating on the iOS version. So if you are able to and really want to you can try "[sideloading](https://beebom.com/how-to-sideload-apps-iphone-ios-10-without-jailbreak/)" it onto your iDevice.
+There has been a little bit of validating on the iOS version. So if you are able to and really want
+to you can
+try "[sideloading](https://beebom.com/how-to-sideload-apps-iphone-ios-10-without-jailbreak/)" it
+onto your iDevice.
## Building
-Because the app uses generated code you will first need to run `flutter packages pub run build_runner build` or `flutter packages pub run build_runner watch` before the app can be build.
+Because the app uses generated code you will first need to
+run `dart run build_runner build` or `dart run build_runner watch`
+before the app can be build.
-While the app is in development there may be changes to the local database, there will not be any migrations written unless it's between actual versions. So you may need to clear the app storage before some new features start working.
+While the app is in development there may be changes to the local database, there will not be any
+migrations written unless it's between actual versions. So you may need to clear the app storage
+before some new features start working.
### Web Builds
-For web builds you will need to download `sql-wasm` and place it in the web folder. This can be
-done from [here](https://github.com/sql-js/sql.js/releases). You will need to download the
-`wasm version, best runtime performance, smaller assets, requires configuration` version. Extract
-the `sql-wasm.js` and `sql-wasm.wasm` files in the web folder. After this you are ready to create
-web builds.
+For web builds you will need to download `sqlite3.dart` and `drift_worker.js`
+and place these in the web folder. This can be done from
+[here](https://github.com/simolus3/sqlite3.dart/releases) for `sqlite3.dart` and
+[here](https://github.com/simolus3/drift/releases) for `drift_worker.js`.
-If you want to debug with chrome on a platform where web bluetooth is behind a startup flag, then
-follow the tutorial provided by the flutter_web_bluetooth library
-[here](https://github.com/jeroen1602/flutter_web_bluetooth/tree/master/chrome-experimental-launch).
+If you want to debug with chrome on a platform where web bluetooth is behind a startup flag, then
+follow the tutorial provided by the flutter_web_bluetooth library
+[here](https://github.com/jeroen1602/flutter_web_bluetooth/tree/master/chrome-experimental-launch).
### Linux Builds
For linux builds you no longer need the sqlite3 dev library on your computer as it now comes with
the `sqlite3_flutter_libs` library.
-The database for user settings is stored under `~/.local/share/lighthouse_pm/settings.sqlite` feel free to remove it if
-you need to reset the settings.
+The database for user settings is stored under `~/.local/share/lighthouse_pm/settings.sqlite` feel
+free to remove it if you need to reset the settings.
### Release build
-Sometimes before you can create a release build you will need to assemble the Android component before an Android build can be created.
-Run `./gradlew assemble` inside the `./android` folder before running `flutter build apk`/ `flutter build appbundle`
+Sometimes before you can create a release build you will need to assemble the Android component
+before an Android build can be created.
+Run `./gradlew assemble` inside the `./android` folder before
+running `flutter build apk`/ `flutter build appbundle`
diff --git a/android/app/build.gradle b/android/app/build.gradle
index a8b27fd4..2dec5edb 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -80,7 +80,7 @@ android {
release {
signingConfig signingConfigs.release
ndk {
- abiFilters "armeabi-v7a", "arm64-v8a", "x86_64", "x86"
+ abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"
}
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
diff --git a/lib/data/database.dart b/lib/data/database.dart
index 3b6d57b2..0ea57ee2 100644
--- a/lib/data/database.dart
+++ b/lib/data/database.dart
@@ -9,6 +9,7 @@ import 'tables/last_seen_devices_table.dart';
import 'tables/nickname_table.dart';
import 'tables/simple_settings_table.dart';
import 'tables/vive_base_station_id_table.dart';
+import 'package:logging/logging.dart';
export 'shared/shared.dart';
@@ -73,3 +74,24 @@ class LighthouseDatabase extends _$LighthouseDatabase {
await customStatement('PRAGMA foreign_keys = ON');
});
}
+
+final databaseLogger = Logger('database_logger');
+
+void initDatabaseLogger() {
+ assert(() {
+ databaseLogger.onRecord.listen((final record) {
+ // ignore: avoid_print
+ print("${record.loggerName}|${record.time}: ${record.message}");
+ if (record.error != null) {
+ // ignore: avoid_print
+ print("Error: ${record.error}");
+ }
+ if (record.stackTrace != null) {
+ // ignore: avoid_print
+ print("Trace: ${record.stackTrace.toString()}");
+ }
+ });
+
+ return true;
+ }());
+}
diff --git a/lib/data/shared/web.dart b/lib/data/shared/web.dart
index 51224aac..66c98382 100644
--- a/lib/data/shared/web.dart
+++ b/lib/data/shared/web.dart
@@ -1,8 +1,27 @@
-import 'package:drift/web.dart';
+import 'package:drift/drift.dart';
+import 'package:drift/wasm.dart';
import '../database.dart';
LighthouseDatabase constructDb({final bool logStatements = false}) {
- return LighthouseDatabase(
- WebDatabase('LighthouseDatabase', logStatements: logStatements));
+ final connection = DatabaseConnection.delayed(Future(() async {
+ final result = await WasmDatabase.open(
+ databaseName: 'LighthouseDatabase',
+ sqlite3Uri: Uri.parse('sqlite3.wasm'),
+ driftWorkerUri: Uri.parse('drift_worker.js'),
+ );
+
+ if (result.missingFeatures.isNotEmpty) {
+ // Depending how central local persistence is to your app, you may want
+ // to show a warning to the user if only unreliable implementations
+ // are available.
+ databaseLogger
+ .info('Using ${result.chosenImplementation} due to missing browser '
+ 'features: ${result.missingFeatures}');
+ }
+
+ return result.resolvedExecutor;
+ }));
+
+ return LighthouseDatabase(connection);
}
diff --git a/lib/main.dart b/lib/main.dart
index 1d087cbd..6910e9c1 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -47,6 +47,7 @@ class MainApp extends StatelessWidget {
final db = constructDb();
final mainBloc = LighthousePMBloc(db);
+ initDatabaseLogger();
LighthouseProviderStart.loadLibrary();
LighthouseProviderStart.setupPersistence(mainBloc);
LighthouseProviderStart.setupCallbacks();
diff --git a/pubspec.lock b/pubspec.lock
index 8091a1ac..456fd55c 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -520,7 +520,7 @@ packages:
source: hosted
version: "3.0.0"
logging:
- dependency: transitive
+ dependency: "direct main"
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
diff --git a/pubspec.yaml b/pubspec.yaml
index 67d7732a..32f2e8ce 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -39,6 +39,7 @@ dependencies:
sqlite3_flutter_libs: ^0.5.18
path_provider: ^2.1.1
path: ^1.8.3
+ logging: ^1.2.0
provider: ^6.1.1
tuple: ^2.0.2
intl: ^0.19.0
diff --git a/scripts/build-release-apks-github.sh b/scripts/build-release-apks-github.sh
new file mode 100755
index 00000000..249bea59
--- /dev/null
+++ b/scripts/build-release-apks-github.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+
+SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
+
+cd "$SCRIPT_DIR/../" || exit
+
+patch -p1 -d "${SCRIPT_DIR}/../" <"${SCRIPT_DIR}/split-per-abi-build.gradle.patch"
+
+flutter build apk --release --no-obfuscate \
+ --flavor=defaultVersion \
+ --dart-define=includeGooglePlayInAppPurchases=false \
+ --dart-define=includeSupportButtons=true \
+ --dart-define=includeSupportPage=true \
+ --dart-define=includePaypal=true \
+ --dart-define=includeGithubSponsor=true \
+ --split-per-abi \
+ --target-platform=android-arm,android-arm64,android-x64
+
+EXIT_CODE=$?
+
+patch -p1 -R -d "${SCRIPT_DIR}/../" <"${SCRIPT_DIR}/split-per-abi-build.gradle.patch"
+
+if [ $EXIT_CODE != 0 ]; then
+ echo 'Could not build'
+ exit $EXIT_CODE
+fi
+
+set -e
+
+mkdir -p "$SCRIPT_DIR/../output"
+
+VERSION=$(grep -oP 'version: \K\d+\.\d+\.\d+\+\d+' "${SCRIPT_DIR}/../pubspec.yaml")
+
+function copy_result() {
+ VERSION=$1
+ ABI=$2
+ NEW_ABI=$3
+ ORIGINAL_PATH="${SCRIPT_DIR}/../build/app/outputs/flutter-apk/app-${ABI}-defaultversion-release.apk"
+ NEW_PATH="${SCRIPT_DIR}/../output/lighthouse_pm-${VERSION}.${NEW_ABI}.apk"
+ cp -vrf "$ORIGINAL_PATH" "$NEW_PATH"
+}
+
+copy_result "$VERSION" "armeabi-v7a" "arm"
+copy_result "$VERSION" "arm64-v8a" "arm64"
+copy_result "$VERSION" "x86_64" "X64"
diff --git a/scripts/build-release-bundle-playstore.sh b/scripts/build-release-bundle-playstore.sh
new file mode 100755
index 00000000..6243456d
--- /dev/null
+++ b/scripts/build-release-bundle-playstore.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+
+SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
+
+cd "$SCRIPT_DIR/../" || exit
+
+flutter build appbundle --release --no-obfuscate \
+ --flavor=googlePlay \
+ --dart-define=includeGooglePlayInAppPurchases=true \
+ --dart-define=includeSupportButtons=true \
+ --dart-define=includeSupportPage=true \
+ --dart-define=includePaypal=false \
+ --dart-define=includeGithubSponsor=false \
+ --target-platform=android-arm,android-arm64,android-x64
+
+EXIT_CODE=$?
+
+if [ $EXIT_CODE != 0 ]; then
+ echo 'Could not build'
+ exit $EXIT_CODE
+fi
+
+set -e
+
+mkdir -p "$SCRIPT_DIR/../output"
+
+VERSION=$(grep -oP 'version: \K\d+\.\d+\.\d+\+\d+' "${SCRIPT_DIR}/../pubspec.yaml")
+
+cp -vrf "${SCRIPT_DIR}/../build/app/outputs/bundle/googlePlayRelease/app-googlePlay-release.aab" "$SCRIPT_DIR/../output/googlePlay-${VERSION}.aab"
diff --git a/scripts/build-release-github-pages.sh b/scripts/build-release-github-pages.sh
new file mode 100755
index 00000000..86274415
--- /dev/null
+++ b/scripts/build-release-github-pages.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+
+SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
+
+cd "$SCRIPT_DIR/../" || exit
+
+flutter build web --release \
+ --dart-define=includeGooglePlayInAppPurchases=false \
+ --dart-define=includeSupportButtons=true \
+ --dart-define=includeSupportPage=true \
+ --dart-define=includePaypal=true \
+ --dart-define=includeGithubSponsor=true \
+ --base-href="/lighthouse_pm/" \
+ --pwa-strategy=offline-first
+
+EXIT_CODE=$?
+
+if [ $EXIT_CODE != 0 ]; then
+ echo 'Could not build'
+ exit $EXIT_CODE
+fi
+
+set -e
+
+cp -vrf "${SCRIPT_DIR}/../build/web/" "${SCRIPT_DIR}/../output/web/"
+
+perl -pi -e 's/"\/":/"\/lighthouse_pm\/":/' "${SCRIPT_DIR}/../output/web/flutter_service_worker.js"
diff --git a/scripts/split-per-abi-build.gradle.patch b/scripts/split-per-abi-build.gradle.patch
new file mode 100644
index 00000000..b5fdb154
--- /dev/null
+++ b/scripts/split-per-abi-build.gradle.patch
@@ -0,0 +1,15 @@
+--- ./android/app/build.gradle 2023-12-08 11:17:36.130601770 +0100
++++ ./android/app/build_split_abi.gradle 2023-12-08 11:21:11.144304948 +0100
+@@ -79,9 +79,9 @@
+ buildTypes {
+ release {
+ signingConfig signingConfigs.release
+- ndk {
+- abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"
+- }
++// ndk {
++// abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"
++// }
+ minifyEnabled true
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
diff --git a/web/index.html b/web/index.html
index 428e07ff..ea949156 100644
--- a/web/index.html
+++ b/web/index.html
@@ -11,7 +11,7 @@
Fore more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
-->
-
+
@@ -49,7 +49,6 @@
});
}
-