Skip to content

Commit

Permalink
Getting ready for release 1.3.0+10
Browse files Browse the repository at this point in the history
- Changed drift web database to the wasm version.
- Removed `x86` from the Android ABI list since flutter cannot release build to this target.
- Created build scripts
  • Loading branch information
jeroen1602 committed Dec 8, 2023
1 parent a21521b commit 6160012
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 41 deletions.
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

Expand All @@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
71 changes: 43 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand All @@ -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.

<a href="https://f-droid.org/packages/com.jeroen1602.lighthouse_pm/" target="_blank">
<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" alt="Get it on F-Droid" height="96"></a>


### Google Play

**NOTE** The Google Play version may be behind by a version because of the approval process.
Expand All @@ -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`
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 22 additions & 0 deletions lib/data/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}());
}
25 changes: 22 additions & 3 deletions lib/data/shared/web.dart
Original file line number Diff line number Diff line change
@@ -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);
}
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MainApp extends StatelessWidget {
final db = constructDb();
final mainBloc = LighthousePMBloc(db);

initDatabaseLogger();
LighthouseProviderStart.loadLibrary();
LighthouseProviderStart.setupPersistence(mainBloc);
LighthouseProviderStart.setupCallbacks();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ packages:
source: hosted
version: "3.0.0"
logging:
dependency: transitive
dependency: "direct main"
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions scripts/build-release-apks-github.sh
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions scripts/build-release-bundle-playstore.sh
Original file line number Diff line number Diff line change
@@ -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"
27 changes: 27 additions & 0 deletions scripts/build-release-github-pages.sh
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 15 additions & 0 deletions scripts/split-per-abi-build.gradle.patch
Original file line number Diff line number Diff line change
@@ -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'
}
3 changes: 1 addition & 2 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Fore more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
-->
<base href="/">
<base href="$FLUTTER_BASE_HREF">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
Expand Down Expand Up @@ -49,7 +49,6 @@
});
}
</script>
<script src="sql-wasm.js" type="application/javascript"></script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

0 comments on commit 6160012

Please sign in to comment.