App registration improvements
This commit is contained in:
parent
3417c38426
commit
12d226509d
@ -100,7 +100,7 @@ class HomeAssistant {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Future checkAppRegistration({bool forceRegister: false}) {
|
Future checkAppRegistration({bool forceRegister: false, bool showOkDialog: false}) {
|
||||||
Completer completer = Completer();
|
Completer completer = Completer();
|
||||||
if (Connection().webhookId == null || forceRegister) {
|
if (Connection().webhookId == null || forceRegister) {
|
||||||
Logger.d("Mobile app was not registered yet or need to be reseted. Registering...");
|
Logger.d("Mobile app was not registered yet or need to be reseted. Registering...");
|
||||||
@ -148,12 +148,19 @@ class HomeAssistant {
|
|||||||
data: json.encode(updateData)
|
data: json.encode(updateData)
|
||||||
).then((response) {
|
).then((response) {
|
||||||
Logger.d("App registration works fine");
|
Logger.d("App registration works fine");
|
||||||
|
if (showOkDialog) {
|
||||||
|
eventBus.fire(ShowDialogEvent(
|
||||||
|
title: "All good",
|
||||||
|
body: "HA Client integration with your Home Assistant server works fine",
|
||||||
|
positiveText: "Nice!"
|
||||||
|
));
|
||||||
|
}
|
||||||
completer.complete();
|
completer.complete();
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
if (e['code'] != null && e['code'] == 410) {
|
if (e['code'] != null && e['code'] == 410) {
|
||||||
Logger.e("This integration was removed.");
|
Logger.e("MobileApp integration was removed");
|
||||||
eventBus.fire(ShowDialogEvent(
|
eventBus.fire(ShowDialogEvent(
|
||||||
title: "App registration was removed or something went wrong",
|
title: "App integration was removed",
|
||||||
body: "Looks like app integration was removed from your Home Assistant. HA Client needs to be registered on your Home Assistant server to make it possible to use notifications and other useful stuff.",
|
body: "Looks like app integration was removed from your Home Assistant. HA Client needs to be registered on your Home Assistant server to make it possible to use notifications and other useful stuff.",
|
||||||
positiveText: "Register now",
|
positiveText: "Register now",
|
||||||
negativeText: "Cancel",
|
negativeText: "Cancel",
|
||||||
@ -167,6 +174,19 @@ class HomeAssistant {
|
|||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
Logger.e("Error updating app registration: ${e.toString()}");
|
Logger.e("Error updating app registration: ${e.toString()}");
|
||||||
|
eventBus.fire(ShowDialogEvent(
|
||||||
|
title: "App integration is not working properly",
|
||||||
|
body: "Something wrong with HA Client integration on your Home Assistant server. Try to remove current app integration from Configuration -> Integrationds using web UI, restart your Home Assistant and go back to the app. NOTE that after clicking 'Ok' current integration data will be removed from the app and new integration wll be created on Home Assistant side on next app launch.",
|
||||||
|
positiveText: "Ok",
|
||||||
|
negativeText: "I'll handle it",
|
||||||
|
onPositive: () {
|
||||||
|
SharedPreferences.getInstance().then((prefs) {
|
||||||
|
prefs.remove("app-webhook-id");
|
||||||
|
Connection().webhookId = null;
|
||||||
|
HAUtils.launchURL(Connection().httpWebHost+"/config/integrations/dashboard");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
));
|
||||||
}
|
}
|
||||||
completer.complete();
|
completer.complete();
|
||||||
});
|
});
|
||||||
|
@ -379,6 +379,27 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showDialog({String title, String body, var onPositive, var onNegative, String positiveText, String negativeText}) {
|
void _showDialog({String title, String body, var onPositive, var onNegative, String positiveText, String negativeText}) {
|
||||||
|
List<Widget> buttons = [];
|
||||||
|
buttons.add(FlatButton(
|
||||||
|
child: new Text("$positiveText"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
if (onPositive != null) {
|
||||||
|
onPositive();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
|
if (negativeText != null) {
|
||||||
|
buttons.add(FlatButton(
|
||||||
|
child: new Text("$negativeText"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
if (onNegative != null) {
|
||||||
|
onNegative();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
// flutter defined function
|
// flutter defined function
|
||||||
showDialog(
|
showDialog(
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@ -388,27 +409,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: new Text("$title"),
|
title: new Text("$title"),
|
||||||
content: new Text("$body"),
|
content: new Text("$body"),
|
||||||
actions: <Widget>[
|
actions: buttons,
|
||||||
// usually buttons at the bottom of the dialog
|
|
||||||
new FlatButton(
|
|
||||||
child: new Text("$positiveText"),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
if (onPositive != null) {
|
|
||||||
onPositive();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
new FlatButton(
|
|
||||||
child: new Text("$negativeText"),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
if (onNegative != null) {
|
|
||||||
onNegative();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user