Merge pull request #481 from estevez-dev/pre-release/702

Pre release/702
This commit is contained in:
Yegor Vialov 2019-10-22 21:57:43 +03:00 committed by GitHub
commit 345301c03a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 24 deletions

View File

@ -50,11 +50,13 @@ android {
}
signingConfigs {
debug {
keyAlias keystoreProperties['debugKeyAlias']
keyPassword keystoreProperties['debugKeyPassword']
storeFile file(keystoreProperties['debugStoreFile'])
storePassword keystoreProperties['debugStorePassword']
if (!System.getenv()["CI"]) {
debug {
keyAlias keystoreProperties['debugKeyAlias']
keyPassword keystoreProperties['debugKeyPassword']
storeFile file(keystoreProperties['debugStoreFile'])
storePassword keystoreProperties['debugStorePassword']
}
}
release {
keyAlias keystoreProperties['keyAlias']

View File

@ -140,7 +140,7 @@ final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
const String appName = "HA Client";
const appVersionNumber = "0.7.0";
const appVersionAdd = "alpha2";
const appVersionAdd = "alpha3";
const appVersion = "$appVersionNumber-$appVersionAdd";
void main() async {

View File

@ -66,13 +66,10 @@ class LocationManager {
"httpWebHost": httpWebHost
},
frequency: _updateInterval,
existingWorkPolicy: workManager.ExistingWorkPolicy.replace,
existingWorkPolicy: workManager.ExistingWorkPolicy.keep,
backoffPolicy: workManager.BackoffPolicy.linear,
backoffPolicyDelay: _updateInterval,
constraints: workManager.Constraints(
requiresBatteryNotLow: false,
requiresCharging: false,
requiresDeviceIdle: false,
requiresStorageNotLow: false,
networkType: workManager.NetworkType.connected
)
);
@ -120,19 +117,20 @@ class LocationManager {
void updateDeviceLocationIsolate() {
workManager.Workmanager.executeTask((backgroundTask, data) {
print("[Location isolate] Started: $backgroundTask");
print("[Background $backgroundTask] Started");
print("[Location isolate] loading settings");
String webhookId = data["webhookId"];
String httpWebHost = data["httpWebHost"];
if (webhookId != null && webhookId.isNotEmpty) {
Logger.d("[Location isolate] Getting device location...");
int battery = DateTime.now().hour;
print("[Background $backgroundTask] hour=$battery");
String url = "$httpWebHost/api/webhook/$webhookId";
Map<String, String> headers = {};
headers["Content-Type"] = "application/json";
print("[Background $backgroundTask] Getting device location...");
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
Logger.d("[Location isolate] Got location: ${location.latitude} ${location.longitude}. Sending home...");
int battery = DateTime.now().hour;
String url = "$httpWebHost/api/webhook/$webhookId";
Map<String, String> headers = {};
headers["Content-Type"] = "application/json";
print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude}");
print("[Background $backgroundTask] sending data home...");
var data = {
"type": "update_location",
"data": {
@ -146,15 +144,56 @@ void updateDeviceLocationIsolate() {
headers: headers,
body: json.encode(data)
).catchError((e) {
print("[Location isolate] Error sending data: ${e.toString()}");
print("[Background $backgroundTask] Error sending data: ${e.toString()}");
}).then((_) {
print("[Location isolate] done!");
print("[Background $backgroundTask] Success!");
});
}).catchError((e) {
print("[Location isolate] Error getting location: ${e.toString()}");
print("[Background $backgroundTask] Error getting current location: ${e.toString()}. Trying last known...");
Geolocator().getLastKnownPosition(desiredAccuracy: LocationAccuracy.medium).then((location){
print("[Background $backgroundTask] Got last known location: ${location.latitude} ${location.longitude}");
print("[Background $backgroundTask] sending data home...");
var data = {
"type": "update_location",
"data": {
"gps": [location.latitude, location.longitude],
"gps_accuracy": location.accuracy,
"battery": battery
}
};
http.post(
url,
headers: headers,
body: json.encode(data)
).catchError((e) {
print("[Background $backgroundTask] Error sending data: ${e.toString()}");
}).then((_) {
print("[Background $backgroundTask] Success!");
});
}).catchError((e){
print("[Background $backgroundTask] Error getting last known location: ${e.toString()}. Sending fake...");
print("[Background $backgroundTask] sending data home...");
var data = {
"type": "update_location",
"data": {
"gps": [40.34, 30.34],
"gps_accuracy": 300,
"battery": battery
}
};
http.post(
url,
headers: headers,
body: json.encode(data)
).catchError((e) {
print("[Background $backgroundTask] Error sending data: ${e.toString()}");
}).then((_) {
print("[Background $backgroundTask] Success!");
});
});
});
} else {
print("[Location isolate] No webhook id. Aborting");
print("[Background $backgroundTask] No webhook id. Aborting");
}
return Future.value(true);
});

View File

@ -1,7 +1,7 @@
name: hass_client
description: Home Assistant Android Client
version: 0.7.0+702
version: 0.7.0+703
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"