TagSpaces is an offline, open source, document manager with tagging support
added device plugin
Ilian Sapundshiev8fba3c59effc
diff --git a/cordova/config.xml b/cordova/config.xmlindex ccece2f60..aa9789d53 100644--- a/cordova/config.xml+++ b/cordova/config.xml@@ -26,5 +26,6 @@<plugin name="cordova-plugin-whitelist" spec="^1.3.3" /><plugin name="cordova-plugin-file" spec="^6.0.1" /><preference name="AndroidPersistentFileLocation" value="Compatibility" />+ <plugin name="cordova-plugin-device" spec="^2.0.2" /><engine name="android" spec="^7.1.4" /></widget>diff --git a/cordova/package.json b/cordova/package.jsonindex 0f7961d92..45b92870d 100644--- a/cordova/package.json+++ b/cordova/package.json@@ -11,13 +11,15 @@"license": "Apache-2.0","dependencies": {"cordova-android": "^7.1.4",+ "cordova-plugin-device": "^2.0.2","cordova-plugin-file": "^6.0.1","cordova-plugin-whitelist": "^1.3.3"},"cordova": {"plugins": {"cordova-plugin-whitelist": {},- "cordova-plugin-file": {}+ "cordova-plugin-file": {},+ "cordova-plugin-device": {}},"platforms": ["android"diff --git a/cordova/platforms/android/android.json b/cordova/platforms/android/android.jsonindex 9a9db1bc0..c59950b95 100644--- a/cordova/platforms/android/android.json+++ b/cordova/platforms/android/android.json@@ -15,6 +15,10 @@{"xml": "<allow-navigation href=\"cdvfile:*\" />","count": 1+ },+ {+ "xml": "<feature name=\"Device\"><param name=\"android-package\" value=\"org.apache.cordova.device.Device\" /></feature>",+ "count": 1}]}@@ -34,6 +38,9 @@"installed_plugins": {"cordova-plugin-file": {"PACKAGE_NAME": "org.tagspaces.mobile"+ },+ "cordova-plugin-device": {+ "PACKAGE_NAME": "org.tagspaces.mobile"}},"dependent_plugins": {},@@ -210,9 +217,18 @@"cordova"],"runs": true+ },+ {+ "id": "cordova-plugin-device.device",+ "file": "plugins/cordova-plugin-device/www/device.js",+ "pluginId": "cordova-plugin-device",+ "clobbers": [+ "device"+ ]}],"plugin_metadata": {- "cordova-plugin-file": "6.0.1"+ "cordova-plugin-file": "6.0.1",+ "cordova-plugin-device": "2.0.2"}}\ No newline at end of filediff --git a/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.js b/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.jsindex 39d58d5ee..6b6a4b338 100644--- a/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.js+++ b/cordova/platforms/android/app/src/main/assets/www/cordova_plugins.js@@ -172,12 +172,21 @@ module.exports = ["cordova"],"runs": true+ },+ {+ "id": "cordova-plugin-device.device",+ "file": "plugins/cordova-plugin-device/www/device.js",+ "pluginId": "cordova-plugin-device",+ "clobbers": [+ "device"+ ]}];module.exports.metadata =// TOP OF METADATA{- "cordova-plugin-file": "6.0.1"+ "cordova-plugin-file": "6.0.1",+ "cordova-plugin-device": "2.0.2"};// BOTTOM OF METADATA});\ No newline at end of filediff --git a/cordova/platforms/android/app/src/main/assets/www/plugins/cordova-plugin-device/www/device.js b/cordova/platforms/android/app/src/main/assets/www/plugins/cordova-plugin-device/www/device.jsnew file mode 100644index 000000000..ae48e3546--- /dev/null+++ b/cordova/platforms/android/app/src/main/assets/www/plugins/cordova-plugin-device/www/device.js@@ -0,0 +1,86 @@+cordova.define("cordova-plugin-device.device", function(require, exports, module) {+/*+ *+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you under the Apache License, Version 2.0 (the+ * "License"); you may not use this file except in compliance+ * with the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing,+ * software distributed under the License is distributed on an+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ * KIND, either express or implied. See the License for the+ * specific language governing permissions and limitations+ * under the License.+ *+*/++var argscheck = require('cordova/argscheck');+var channel = require('cordova/channel');+var utils = require('cordova/utils');+var exec = require('cordova/exec');+var cordova = require('cordova');++channel.createSticky('onCordovaInfoReady');+// Tell cordova channel to wait on the CordovaInfoReady event+channel.waitForInitialization('onCordovaInfoReady');++/**+ * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the+ * phone, etc.+ * @constructor+ */+function Device () {+ this.available = false;+ this.platform = null;+ this.version = null;+ this.uuid = null;+ this.cordova = null;+ this.model = null;+ this.manufacturer = null;+ this.isVirtual = null;+ this.serial = null;++ var me = this;++ channel.onCordovaReady.subscribe(function () {+ me.getInfo(function (info) {+ // ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js+ // TODO: CB-5105 native implementations should not return info.cordova+ var buildLabel = cordova.version;+ me.available = true;+ me.platform = info.platform;+ me.version = info.version;+ me.uuid = info.uuid;+ me.cordova = buildLabel;+ me.model = info.model;+ me.isVirtual = info.isVirtual;+ me.manufacturer = info.manufacturer || 'unknown';+ me.serial = info.serial || 'unknown';+ channel.onCordovaInfoReady.fire();+ }, function (e) {+ me.available = false;+ utils.alert('[ERROR] Error initializing Cordova: ' + e);+ });+ });+}++/**+ * Get device info+ *+ * @param {Function} successCallback The function to call when the heading data is available+ * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)+ */+Device.prototype.getInfo = function (successCallback, errorCallback) {+ argscheck.checkArgs('fF', 'Device.getInfo', arguments);+ exec(successCallback, errorCallback, 'Device', 'getDeviceInfo', []);+};++module.exports = new Device();++});diff --git a/cordova/platforms/android/app/src/main/java/org/apache/cordova/device/Device.java b/cordova/platforms/android/app/src/main/java/org/apache/cordova/device/Device.javanew file mode 100644index 000000000..e9efcb49b--- /dev/null+++ b/cordova/platforms/android/app/src/main/java/org/apache/cordova/device/Device.java@@ -0,0 +1,174 @@+/*+ Licensed to the Apache Software Foundation (ASF) under one+ or more contributor license agreements. See the NOTICE file+ distributed with this work for additional information+ regarding copyright ownership. The ASF licenses this file+ to you under the Apache License, Version 2.0 (the+ "License"); you may not use this file except in compliance+ with the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing,+ software distributed under the License is distributed on an+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ KIND, either express or implied. See the License for the+ specific language governing permissions and limitations+ under the License.+*/+package org.apache.cordova.device;++import java.util.TimeZone;++import org.apache.cordova.CordovaWebView;+import org.apache.cordova.CallbackContext;+import org.apache.cordova.CordovaPlugin;+import org.apache.cordova.CordovaInterface;+import org.json.JSONArray;+import org.json.JSONException;+import org.json.JSONObject;++import android.provider.Settings;++public class Device extends CordovaPlugin {+ public static final String TAG = "Device";++ public static String platform; // Device OS+ public static String uuid; // Device UUID++ private static final String ANDROID_PLATFORM = "Android";+ private static final String AMAZON_PLATFORM = "amazon-fireos";+ private static final String AMAZON_DEVICE = "Amazon";++ /**+ * Constructor.+ */+ public Device() {+ }++ /**+ * Sets the context of the Command. This can then be used to do things like+ * get file paths associated with the Activity.+ *+ * @param cordova The context of the main Activity.+ * @param webView The CordovaWebView Cordova is running in.+ */+ public void initialize(CordovaInterface cordova, CordovaWebView webView) {+ super.initialize(cordova, webView);+ Device.uuid = getUuid();+ }++ /**+ * Executes the request and returns PluginResult.+ *+ * @param action The action to execute.+ * @param args JSONArry of arguments for the plugin.+ * @param callbackContext The callback id used when calling back into JavaScript.+ * @return True if the action was valid, false if not.+ */+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {+ if ("getDeviceInfo".equals(action)) {+ JSONObject r = new JSONObject();+ r.put("uuid", Device.uuid);+ r.put("version", this.getOSVersion());+ r.put("platform", this.getPlatform());+ r.put("model", this.getModel());+ r.put("manufacturer", this.getManufacturer());+ r.put("isVirtual", this.isVirtual());+ r.put("serial", this.getSerialNumber());+ callbackContext.success(r);+ }+ else {+ return false;+ }+ return true;+ }++ //--------------------------------------------------------------------------+ // LOCAL METHODS+ //--------------------------------------------------------------------------++ /**+ * Get the OS name.+ *+ * @return+ */+ public String getPlatform() {+ String platform;+ if (isAmazonDevice()) {+ platform = AMAZON_PLATFORM;+ } else {+ platform = ANDROID_PLATFORM;+ }+ return platform;+ }++ /**+ * Get the device's Universally Unique Identifier (UUID).+ *+ * @return+ */+ public String getUuid() {+ String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);+ return uuid;+ }++ public String getModel() {+ String model = android.os.Build.MODEL;+ return model;+ }++ public String getProductName() {+ String productname = android.os.Build.PRODUCT;+ return productname;+ }++ public String getManufacturer() {+ String manufacturer = android.os.Build.MANUFACTURER;+ return manufacturer;+ }++ public String getSerialNumber() {+ String serial = android.os.Build.SERIAL;+ return serial;+ }++ /**+ * Get the OS version.+ *+ * @return+ */+ public String getOSVersion() {+ String osversion = android.os.Build.VERSION.RELEASE;+ return osversion;+ }++ public String getSDKVersion() {+ @SuppressWarnings("deprecation")+ String sdkversion = android.os.Build.VERSION.SDK;+ return sdkversion;+ }++ public String getTimeZoneID() {+ TimeZone tz = TimeZone.getDefault();+ return (tz.getID());+ }++ /**+ * Function to check if the device is manufactured by Amazon+ *+ * @return+ */+ public boolean isAmazonDevice() {+ if (android.os.Build.MANUFACTURER.equals(AMAZON_DEVICE)) {+ return true;+ }+ return false;+ }++ public boolean isVirtual() {+ return android.os.Build.FINGERPRINT.contains("generic") ||+ android.os.Build.PRODUCT.contains("sdk");+ }++}diff --git a/cordova/platforms/android/app/src/main/res/xml/config.xml b/cordova/platforms/android/app/src/main/res/xml/config.xmlindex 728664aa4..c94a36268 100644--- a/cordova/platforms/android/app/src/main/res/xml/config.xml+++ b/cordova/platforms/android/app/src/main/res/xml/config.xml@@ -5,6 +5,9 @@<param name="onload" value="true" /></feature><allow-navigation href="cdvfile:*" />+ <feature name="Device">+ <param name="android-package" value="org.apache.cordova.device.Device" />+ </feature><name>TagSpaces</name><description>A sample Apache Cordova application that responds to the deviceready event.diff --git a/cordova/platforms/android/platform_www/cordova_plugins.js b/cordova/platforms/android/platform_www/cordova_plugins.jsindex 39d58d5ee..6b6a4b338 100644--- a/cordova/platforms/android/platform_www/cordova_plugins.js+++ b/cordova/platforms/android/platform_www/cordova_plugins.js@@ -172,12 +172,21 @@ module.exports = ["cordova"],"runs": true+ },+ {+ "id": "cordova-plugin-device.device",+ "file": "plugins/cordova-plugin-device/www/device.js",+ "pluginId": "cordova-plugin-device",+ "clobbers": [+ "device"+ ]}];module.exports.metadata =// TOP OF METADATA{- "cordova-plugin-file": "6.0.1"+ "cordova-plugin-file": "6.0.1",+ "cordova-plugin-device": "2.0.2"};// BOTTOM OF METADATA});\ No newline at end of filediff --git a/cordova/platforms/android/platform_www/plugins/cordova-plugin-device/www/device.js b/cordova/platforms/android/platform_www/plugins/cordova-plugin-device/www/device.jsnew file mode 100644index 000000000..ae48e3546--- /dev/null+++ b/cordova/platforms/android/platform_www/plugins/cordova-plugin-device/www/device.js@@ -0,0 +1,86 @@+cordova.define("cordova-plugin-device.device", function(require, exports, module) {+/*+ *+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you under the Apache License, Version 2.0 (the+ * "License"); you may not use this file except in compliance+ * with the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing,+ * software distributed under the License is distributed on an+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY+ * KIND, either express or implied. See the License for the+ * specific language governing permissions and limitations+ * under the License.+ *+*/++var argscheck = require('cordova/argscheck');+var channel = require('cordova/channel');+var utils = require('cordova/utils');+var exec = require('cordova/exec');+var cordova = require('cordova');++channel.createSticky('onCordovaInfoReady');+// Tell cordova channel to wait on the CordovaInfoReady event+channel.waitForInitialization('onCordovaInfoReady');++/**+ * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the+ * phone, etc.+ * @constructor+ */+function Device () {+ this.available = false;+ this.platform = null;+ this.version = null;+ this.uuid = null;+ this.cordova = null;+ this.model = null;+ this.manufacturer = null;+ this.isVirtual = null;+ this.serial = null;++ var me = this;++ channel.onCordovaReady.subscribe(function () {+ me.getInfo(function (info) {+ // ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js+ // TODO: CB-5105 native implementations should not return info.cordova+ var buildLabel = cordova.version;+ me.available = true;+ me.platform = info.platform;+ me.version = info.version;+ me.uuid = info.uuid;+ me.cordova = buildLabel;+ me.model = info.model;+ me.isVirtual = info.isVirtual;+ me.manufacturer = info.manufacturer || 'unknown';+ me.serial = info.serial || 'unknown';+ channel.onCordovaInfoReady.fire();+ }, function (e) {+ me.available = false;+ utils.alert('[ERROR] Error initializing Cordova: ' + e);+ });+ });+}++/**+ * Get device info+ *+ * @param {Function} successCallback The function to call when the heading data is available+ * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)+ */+Device.prototype.getInfo = function (successCallback, errorCallback) {+ argscheck.checkArgs('fF', 'Device.getInfo', arguments);+ exec(successCallback, errorCallback, 'Device', 'getDeviceInfo', []);+};++module.exports = new Device();++});diff --git a/webpack.config.renderer.cordova.js b/webpack.config.renderer.cordova.jsindex 27a3dc3df..db01e1c31 100644--- a/webpack.config.renderer.cordova.js+++ b/webpack.config.renderer.cordova.js@@ -21,6 +21,11 @@ export default merge.smart(baseConfig, {publicPath: './dist/'},+ optimization: {+ // We no not want to minimize our code. TODO remove this for production+ minimize: true+ },+node: {fs: 'empty'},