From e0ba24662b631394b4076ac39fad970447879f8f Mon Sep 17 00:00:00 2001 From: PliablePixels Date: Fri, 3 Jul 2015 08:31:13 -0400 Subject: Added plugin that picks up version from config.xml and displays in app --- config.xml | 2 +- .../CHANGELOG.md | 39 +++++++++++ .../uk.co.whiteoctober.cordova.appversion/LICENSE | 20 ++++++ .../README.md | 71 +++++++++++++++++++ .../uk.co.whiteoctober.cordova.appversion/VERSION | 1 + .../plugin.xml | 79 ++++++++++++++++++++++ .../src/android/AppVersion.java | 45 ++++++++++++ .../src/ios/AppVersion.h | 13 ++++ .../src/ios/AppVersion.m | 47 +++++++++++++ .../src/windows8/AppVersionProxy.js | 7 ++ .../src/wp8/AppVersion.cs | 24 +++++++ .../www/AppVersionPlugin.js | 48 +++++++++++++ www/js/app.js | 13 ++++ www/templates/log.html | 6 +- 14 files changed, 411 insertions(+), 4 deletions(-) create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/CHANGELOG.md create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/LICENSE create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/README.md create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/VERSION create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/plugin.xml create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/src/android/AppVersion.java create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.h create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.m create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/src/windows8/AppVersionProxy.js create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/src/wp8/AppVersion.cs create mode 100644 plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js diff --git a/config.xml b/config.xml index 6f92af80..794ec7e4 100644 --- a/config.xml +++ b/config.xml @@ -1,5 +1,5 @@ - + zmNinja High performance ZoneMinder client diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/CHANGELOG.md b/plugins/uk.co.whiteoctober.cordova.appversion/CHANGELOG.md new file mode 100644 index 00000000..dcc0129a --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/CHANGELOG.md @@ -0,0 +1,39 @@ +### 0.1.7 + +* Add getPackageName feature (thanks to @gprasanth) +* Add getAppName feature (thanks to @mirko77) +* Fix for windows 8 (thanks to @deliriousrhino) +* Fix version number in plugin.xml file + +### 0.1.6 + +* Split into two functions getAppVersion.getVersionNumber() and getAppVersion.getVersionCode() to return build number +* Fix a deprecation warning in iOS version + +### 0.1.5 + +* iOS: Return version number but log and fall back to build number if it is nil (thanks to [Eddy Verbruggen](https://github.com/EddyVerbruggen)) + +### 0.1.4 + +* Return version number, not build number on iOS (thanks to http://www.humancopy.net) +* Support for Windows phone 8 (thanks to Cristi Badila / Gediminas Šaltenis) +* Support for AngularJS as well as jQuery (thanks to Matias Singers, [Red Ape Solutions](http://www.redapesolutions.com/)) + +### 0.1.3 + +* Fixes to Android for Corova 3 and above (thanks to AxoInsanit) + +### 0.1.2 + +* Updated for Cordova 3 and above (thanks to Russell Keith-Magee [freakboy3742](https://github.com/freakboy3742) + +### 0.1.1 + +* Improved README +* Bug fix for non-jQuery use +* Tidy plugin.xml + +### 0.1.0 + +* First release diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/LICENSE b/plugins/uk.co.whiteoctober.cordova.appversion/LICENSE new file mode 100644 index 00000000..484859fd --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2013 White October + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/README.md b/plugins/uk.co.whiteoctober.cordova.appversion/README.md new file mode 100644 index 00000000..2afff928 --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/README.md @@ -0,0 +1,71 @@ +# Cordova AppVersion plugin + +Reads the version of your app from the target build settings. + +## Installation + +### With cordova-cli + +If you are using [cordova-cli](https://github.com/apache/cordova-cli), install +with: + + cordova plugin add https://github.com/whiteoctober/cordova-plugin-app-version.git + +### With plugman + +With a plain [plugman](https://github.com/apache/cordova-plugman), you should be +able to install with something like: + + plugman --platform --project --plugin https://github.com/whiteoctober/cordova-plugin-app-version.git + +### Manually in iOS + +TODO: Write these instructions + +### Manually in Android + +TODO: Write these instructions + +## Use from Javascript + +If you are using jQuery or AngularJS, promise style is supported. Use something like: + + cordova.getAppVersion.getVersionNumber().then(function (version) { + $('.version').text(version); + }); + +If not, pass a callback function: + + cordova.getAppVersion.getVersionNumber(function (version) { + alert(version); + }); + +In addition to the version number you can also retrieve other details about your application: + +### getAppName + +Returns the name of the app. E.g. "My Awesome App" + +### getPackageName + +Returns the package name of the app - the reversed domain name app identifier like com.example.myawesomeapp + +### getVersionCode + +Returns the build identifier of the app + +### getVersionNumber + +Returns the version number of the app + +## Credits + +Written by [Robert (Jamie) Munro](http://twitter.com/rjmunro) at +[White October](http://whiteoctober.co.uk/) + +Various others have contributed fixes and new features. See the CHANGELOG.md for details. + +Original code based on the following Stack Overflow posts: + +* [iOS](http://stackoverflow.com/a/14713364/3408) +* [Android](http://stackoverflow.com/a/3637686/3408) diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/VERSION b/plugins/uk.co.whiteoctober.cordova.appversion/VERSION new file mode 100644 index 00000000..11808190 --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/VERSION @@ -0,0 +1 @@ +0.1.7 diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/plugin.xml b/plugins/uk.co.whiteoctober.cordova.appversion/plugin.xml new file mode 100644 index 00000000..8ff4c5eb --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/plugin.xml @@ -0,0 +1,79 @@ + + + + AppVersion + + This plugin will return the version of your App that you have set in + packaging it. I.e. it will always match the version in the app store. + + MIT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/src/android/AppVersion.java b/plugins/uk.co.whiteoctober.cordova.appversion/src/android/AppVersion.java new file mode 100644 index 00000000..204ed7e8 --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/src/android/AppVersion.java @@ -0,0 +1,45 @@ +package uk.co.whiteoctober.cordova; + +import org.apache.cordova.CordovaPlugin; +import org.apache.cordova.CallbackContext; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.PackageManager; + +public class AppVersion extends CordovaPlugin { + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + + try { + if (action.equals("getAppName")) { + PackageManager packageManager = this.cordova.getActivity().getPackageManager(); + ApplicationInfo app = packageManager.getApplicationInfo(this.cordova.getActivity().getPackageName(), 0); + callbackContext.success((String)packageManager.getApplicationLabel(app)); + return true; + } + if (action.equals("getPackageName")) { + callbackContext.success(this.cordova.getActivity().getPackageName()); + return true; + } + if (action.equals("getVersionNumber")) { + PackageManager packageManager = this.cordova.getActivity().getPackageManager(); + callbackContext.success(packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionName); + return true; + } + if (action.equals("getVersionCode")) { + PackageManager packageManager = this.cordova.getActivity().getPackageManager(); + callbackContext.success(packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode); + return true; + } + return false; + } catch (NameNotFoundException e) { + callbackContext.success("N/A"); + return true; + } + } + +} diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.h b/plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.h new file mode 100644 index 00000000..87c0330b --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.h @@ -0,0 +1,13 @@ +#import + +@interface AppVersion : CDVPlugin + +- (void)getAppName:(CDVInvokedUrlCommand*)command; + +- (void)getPackageName:(CDVInvokedUrlCommand*)command; + +- (void)getVersionNumber:(CDVInvokedUrlCommand*)command; + +- (void)getVersionCode:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.m b/plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.m new file mode 100644 index 00000000..a73c78f9 --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/src/ios/AppVersion.m @@ -0,0 +1,47 @@ +#import "AppVersion.h" +#import + +@implementation AppVersion + +- (void)getAppName : (CDVInvokedUrlCommand *)command +{ + NSString * callbackId = command.callbackId; + NSString * version =[[[NSBundle mainBundle]infoDictionary]objectForKey :@"CFBundleDisplayName"]; + CDVPluginResult * pluginResult =[CDVPluginResult resultWithStatus : CDVCommandStatus_OK messageAsString : version]; + [self.commandDelegate sendPluginResult : pluginResult callbackId : callbackId]; +} + +- (void)getPackageName:(CDVInvokedUrlCommand*)command +{ + NSString* callbackId = command.callbackId; + NSString* packageName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:packageName]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; +} + +- (void)getVersionNumber:(CDVInvokedUrlCommand*)command +{ + NSString* callbackId = command.callbackId; + NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; + if (version == nil) { + NSLog(@"CFBundleShortVersionString was nil, attempting CFBundleVersion"); + version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; + if (version == nil) { + NSLog(@"CFBundleVersion was also nil, giving up"); + // not calling error callback here to maintain backward compatibility + } + } + + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:version]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; +} + +- (void)getVersionCode:(CDVInvokedUrlCommand*)command +{ + NSString* callbackId = command.callbackId; + NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:version]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:callbackId]; +} + +@end diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/src/windows8/AppVersionProxy.js b/plugins/uk.co.whiteoctober.cordova.appversion/src/windows8/AppVersionProxy.js new file mode 100644 index 00000000..3b4c50ee --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/src/windows8/AppVersionProxy.js @@ -0,0 +1,7 @@ +AppVersionProxy = { + getVersionNumber: function (successCallback, failCallback, args) { + var version = Windows.ApplicationModel.Package.current.id.version; + successCallback([version.major, version.minor, version.build, version.revision].join('.')); + } +}; +cordova.commandProxy.add("AppVersion", AppVersionProxy); diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/src/wp8/AppVersion.cs b/plugins/uk.co.whiteoctober.cordova.appversion/src/wp8/AppVersion.cs new file mode 100644 index 00000000..2f3d2c95 --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/src/wp8/AppVersion.cs @@ -0,0 +1,24 @@ +using System; +using System.Windows; +using System.Windows.Navigation; +using Microsoft.Phone.Controls; +using WPCordovaClassLib.Cordova; +using WPCordovaClassLib.Cordova.Commands; +using WPCordovaClassLib.Cordova.JSON; +using Windows.ApplicationModel; +using System.Xml.Linq; + +namespace Cordova.Extension.Commands +{ + public class AppVersion : BaseCommand + { + public void getVersionNumber(string empty) + { + //Windows.ApplicationModel.Package.current.id.version is NOT working in Windows Phone 8 + //Workaround based on http://stackoverflow.com/questions/14371275/how-can-i-get-my-windows-store-apps-title-and-version-info + String version= XDocument.Load("WMAppManifest.xml").Root.Element("App").Attribute("Version").Value; + + this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, version)); + } + } +} diff --git a/plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js b/plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js new file mode 100644 index 00000000..3e395260 --- /dev/null +++ b/plugins/uk.co.whiteoctober.cordova.appversion/www/AppVersionPlugin.js @@ -0,0 +1,48 @@ +/*jslint indent: 2 */ +/*global window, jQuery, angular, cordova */ +"use strict"; + +// Returns a jQuery or AngularJS deferred object, or pass a success and fail callbacks if you don't want to use jQuery or AngularJS +var getPromisedCordovaExec = function (command, success, fail) { + var toReturn, deferred, injector, $q; + if (success === undefined) { + if (window.jQuery) { + deferred = jQuery.Deferred(); + toReturn = deferred; + } else if (window.angular) { + injector = angular.injector(["ng"]); + $q = injector.get("$q"); + deferred = $q.defer(); + toReturn = deferred.promise; + } else { + return console.error('AppVersion either needs a success callback, or jQuery/AngularJS defined for using promises'); + } + success = deferred.resolve; + fail = deferred.reject; + } + // 5th param is NOT optional. must be at least empty array + cordova.exec(success, fail, "AppVersion", command, []); + return toReturn; +}; + +var getAppVersion = function (success, fail) { + return getPromisedCordovaExec('getVersionNumber', success, fail); +}; + +getAppVersion.getAppName = function (success, fail) { + return getPromisedCordovaExec('getAppName', success, fail); +}; + +getAppVersion.getPackageName = function (success, fail) { + return getPromisedCordovaExec('getPackageName', success, fail); +}; + +getAppVersion.getVersionNumber = function (success, fail) { + return getPromisedCordovaExec('getVersionNumber', success, fail); +}; + +getAppVersion.getVersionCode = function (success, fail) { + return getPromisedCordovaExec('getVersionCode', success, fail); +}; + +module.exports = getAppVersion; diff --git a/www/js/app.js b/www/js/app.js index 6e7b72ed..3abcb634 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -3,6 +3,7 @@ /* global cordova,StatusBar,angular,console */ +var appVersion = "0.0.0"; // core app start stuff angular.module('zmApp', [ 'ionic', @@ -12,6 +13,7 @@ angular.module('zmApp', [ ]) + //------------------------------------------------------------------ // this directive will be load any time an image completes loading // via img tags where this directive is added (I am using this in @@ -220,6 +222,8 @@ angular.module('zmApp', [ console.log("**** DEVICE READY ***"); + + $fileLogger.checkFile().then(function(resp) { if (parseInt(resp.size) > 50000) { @@ -240,7 +244,15 @@ angular.module('zmApp', [ $fileLogger.setStorageFilename('zmNinjaLog.txt'); + if (window.cordova) + { + cordova.getAppVersion(function(version) { + appVersion = version; + ZMDataModel.zmLog ("zmNinja Version: " + appVersion); + ZMDataModel.setAppVersion(appVersion); + }); + } setTimeout(function () { if (window.cordova) @@ -290,6 +302,7 @@ angular.module('zmApp', [ } + }); //platformReady diff --git a/www/templates/log.html b/www/templates/log.html index 102877ae..913094d2 100644 --- a/www/templates/log.html +++ b/www/templates/log.html @@ -9,8 +9,8 @@ -
-            {{zmLog.logString}}
-        
+ zmNinja Version: {{zmAppVersion}}
+ +
{{zmLog.logString}}
-- cgit v1.2.3