From c7c124f9b3be93f806d2bbecc5cf2390be943b33 Mon Sep 17 00:00:00 2001 From: Daniel Sogl Date: Sat, 3 Jun 2017 14:37:25 +0200 Subject: [PATCH 1/9] Create package.json --- package.json | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..94f41e9 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "cordova-plugin-clipboard", + "version": "1.0.0", + "description": "Clipboard management plugin for Cordova/PhoneGap", + "cordova": { + "id": "ionic-plugin-deploy", + "platforms": [ + "android", + "ios" + ] + }, + "repository": { + "type": "git", + "url": "git+https://github.com/danielsogl/CordovaClipboard.git" + }, + "keywords": [ + "Ionic", + "deploy", + "ecosystem:cordova", + "cordova-android", + "cordova-ios" + ], + "author": "Daniel Sogl", + "license": "MIT", + "bugs": { + "url": "https://github.com/danielsogl/CordovaClipboardissues" + }, + "homepage": "https://github.com/danielsogl/CordovaClipboard#readme" +} From 6feddd270092e9056f72a8bd92c7d156e3eca003 Mon Sep 17 00:00:00 2001 From: Daniel Sogl Date: Sat, 3 Jun 2017 14:41:10 +0200 Subject: [PATCH 2/9] Update package.json --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 94f41e9..758720d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/danielsogl/CordovaClipboard.git" + "url": "git+https://github.com/danielsogl/cordova-plugin-clipboard.git" }, "keywords": [ "Ionic", @@ -23,7 +23,7 @@ "author": "Daniel Sogl", "license": "MIT", "bugs": { - "url": "https://github.com/danielsogl/CordovaClipboardissues" + "url": "https://github.com/danielsogl/cordova-plugin-clipboard" }, - "homepage": "https://github.com/danielsogl/CordovaClipboard#readme" + "homepage": "https://github.com/danielsogl/cordova-plugin-clipboard#readme" } From 0676bf695e9a6a3ead3950d84fc2d62b9351a22b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Jun 2017 14:45:12 +0200 Subject: [PATCH 3/9] renamed plugin and add windows support --- plugin.xml | 100 ++++++++++++++++++---------------- src/android/Clipboard.java | 4 +- src/windows/ClipboardProxy.js | 40 ++++++++++++++ www/clipboard.js | 14 ++--- 4 files changed, 100 insertions(+), 58 deletions(-) create mode 100644 src/windows/ClipboardProxy.js diff --git a/plugin.xml b/plugin.xml index 4148d15..1c900b6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,59 +1,63 @@ - + - - - + + + - Clipboard + Clipboard - Clipboard management plugin for Cordova/PhoneGap + Clipboard management plugin for Cordova/PhoneGap - Verso Solutions LLC + Daniel Sogl - clipboard,copy,paste + clipboard,copy,paste - MIT + MIT - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/android/Clipboard.java b/src/android/Clipboard.java index 438ebc1..0f6236f 100644 --- a/src/android/Clipboard.java +++ b/src/android/Clipboard.java @@ -1,4 +1,4 @@ -package com.verso.cordova.clipboard; +package com.danielsogl.cordova.clipboard; import org.apache.cordova.CordovaPlugin; import org.apache.cordova.PluginResult; @@ -58,5 +58,3 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo return false; } } - - diff --git a/src/windows/ClipboardProxy.js b/src/windows/ClipboardProxy.js new file mode 100644 index 0000000..03036b1 --- /dev/null +++ b/src/windows/ClipboardProxy.js @@ -0,0 +1,40 @@ +var cordova = require('cordova'); + +module.exports = { + + copy: function(successCallback, errorCallback, args) { + var text = ""; + try { + text = args[0]; + } catch (e) { + errorCallback(e); + return; + } + + try { + var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage(); + dataPackage.setText(text); + Windows.ApplicationModel.DataTransfer.Clipboard.setContent(dataPackage); + successCallback(text); + } catch (e) { + errorCallback(e);; + } + }, + paste: function(successCallback, errorCallback, args) { + var text = ""; + + try { + var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.getContent(); + if (dataPackageView.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) { + dataPackageView.getTextAsync().then(function(value) { + text = value; + successCallback(text); + }); + } + } catch (e) { + errorCallback(e);; + } + } +}; // exports + +require("cordova/exec/proxy").add("Clipboard", module.exports); diff --git a/www/clipboard.js b/www/clipboard.js index 6c2ed7b..57cef16 100644 --- a/www/clipboard.js +++ b/www/clipboard.js @@ -2,10 +2,10 @@ var cordova = require('cordova'); /** * Clipboard plugin for Cordova - * + * * @constructor */ -function Clipboard () {} +function Clipboard() {} /** * Sets the clipboard content @@ -14,9 +14,9 @@ function Clipboard () {} * @param {Function} onSuccess The function to call in case of success (takes the copied text as argument) * @param {Function} onFail The function to call in case of error */ -Clipboard.prototype.copy = function (text, onSuccess, onFail) { - if (typeof text === "undefined" || text === null) text = ""; - cordova.exec(onSuccess, onFail, "Clipboard", "copy", [text]); +Clipboard.prototype.copy = function(text, onSuccess, onFail) { + if (typeof text === "undefined" || text === null) text = ""; + cordova.exec(onSuccess, onFail, "Clipboard", "copy", [text]); }; /** @@ -25,8 +25,8 @@ Clipboard.prototype.copy = function (text, onSuccess, onFail) { * @param {Function} onSuccess The function to call in case of success * @param {Function} onFail The function to call in case of error */ -Clipboard.prototype.paste = function (onSuccess, onFail) { - cordova.exec(onSuccess, onFail, "Clipboard", "paste", []); +Clipboard.prototype.paste = function(onSuccess, onFail) { + cordova.exec(onSuccess, onFail, "Clipboard", "paste", []); }; // Register the plugin From c66b49cac238094a1241f4e8b11b72edd0ad8cf2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Jun 2017 14:55:26 +0200 Subject: [PATCH 4/9] updated package.json --- README.md | 28 ++------------- package.json | 23 +++++++++---- plugin.xml | 96 +++++++++++++++++++++++++++------------------------- 3 files changed, 68 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 54ff59d..ba1a950 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ Clipboard ========= -Clipboard management plugin for Cordova/PhoneGap that supports iOS, Android, and Windows Phone 8. +Clipboard management plugin for Cordova/PhoneGap that supports iOS, Android, Windows, and Windows Phone 8. ## Usage Install the plugin using the CLI, for instance with PhoneGap: - phonegap local plugin add https://github.com/VersoSolutions/CordovaClipboard + phonegap local plugin add https://github.com/danielsogl/cordova-plugin-clipboard The plugin creates the object `cordova.plugins.clipboard` with the methods `copy(text, onSuccess, onError)` and `paste(onSuccess, onError)`. @@ -36,27 +36,3 @@ Example: ## Acknowledgements This plugin was inspired by [ClipboardManagerPlugin](https://github.com/jacob/ClipboardManagerPlugin) (Android) and [ClipboardPlugin](https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/ClipboardPlugin) (iOS). - -## License - -The MIT License (MIT) - -Copyright (c) 2013 Verso Solutions LLC - -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/package.json b/package.json index 758720d..f970c3d 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,12 @@ "version": "1.0.0", "description": "Clipboard management plugin for Cordova/PhoneGap", "cordova": { - "id": "ionic-plugin-deploy", + "id": "com.danielsogl.cordova.clipboard", "platforms": [ + "ios", "android", - "ios" + "wp8", + "windows" ] }, "repository": { @@ -14,16 +16,25 @@ "url": "git+https://github.com/danielsogl/cordova-plugin-clipboard.git" }, "keywords": [ - "Ionic", - "deploy", + "clipboard", + "copy", + "paste", "ecosystem:cordova", + "cordova-ios", "cordova-android", - "cordova-ios" + "cordova-wp8", + "cordova-windows" + ], + "engines": [ + { + "name": "cordova", + "version": ">=4.0.0" + } ], "author": "Daniel Sogl", "license": "MIT", "bugs": { - "url": "https://github.com/danielsogl/cordova-plugin-clipboard" + "url": "https://github.com/danielsogl/cordova-plugin-clipboard/issues" }, "homepage": "https://github.com/danielsogl/cordova-plugin-clipboard#readme" } diff --git a/plugin.xml b/plugin.xml index 1c900b6..6b577b0 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,63 +1,65 @@ - + - - - + + + - Clipboard + Clipboard - Clipboard management plugin for Cordova/PhoneGap + Clipboard management plugin for Cordova/PhoneGap - Daniel Sogl + Verso Solutions LLC - clipboard,copy,paste + clipboard,copy,paste - MIT + MIT - - - - - - - - - - - + + + - - - + + + + + + + - - - + + + - - - - - - + + + - - - - - - - + + + + + + - - + + + + + + + - - - - - - + + + + + + + + From dc6d6757307e87a6700685c27752ac3c5008bd06 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Jun 2017 14:58:54 +0200 Subject: [PATCH 5/9] renamed package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f970c3d..45097c0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "cordova-plugin-clipboard", + "name": "danielsogl-cordova-plugin-clipboard", "version": "1.0.0", "description": "Clipboard management plugin for Cordova/PhoneGap", "cordova": { From 49adbdfa8645f81304614479b0375e94686d9197 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Jun 2017 15:12:33 +0200 Subject: [PATCH 6/9] publish --- package.json | 8 ++-- src/android/Clipboard.java | 86 +++++++++++++++++++------------------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index 45097c0..5728645 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { "name": "danielsogl-cordova-plugin-clipboard", - "version": "1.0.0", + "version": "1.0.1", "description": "Clipboard management plugin for Cordova/PhoneGap", "cordova": { "id": "com.danielsogl.cordova.clipboard", "platforms": [ - "ios", "android", - "wp8", - "windows" + "ios", + "windows", + "wp8" ] }, "repository": { diff --git a/src/android/Clipboard.java b/src/android/Clipboard.java index 0f6236f..b98ed25 100644 --- a/src/android/Clipboard.java +++ b/src/android/Clipboard.java @@ -13,48 +13,48 @@ import android.content.ClipDescription; public class Clipboard extends CordovaPlugin { - - private static final String actionCopy = "copy"; - private static final String actionPaste = "paste"; - - @Override - public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { - ClipboardManager clipboard = (ClipboardManager) cordova.getActivity().getSystemService(Context.CLIPBOARD_SERVICE); - - if (action.equals(actionCopy)) { - try { - String text = args.getString(0); - ClipData clip = ClipData.newPlainText("Text", text); - - clipboard.setPrimaryClip(clip); - - callbackContext.success(text); - - return true; - } catch (JSONException e) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); - } catch (Exception e) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString())); - } - } else if (action.equals(actionPaste)) { - if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT)); - } - - try { - ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); - String text = item.getText().toString(); - - if (text == null) text = ""; - - callbackContext.success(text); - - return true; - } catch (Exception e) { - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString())); - } - } - - return false; + + private static final String actionCopy = "copy"; + private static final String actionPaste = "paste"; + + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + ClipboardManager clipboard = (ClipboardManager) cordova.getActivity().getSystemService(Context.CLIPBOARD_SERVICE); + + if (action.equals(actionCopy)) { + try { + String text = args.getString(0); + ClipData clip = ClipData.newPlainText("Text", text); + + clipboard.setPrimaryClip(clip); + + callbackContext.success(text); + + return true; + } catch (JSONException e) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); + } catch (Exception e) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString())); + } + } else if (action.equals(actionPaste)) { + if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT)); + } + + try { + ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); + String text = item.getText().toString(); + + if (text == null) text = ""; + + callbackContext.success(text); + + return true; + } catch (Exception e) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString())); + } } + + return false; + } } From ef4573207773f46fc903a4e19b6d30abbf01f93a Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Jun 2017 15:14:54 +0200 Subject: [PATCH 7/9] publish --- package.json | 14 ++++++-------- plugin.xml | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 5728645..d133296 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,10 @@ "cordova": { "id": "com.danielsogl.cordova.clipboard", "platforms": [ - "android", "ios", + "android", + "wp8", "windows", - "wp8" ] }, "repository": { @@ -25,12 +25,10 @@ "cordova-wp8", "cordova-windows" ], - "engines": [ - { - "name": "cordova", - "version": ">=4.0.0" - } - ], + "engines": [{ + "name": "cordova", + "version": ">=4.0.0" + }], "author": "Daniel Sogl", "license": "MIT", "bugs": { diff --git a/plugin.xml b/plugin.xml index 6b577b0..f2a5974 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.1"> From 5bc5cd971a0ec46ea63c56cff552a38e2370ae6b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Jun 2017 15:16:22 +0200 Subject: [PATCH 8/9] fixed json error --- package.json | 14 ++++++++------ plugin.xml | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d133296..7eae607 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "danielsogl-cordova-plugin-clipboard", - "version": "1.0.1", + "version": "1.0.2", "description": "Clipboard management plugin for Cordova/PhoneGap", "cordova": { "id": "com.danielsogl.cordova.clipboard", @@ -8,7 +8,7 @@ "ios", "android", "wp8", - "windows", + "windows" ] }, "repository": { @@ -25,10 +25,12 @@ "cordova-wp8", "cordova-windows" ], - "engines": [{ - "name": "cordova", - "version": ">=4.0.0" - }], + "engines": [ + { + "name": "cordova", + "version": ">=4.0.0" + } + ], "author": "Daniel Sogl", "license": "MIT", "bugs": { diff --git a/plugin.xml b/plugin.xml index f2a5974..e89c494 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.2"> From 2f5c490215e007f07cbe8bed9110081b1c74d076 Mon Sep 17 00:00:00 2001 From: Daniel Sogl Date: Sun, 4 Jun 2017 23:06:30 +0200 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba1a950..cc65a20 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Clipboard management plugin for Cordova/PhoneGap that supports iOS, Android, Win Install the plugin using the CLI, for instance with PhoneGap: - phonegap local plugin add https://github.com/danielsogl/cordova-plugin-clipboard + phonegap local plugin add danielsogl-cordova-plugin-clipboard The plugin creates the object `cordova.plugins.clipboard` with the methods `copy(text, onSuccess, onError)` and `paste(onSuccess, onError)`.