WebVIew UI settings
This commit is contained in:
parent
8a80d0c5d1
commit
01226cb9eb
@ -104,7 +104,7 @@ part 'pages/widgets/product_purchase.widget.dart';
|
|||||||
part 'pages/widgets/page_loading_indicator.dart';
|
part 'pages/widgets/page_loading_indicator.dart';
|
||||||
part 'pages/widgets/page_loading_error.dart';
|
part 'pages/widgets/page_loading_error.dart';
|
||||||
part 'pages/panel.page.dart';
|
part 'pages/panel.page.dart';
|
||||||
part 'pages/main.page.dart';
|
part 'pages/main/main.page.dart';
|
||||||
part 'pages/integration_settings.page.dart';
|
part 'pages/integration_settings.page.dart';
|
||||||
part 'home_assistant.class.dart';
|
part 'home_assistant.class.dart';
|
||||||
part 'pages/log.page.dart';
|
part 'pages/log.page.dart';
|
||||||
|
@ -20,7 +20,7 @@ class ConnectionManager {
|
|||||||
String oauthUrl;
|
String oauthUrl;
|
||||||
String webhookId;
|
String webhookId;
|
||||||
bool useLovelace = true;
|
bool useLovelace = true;
|
||||||
bool useWebView = true;
|
bool useWebView = false;
|
||||||
bool settingsLoaded = false;
|
bool settingsLoaded = false;
|
||||||
bool get isAuthenticated => _token != null;
|
bool get isAuthenticated => _token != null;
|
||||||
StreamSubscription _socketSubscription;
|
StreamSubscription _socketSubscription;
|
||||||
@ -42,6 +42,7 @@ class ConnectionManager {
|
|||||||
Logger.e("Loading settings...");
|
Logger.e("Loading settings...");
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
useLovelace = prefs.getBool('use-lovelace') ?? true;
|
useLovelace = prefs.getBool('use-lovelace') ?? true;
|
||||||
|
useWebView = prefs.getBool("use-webview") ?? false;
|
||||||
_domain = prefs.getString('hassio-domain');
|
_domain = prefs.getString('hassio-domain');
|
||||||
_port = prefs.getString('hassio-port');
|
_port = prefs.getString('hassio-port');
|
||||||
webhookId = prefs.getString('app-webhook-id');
|
webhookId = prefs.getString('app-webhook-id');
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
part of '../main.dart';
|
part of '../../main.dart';
|
||||||
|
|
||||||
class MainPage extends StatefulWidget {
|
class MainPage extends StatefulWidget {
|
||||||
MainPage({Key key, this.title}) : super(key: key);
|
MainPage({Key key, this.title}) : super(key: key);
|
||||||
@ -24,6 +24,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
int _previousViewCount;
|
int _previousViewCount;
|
||||||
bool _showLoginButton = false;
|
bool _showLoginButton = false;
|
||||||
bool _preventAppRefresh = false;
|
bool _preventAppRefresh = false;
|
||||||
|
bool _showWebViewControls = true;
|
||||||
Entity _entityToShow;
|
Entity _entityToShow;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -129,6 +130,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
flutterWebViewPlugin.onScrollYChanged.listen((double offsetY) {
|
||||||
|
setState(() {
|
||||||
|
_showWebViewControls = (offsetY == 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
await HomeAssistant().fetchData().then((_) {
|
await HomeAssistant().fetchData().then((_) {
|
||||||
_hideBottomBar();
|
_hideBottomBar();
|
||||||
@ -855,14 +862,30 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
primary: false,
|
primary: false,
|
||||||
bottomNavigationBar: bottomBar,
|
bottomNavigationBar: bottomBar,
|
||||||
body: _buildScaffoldBody(true)
|
body: Container(
|
||||||
|
color: Colors.white,
|
||||||
|
)
|
||||||
);
|
);
|
||||||
} else if (ConnectionManager().settingsLoaded && ConnectionManager().useWebView) {
|
} else if (ConnectionManager().settingsLoaded && ConnectionManager().useWebView) {
|
||||||
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
|
|
||||||
return WebviewScaffold(
|
return WebviewScaffold(
|
||||||
url: ConnectionManager().httpWebHost,
|
url: ConnectionManager().httpWebHost,
|
||||||
primary: false,
|
primary: false,
|
||||||
appBar: EmptyAppBar (),
|
appBar: !_showWebViewControls ? EmptyAppBar() : AppBar(
|
||||||
|
actions: <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.smartphone),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pushNamed('/integration-settings');
|
||||||
|
}
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.settings),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pushNamed('/connection-settings');
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
bottomNavigationBar: bottomBar,
|
bottomNavigationBar: bottomBar,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -926,3 +949,24 @@ class EmptyAppBar extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
@override
|
@override
|
||||||
Size get preferredSize => Size(0.0,0.0);
|
Size get preferredSize => Size(0.0,0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class WebViewAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.smartphone),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pushNamed('/connection-settings');
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
//return Container();
|
||||||
|
}
|
||||||
|
@override
|
||||||
|
Size get preferredSize => Size(0.0,30.0);
|
||||||
|
}
|
@ -20,6 +20,8 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
String _newLongLivedToken = "";
|
String _newLongLivedToken = "";
|
||||||
bool _useLovelace = true;
|
bool _useLovelace = true;
|
||||||
bool _newUseLovelace = true;
|
bool _newUseLovelace = true;
|
||||||
|
bool _useWebView = true;
|
||||||
|
bool _newUseWebView = true;
|
||||||
|
|
||||||
String oauthUrl;
|
String oauthUrl;
|
||||||
bool useOAuth = false;
|
bool useOAuth = false;
|
||||||
@ -60,6 +62,11 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
_useLovelace = _newUseLovelace = true;
|
_useLovelace = _newUseLovelace = true;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
_useWebView = _newUseWebView = prefs.getBool("use-webview") ?? true;
|
||||||
|
} catch (e) {
|
||||||
|
_useWebView = _newUseWebView = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +76,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
(_newHassioDomain != _hassioDomain) ||
|
(_newHassioDomain != _hassioDomain) ||
|
||||||
(_newSocketProtocol != _socketProtocol) ||
|
(_newSocketProtocol != _socketProtocol) ||
|
||||||
(_newUseLovelace != _useLovelace) ||
|
(_newUseLovelace != _useLovelace) ||
|
||||||
|
(_newUseWebView != _useWebView) ||
|
||||||
(_newLongLivedToken != _longLivedToken));
|
(_newLongLivedToken != _longLivedToken));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -104,6 +112,7 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
prefs.setString("hassio-protocol", _newSocketProtocol);
|
prefs.setString("hassio-protocol", _newSocketProtocol);
|
||||||
prefs.setString("hassio-res-protocol", _newSocketProtocol == "wss" ? "https" : "http");
|
prefs.setString("hassio-res-protocol", _newSocketProtocol == "wss" ? "https" : "http");
|
||||||
prefs.setBool("use-lovelace", _newUseLovelace);
|
prefs.setBool("use-lovelace", _newUseLovelace);
|
||||||
|
prefs.setBool("use-webview", _newUseWebView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -201,6 +210,19 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
new Row(
|
||||||
|
children: [
|
||||||
|
Text("Use web UI"),
|
||||||
|
Switch(
|
||||||
|
value: _newUseWebView,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
_newUseWebView = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
"Authentication settings",
|
"Authentication settings",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
Reference in New Issue
Block a user