Remove webview plugin

This commit is contained in:
Yegor Vialov 2019-10-20 17:18:23 +00:00
parent 520fd6bc38
commit 079070071e
7 changed files with 11 additions and 82 deletions

View File

@ -17,7 +17,6 @@ import 'package:progress_indicators/progress_indicators.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:device_info/device_info.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
@ -185,17 +184,7 @@ class HAClientApp extends StatelessWidget {
mediaType: "${ModalRoute.of(context).settings.arguments != null ? (ModalRoute.of(context).settings.arguments as Map)['type'] ?? '' : ''}",
),
"/log-view": (context) => LogViewPage(title: "Log"),
"/whats-new": (context) => WhatsNewPage(),
"/webview": (context) => WebviewScaffold(
url: "${(ModalRoute.of(context).settings.arguments as Map)['url']}",
appBar: new AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop()
),
title: new Text("${(ModalRoute.of(context).settings.arguments as Map)['title']}"),
),
)
"/whats-new": (context) => WhatsNewPage()
},
);
}

View File

@ -369,21 +369,8 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
accountName: Text(HomeAssistant().userName),
accountEmail: Text(ConnectionManager().displayHostname ?? "Not configured"),
onDetailsPressed: () {
final flutterWebViewPlugin = new FlutterWebviewPlugin();
flutterWebViewPlugin.onStateChanged.listen((viewState) async {
if (viewState.type == WebViewState.startLoad) {
Logger.d("[WebView] Injecting external auth JS");
rootBundle.loadString('assets/js/externalAuth.js').then((js){
flutterWebViewPlugin.evalJavascript(js.replaceFirst("[token]", ConnectionManager()._token));
});
}
});
Navigator.of(context).pushNamed(
"/webview",
arguments: {
"url": "${ConnectionManager().httpWebHost}/profile?external_auth=1",
"title": "Profile"
}
Launcher.launchURLInCustomTab(
url: "${ConnectionManager().httpWebHost}/profile?external_auth=1"
);
},
currentAccountPicture: CircleAvatar(
@ -407,7 +394,7 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
children: <Widget>[
Text("${panel.title}"),
Container(width: 4.0,),
panel.isWebView ? Text("webview", style: TextStyle(fontSize: 8.0, color: Colors.black45),) : Container(width: 1.0,)
panel.isWebView ? Text("WEB", style: TextStyle(fontSize: 8.0, color: Colors.black45),) : Container(width: 1.0,)
],
),
onTap: () {
@ -888,15 +875,13 @@ class _MainPageState extends ReceiveShareState<MainPage> with WidgetsBindingObse
drawer: _buildAppDrawer(),
primary: false,
bottomNavigationBar: bottomBar,
body: _buildScaffoldBody(false),
body: _buildScaffoldBody(false)
);
}
}
@override
void dispose() {
final flutterWebviewPlugin = new FlutterWebviewPlugin();
flutterWebviewPlugin.dispose();
WidgetsBinding.instance.removeObserver(this);
_viewsTabController?.dispose();
_stateSubscription?.cancel();

View File

@ -28,7 +28,7 @@ class _ConfigPanelWidgetState extends State<ConfigPanelWidget> {
stop() {
eventBus.fire(ShowPopupDialogEvent(
title: "Are you sure you wanr to STOP Home Assistant?",
title: "Are you sure you want to STOP Home Assistant?",
body: "This will STOP your Home Assistant server. It means that your web interface as well as HA Client will not work untill you'll find a way to start your server using ssh or something.",
positiveText: "Sure. Make it so",
negativeText: "What?? No!",
@ -96,19 +96,7 @@ class _ConfigPanelWidgetState extends State<ConfigPanelWidget> {
),
),
),
LinkToWebConfig(name: "Home Assistant Cloud", url: ConnectionManager().httpWebHost+"/config/cloud/account"),
Container(height: 8.0,),
LinkToWebConfig(name: "Integrations", url: ConnectionManager().httpWebHost+"/config/integrations/dashboard"),
LinkToWebConfig(name: "Users", url: ConnectionManager().httpWebHost+"/config/users/picker"),
Container(height: 8.0,),
LinkToWebConfig(name: "General", url: ConnectionManager().httpWebHost+"/config/core"),
LinkToWebConfig(name: "Server Control", url: ConnectionManager().httpWebHost+"/config/server_control"),
LinkToWebConfig(name: "Persons", url: ConnectionManager().httpWebHost+"/config/person"),
LinkToWebConfig(name: "Entity Registry", url: ConnectionManager().httpWebHost+"/config/entity_registry"),
LinkToWebConfig(name: "Area Registry", url: ConnectionManager().httpWebHost+"/config/area_registry"),
LinkToWebConfig(name: "Automation", url: ConnectionManager().httpWebHost+"/config/automation"),
LinkToWebConfig(name: "Script", url: ConnectionManager().httpWebHost+"/config/script"),
LinkToWebConfig(name: "Customization", url: ConnectionManager().httpWebHost+"/config/customize"),
LinkToWebConfig(name: "Home AssistantConfiguration", url: ConnectionManager().httpWebHost+"/config"),
],
);
}

View File

@ -35,7 +35,7 @@ class Panel {
)
);
} else {
Launcher.launchAuthenticatedWebView(context: context, url: "${ConnectionManager().httpWebHost}/$urlPath", title: "${this.title}");
Launcher.launchURLInCustomTab(url: "${ConnectionManager().httpWebHost}/$urlPath");
}
}

View File

@ -19,7 +19,7 @@ class LinkToWebConfig extends StatelessWidget {
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: Sizes.largeFontSize)),
subtitle: Text("Tap to open web version"),
onTap: () {
Launcher.launchAuthenticatedWebView(context: context, url: this.url, title: this.name);
Launcher.launchURLInCustomTab(url: this.url);
},
)
],

View File

@ -10,47 +10,16 @@ class Launcher {
}
}
static void launchAuthenticatedWebView({BuildContext context, String url, String title}) {
if (url.contains("?")) {
url += "&external_auth=1";
} else {
url += "?external_auth=1";
}
final flutterWebViewPlugin = new FlutterWebviewPlugin();
flutterWebViewPlugin.onStateChanged.listen((viewState) async {
if (viewState.type == WebViewState.startLoad) {
Logger.d("[WebView] Injecting external auth JS");
rootBundle.loadString('assets/js/externalAuth.js').then((js){
flutterWebViewPlugin.evalJavascript(js.replaceFirst("[token]", ConnectionManager()._token));
});
}
});
Navigator.of(context).pushNamed(
"/webview",
arguments: {
"url": "$url",
"title": "${title ?? ''}"
}
);
}
static void launchURLInCustomTab({BuildContext context, String url, bool enableDefaultShare: true, bool showPageTitle: true}) async {
try {
await launch(
"$url",
option: new CustomTabsOption(
toolbarColor: Theme.of(context).primaryColor,
toolbarColor: context != null ? Theme.of(context).primaryColor : Colors.blue,
enableDefaultShare: enableDefaultShare,
enableUrlBarHiding: true,
showPageTitle: showPageTitle,
animation: new CustomTabsAnimation.slideIn()
// or user defined animation.
/*animation: new CustomTabsAnimation(
startEnter: 'slide_up',
startExit: 'android:anim/fade_out',
endEnter: 'android:anim/fade_in',
endExit: 'slide_down',
)*/,
animation: new CustomTabsAnimation.slideIn(),
extraCustomTabs: <String>[
// ref. https://play.google.com/store/apps/details?id=org.mozilla.firefox
'org.mozilla.firefox',

View File

@ -19,11 +19,9 @@ dependencies:
charts_flutter: ^0.8.1
flutter_markdown: any
in_app_purchase: ^0.2.1+4
# flutter_svg: ^0.10.3
flutter_custom_tabs: ^0.6.0
firebase_messaging: ^5.1.6
uni_links: ^0.2.0
flutter_webview_plugin: ^0.3.8
flutter_secure_storage: ^3.3.1+1
device_info: ^0.4.0+3
flutter_local_notifications: ^0.8.4