'初始化提交'

This commit is contained in:
2025-08-11 22:55:39 +08:00
parent 3deaf322c6
commit 9ec6daa82b
212 changed files with 45916 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
Copyright (c) 2015 Rareloop Ltd
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.

View File

@@ -0,0 +1,31 @@
# Cordova App Version Plugin
Cordova/PhoneGap plugin for accessing the native app's version and build number within JavaScript. The values are bootstrapped at app load and can be used synchronously.
## Supported Platforms
- iOS
- Android
## Installation
The plugin can be installed with the Cordova CLI:
```shell
cordova plugin add cordova-plugin-appversion
```
The plugin is hosted on NPM so requires Cordova CLI `5.0.0` as a minimum. If you have any issues installing, make sure you have the most upto date version of Cordova from NPM:
```shell
npm install -g cordova
```
## Usage
After `deviceReady` has fired you'll be able to access a new object in the global scope that contains both the app version and build number.
```javascript
console.log(AppVersion.version); // e.g. "1.2.3"
console.log(AppVersion.build); // e.g. 1234
```

View File

@@ -0,0 +1,29 @@
{
"name": "cordova-plugin-appversion",
"version": "1.0.0",
"description": "Access the native app version & build number in JavaScript",
"cordova": {
"id": "cordova-plugin-appversion",
"platforms": [
"android",
"ios"
]
},
"repository": {
"type": "git",
"url": "https://github.com/Rareloop/cordova-plugin-app-version.git"
},
"keywords": [
"cordova",
"appversion",
"ecosystem:cordova",
"cordova-ios",
"cordova-android"
],
"author": "Rareloop (http://rareloop.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/Rareloop/cordova-plugin-app-version/issues"
},
"homepage": "https://github.com/Rareloop/cordova-plugin-app-version"
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-appversion" version="1.0.0">
<name>App Version</name>
<description>Expose the native app version to JavaScript</description>
<license>MIT</license>
<js-module src="www/app-version.js" name="RareloopAppVersion">
<clobbers target="AppVersion" />
</js-module>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="RareloopAppVersion">
<param name="ios-package" value="RareloopAppVersion"/>
</feature>
</config-file>
<header-file src="src/ios/RareloopAppVersion.h" />
<source-file src="src/ios/RareloopAppVersion.m" />
</platform>
<platform name="android">
<config-file target="config.xml" parent="/*">
<feature name="RareloopAppVersion">
<param name="android-package" value="com.rareloop.cordova.appversion.RareloopAppVersion"/>
</feature>
</config-file>
<source-file src="src/android/RareloopAppVersion.java" target-dir="src/com/rareloop/cordova/appversion" />
</platform>
</plugin>

View File

@@ -0,0 +1,81 @@
/**
* Copyright (c) 2015 Rareloop Ltd
*
* 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.
*/
package com.rareloop.cordova.appversion;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.PluginResult;
import android.util.TypedValue;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager;
import android.util.Log;
/**
* Cordova plugin that allows for an arbitrarly sized and positioned WebView to be shown ontop of the canvas
*/
public class RareloopAppVersion extends CordovaPlugin {
private static final String TAG = "RareloopAppVersion";
/**
* Executes the request and returns PluginResult
*
* @param action
* @param args
* @param callbackContext
* @return boolean
* @throws JSONException
*/
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
/**
* appVersion
*/
if (action.equals("getAppVersion")) {
try {
PackageManager packageManager = this.cordova.getActivity().getPackageManager();
JSONObject r = new JSONObject();
r.put("version", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionName);
r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
callbackContext.success(r);
} catch (NameNotFoundException e) {
callbackContext.error("Exception thrown");
}
return true;
}
// Default response to say the action hasn't been handled
return false;
}
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2015 Rareloop Ltd
*
* 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.
*/
#import <Cordova/CDV.h>
@interface RareloopAppVersion : CDVPlugin <UIWebViewDelegate>
{
}
- (void)getAppVersion:(CDVInvokedUrlCommand*)command;
@end

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) 2015 Rareloop Ltd
*
* 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.
*/
#import "RareloopAppVersion.h"
#import <Cordova/CDV.h>
@implementation RareloopAppVersion
/**
* Get the app version and build number
*
* @param {CDVInvokedUrlCommand*} command [description]
*/
- (void)getAppVersion:(CDVInvokedUrlCommand*)command
{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *appVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
NSNumber *buildNumber = [infoDict objectForKey:@"CFBundleVersion"];
// Build a plugin response
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: @{@"version": appVersion, @"build": buildNumber}];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end

View File

@@ -0,0 +1,68 @@
/**
* Copyright (c) 2015 Rareloop Ltd
*
* 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.
*/
var exec = require('cordova/exec');
var channel = require('cordova/channel');
var utils = require('cordova/utils');
channel.createSticky('onCordovaAppVersionReady');
// Wait on the onCordovaAppVersionReady event
channel.waitForInitialization('onCordovaAppVersionReady');
/**
* Object representing the app's native version and build number
* @constructor
*/
var RareloopAppVersion = function () {
this.version = null;
this.build = null;
this.available = false;
var _this = this;
channel.onCordovaReady.subscribe(function() {
_this.getInfo(function(info) {
_this.available = true;
_this.version = info.version;
_this.build = parseInt(info.build, 10);
channel.onCordovaAppVersionReady.fire();
},function(e) {
_this.available = false;
utils.alert("[ERROR] Error initializing Version Plugin: " + e);
});
});
};
/**
* Get the app version
*
* @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)
*/
RareloopAppVersion.prototype.getInfo = function(successCallback, errorCallback) {
exec(successCallback, errorCallback, "RareloopAppVersion", "getAppVersion", []);
};
// Export the module
module.exports = new RareloopAppVersion();