Giter Site home page Giter Site logo

devhotsales / cordova-plugin-webviewselector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wizcorp/cordova-plugin-webviewselector

0.0 1.0 0.0 7 KB

Cordova plugin allowing an Android app user to switch between system webview and Crosswalk's webview

License: Other

JavaScript 30.31% Java 69.69%

cordova-plugin-webviewselector's Introduction

cordova-plugin-webviewselector

This plugin is designed to allow developers that are using Crosswalk with cordova-plugin-crosswalk-webview to be able to switch dynamically between Crosswalk webview and default system webview (on Android).

Why anyone would want that?

Crosswalk being not maintained anymore, the future is in the use of system's webview. But on older devices you may want to keep a well working older version of Chromium. You may also want to let your application's users to switch themselves between engines for some reasons, like if your heuristic to select the best engine automatically depending on their device is not perfect.

How is it working?

This plugin is only changing Cordova's webview setting dynamically before the creation of the webview.

Compatibility

Currently tested with:

  • Cordova Android Engine 4.1.1.
  • Cordova CLI 6.5.0.

TODO: test on more recent versions.

Prerequisites

You need to have cordova-plugin-crosswalk-webview installed in your project.

Installation

After having added the plugin to your project, you can add the following line in your config.xml (optional):

<preference name="webviewselector-xwalkMaxSdkVersion" value="23" />

This controls which webview engine will be used by default based on Android API level. Up to this preference's value, Crosswalk will be used. Above, it will be system's webview.

If you omit this setting, default value is 23: Crosswalk will be used on all devices up to Android 6.0 and system webview starting with Android 7.0.

Usage

WebViewSelector is available on: window.cordova.plugins.WebViewSelector.

WebViewType

Contains available engine ids:

WebViewType.SYSTEM
WebViewType.CROSSWALK

currentEngine

Contains id of current engine:

var ws = window.cordova.plugins.WebViewSelector;
if (ws.currentEngine === ws.WebViewType.CROSSWALK) {
	// ...
}

availableEngines

Array of available engines ids. If Crosswalk is not installed it will only contain WebViewType.SYSTEM.

var ws = window.cordova.plugins.WebViewSelector;
if (ws.availableEngines.length > 1) {
	// we have at least 2 engines available
}

setEngine

Change webview engine. Application needs to be restarted for change to take effect, window.location.reload() being not enough for that. It's possible to kill the application programmatically with navigator.app.exitApp().

var ws = window.cordova.plugins.WebViewSelector;
ws.setEngine(ws.WebViewType.SYSTEM, function (error) {
	if (error) {
		return console.error(error);
	}
	alert('Kill and restart application for change to take effect.');
});

Manual switch

In addition to javascript interface, user can connect his phone to a computer and drop a file named webview.txt containg 0 for system webview or 1 for Crosswalk inside Internal storage/Android/data/yourAppId/files/. This setting will prevail over any other (TODO: it should have an effect only during the first restart and be automatically deleted).

cordova-plugin-webviewselector's People

Contributors

aluferraz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.