Initial commit
This commit is contained in:
commit
c05f3be5a7
28
.appveyor.yml
Normal file
28
.appveyor.yml
Normal file
@ -0,0 +1,28 @@
|
||||
# appveyor file
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
|
||||
max_jobs: 1
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
init:
|
||||
- git config --global core.autocrlf true
|
||||
|
||||
image:
|
||||
- Visual Studio 2017
|
||||
|
||||
environment:
|
||||
nodejs_version: "4"
|
||||
matrix:
|
||||
- PLATFORM: windows-10-store
|
||||
JUST_BUILD: --justBuild
|
||||
install:
|
||||
- npm cache clean -f
|
||||
- node --version
|
||||
- npm install -g cordova-paramedic@https://github.com/apache/cordova-paramedic.git
|
||||
- npm install -g cordova
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- cordova-paramedic --config pr\%PLATFORM% --plugin . %JUST_BUILD%
|
28
.gitignore
vendored
Normal file
28
.gitignore
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
#If ignorance is bliss, then somebody knock the smile off my face
|
||||
|
||||
*.csproj.user
|
||||
*.suo
|
||||
*.cache
|
||||
Thumbs.db
|
||||
*.DS_Store
|
||||
|
||||
*.bak
|
||||
*.cache
|
||||
*.log
|
||||
*.swp
|
||||
*.user
|
||||
.idea
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
node_modules
|
||||
|
||||
/tests/ios/CDVSplashScreenTest/CDVSplashScreenTest.xcodeproj/xcuserdata/
|
||||
|
||||
/tests/ios/CDVSplashScreenTest.xcworkspace/xcuserdata/
|
1
.jshintignore
Normal file
1
.jshintignore
Normal file
@ -0,0 +1 @@
|
||||
tests/ios
|
16
.jshintrc
Normal file
16
.jshintrc
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"browser": true
|
||||
, "devel": true
|
||||
, "bitwise": true
|
||||
, "undef": true
|
||||
, "trailing": true
|
||||
, "quotmark": false
|
||||
, "indent": 4
|
||||
, "unused": "vars"
|
||||
, "latedef": "nofunc"
|
||||
, "globals": {
|
||||
"module": false,
|
||||
"exports": false,
|
||||
"require": false
|
||||
}
|
||||
}
|
98
.travis.yml
Normal file
98
.travis.yml
Normal file
@ -0,0 +1,98 @@
|
||||
sudo: false
|
||||
addons:
|
||||
jwt:
|
||||
secure: UmbBQ73ydIzhTCfaTb/g0beTwnOHjYxlILmQYK2Tl9Gna/KbpawiVmbloX1eZakevkeYgzQmAHEF0LyDINy5AUk97azYeP0Sz/IOjIDfXAdc6U6sZb7BScneBMt6ET/hCprG4f3mbmleQ+gx+dmNWez6rlb3Xu+XWfJuwDfAWm0=
|
||||
env:
|
||||
global:
|
||||
- SAUCE_USERNAME=snay
|
||||
- TRAVIS_NODE_VERSION="4.2"
|
||||
matrix:
|
||||
include:
|
||||
- env: PLATFORM=browser-chrome
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=browser-firefox
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=browser-safari
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=browser-edge
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: TEST_DIR=.
|
||||
language: objective-c
|
||||
osx_image: xcode7
|
||||
- env: TEST_DIR=./tests/ios
|
||||
language: objective-c
|
||||
osx_image: xcode7
|
||||
- env: PLATFORM=ios-9.3
|
||||
os: osx
|
||||
osx_image: xcode7.3
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=ios-10.0
|
||||
os: osx
|
||||
osx_image: xcode7.3
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=android-4.4
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- extra-android-m2repository
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-5.1
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- extra-android-m2repository
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-6.0
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- extra-android-m2repository
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-7.0
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- extra-android-m2repository
|
||||
- build-tools-26.0.2
|
||||
before_install:
|
||||
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm
|
||||
&& git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm
|
||||
install $TRAVIS_NODE_VERSION
|
||||
- node --version
|
||||
- if [[ "$PLATFORM" =~ android ]]; then gradle --version; fi
|
||||
- if [[ "$PLATFORM" =~ ios ]]; then npm install -g ios-deploy; fi
|
||||
- if [[ "$PLATFORM" =~ android ]]; then echo y | android update sdk -u --filter android-22,android-23,android-24,android-25,android-26;
|
||||
fi
|
||||
- git clone https://github.com/apache/cordova-paramedic /tmp/paramedic && pushd /tmp/paramedic
|
||||
&& npm install && popd
|
||||
- npm install -g cordova
|
||||
install:
|
||||
- npm install
|
||||
script:
|
||||
- if [[ "$TEST_DIR" != "" ]];
|
||||
then cd $TEST_DIR && npm install && (npm test || npm test);
|
||||
else node /tmp/paramedic/main.js --config pr/$PLATFORM --plugin $(pwd) --shouldUseSauce
|
||||
--buildName travis-plugin-splashscreen-$TRAVIS_JOB_NUMBER;
|
||||
fi
|
204
LICENSE
Normal file
204
LICENSE
Normal file
@ -0,0 +1,204 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed 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.
|
||||
|
||||
Based on cordova-plugin-splashscreen by Apache Cordova
|
89
README.md
Normal file
89
README.md
Normal file
@ -0,0 +1,89 @@
|
||||
cordova-plugin-timer
|
||||
============================
|
||||
Cordova native timer plugin
|
||||
|
||||
### Installation
|
||||
cordova plugin add cordova-plugin-timer
|
||||
|
||||
// you may also install directly from this repo
|
||||
cordova plugin add https://github.com/kitolog/cordova-plugin-timer
|
||||
|
||||
## Sample usage
|
||||
Here is simple example of how to connect to remote server, consume data from it and close the connection.
|
||||
|
||||
Create instance of Socket type:
|
||||
```
|
||||
var timer = new window.nativeTimer();
|
||||
```
|
||||
|
||||
Set data consumer, error and close handlers:
|
||||
```
|
||||
timer.onTick = function(tick) {
|
||||
// invoked on tick
|
||||
};
|
||||
timer.onError = function(errorMessage) {
|
||||
// invoked after error occurs
|
||||
};
|
||||
timer.onStop during connection = function(hasError) {
|
||||
// invoked after stop
|
||||
};
|
||||
```
|
||||
Start timer with delay 1ms and repeat 1000ms
|
||||
```
|
||||
timer.start(
|
||||
1,
|
||||
1000,
|
||||
function() {
|
||||
// invoked after successful start
|
||||
},
|
||||
function(errorMessage) {
|
||||
// invoked after unsuccessful start
|
||||
});
|
||||
```
|
||||
|
||||
stop the timer
|
||||
```
|
||||
timer.stop();
|
||||
```
|
||||
|
||||
## API
|
||||
### Event handlers
|
||||
#### `onTick: (data: int) => void`
|
||||
Invoked after new tick is received by the timer.
|
||||
|
||||
#### `onStop: (hasError: boolean) => void`
|
||||
Invoked after timer was stopped.
|
||||
|
||||
#### `onError: (message: string) => void`
|
||||
Invoked when some error occurs during timer process.
|
||||
|
||||
#### `on: (eventName: string, callback: function) => void`
|
||||
Syntax sugar for the event handlers (onTick, onStop, onError)
|
||||
eventName: `error`, `tick`, `stop`
|
||||
|
||||
### Methods
|
||||
#### `start(delay, interval, onSuccess?, onError?): void`
|
||||
Establishes connection with the remote host.
|
||||
|
||||
| parameter | type | description |
|
||||
| ----------- |-----------------------------|--------------|
|
||||
| `delay` | `number` | timer delay | |
|
||||
| `interval` | `number` | timer tick interval |
|
||||
| `onSuccess` | `() => void` | Success callback - called after successfull timer start. (optional)|
|
||||
| `onError` | `(message: string) => void` | Error callback - called when some error occurs during timer start. (optional)|
|
||||
|
||||
|
||||
#### `stop(onSuccess?, onError?): void`
|
||||
Closes the connection. `onClose` event handler is called when connection is successfuly closed.
|
||||
|
||||
| parameter | type | description |
|
||||
| ----------- |-----------------------------|--------------|
|
||||
| `onSuccess` | `() => void` | Success callback, called after timer was stopped. (optional)|
|
||||
| `onError` | `(message: string) => void` | Error callback, called when some error occurs during this procedure. (optional)|
|
||||
|
||||
|
||||
|
||||
## What's new
|
||||
- 1.0.0 - initial code
|
||||
- 1.0.1 - added common event handler
|
||||
- 1.0.2 - updated types
|
0
RELEASENOTES.md
Normal file
0
RELEASENOTES.md
Normal file
1071
package-lock.json
generated
Normal file
1071
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
58
package.json
Normal file
58
package.json
Normal file
@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "cordova-plugin-zip-compression",
|
||||
"version": "1.0.0",
|
||||
"description": "Cordova Zip Plugin",
|
||||
"types": "./types/index.d.ts",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-zip-compression",
|
||||
"platforms": [
|
||||
"android",
|
||||
"ios"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kitolog/cordova-plugin-zip-compression"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/kitolog/cordova-plugin-zip-compression"
|
||||
},
|
||||
"keywords": [
|
||||
"cordova",
|
||||
"zip",
|
||||
"archhive",
|
||||
"native",
|
||||
"native timer",
|
||||
"ios timer",
|
||||
"android timer",
|
||||
"cordova timer",
|
||||
"android interval",
|
||||
"ios interval",
|
||||
"cordova interval",
|
||||
"cordova-android",
|
||||
"cordova-ios"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "npm run jshint",
|
||||
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
|
||||
},
|
||||
"engines": {
|
||||
"cordovaDependencies": {
|
||||
"2.0.0": {
|
||||
"cordova-android": ">=3.6.0"
|
||||
},
|
||||
"4.0.0": {
|
||||
"cordova-android": ">=3.6.0"
|
||||
},
|
||||
"6.0.0": {
|
||||
"cordova": ">100"
|
||||
}
|
||||
}
|
||||
},
|
||||
"author": "kitolog",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"jshint": "^2.6.0"
|
||||
}
|
||||
}
|
68
plugin.xml
Normal file
68
plugin.xml
Normal file
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-zip-archive" version="1.0.0">
|
||||
<name>Zip archive</name>
|
||||
<description>Cordova zip archive plugin</description>
|
||||
<license>Apache 2.0</license>
|
||||
<keywords>cordova,zip,archive,plugin,native,android,ios</keywords>
|
||||
<repo>https://github.com/kitolog/cordova-plugin-zip-archive</repo>
|
||||
<issue>https://github.com/kitolog/cordova-plugin-zip-archive</issue>
|
||||
|
||||
<engines>
|
||||
<engine name="cordova-android" version=">=3.6.0"/><!-- Requires CordovaPlugin.preferences -->
|
||||
<engine name="cordova-ios" version=">=4.0.0"/>
|
||||
</engines>
|
||||
|
||||
<js-module src="www/ziparchive.js" name="ZipArchive">
|
||||
<clobbers target="window.zipArchive"/>
|
||||
</js-module>
|
||||
|
||||
<!-- android -->
|
||||
<platform name="android">
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="ZipArchive">
|
||||
<param name="android-package" value="com.hqsoftwarelab.ziparchive.ZipArchivePlugin"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/android/ZipArchiveAdapter.java" target-dir="src/com/hqsoftwarelab/ziparchive"/>
|
||||
<source-file src="src/android/ZipArchiveAdapterImpl.java" target-dir="src/com/hqsoftwarelab/ziparchive"/>
|
||||
<source-file src="src/android/ZipArchivePlugin.java" target-dir="src/com/hqsoftwarelab/ziparchive"/>
|
||||
<source-file src="src/android/Consumer.java" target-dir="src/com/hqsoftwarelab/ziparchive"/>
|
||||
</platform>
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="ZipArchive">
|
||||
<param name="ios-package" value="ZipArchivePlugin"/>
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<framework src="SSZipArchive" type="podspec" spec="~> 2.0.0" />
|
||||
|
||||
<header-file src="src/ios/ZipArchiveAdapter.h"/>
|
||||
<source-file src="src/ios/ZipArchiveAdapter.m"/>
|
||||
<source-file src="src/ios/ZipArchivePlugin.h"/>
|
||||
<source-file src="src/ios/ZipArchivePlugin.m"/>
|
||||
</platform>
|
||||
</plugin>
|
22
src/android/Consumer.java
Normal file
22
src/android/Consumer.java
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2019, kitolog
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog. may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
package com.hqsoftwarelab.ziparchive;
|
||||
|
||||
public interface Consumer<T> {
|
||||
void accept(T t);
|
||||
}
|
32
src/android/ZipArchiveAdapter.java
Normal file
32
src/android/ZipArchiveAdapter.java
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) 2019, kitolog
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
package com.hqsoftwarelab.ziparchive;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ZipArchiveAdapter {
|
||||
public void zip(String zipFile, ArrayList<String> files) throws IOException;
|
||||
// public void zip(String zipFile, String[] files) throws IOException;
|
||||
public void stop();
|
||||
public void setZipEventHandler(Consumer<String> startEventHandler);
|
||||
public void setProgressHandler(Consumer<Integer> progressHandler);
|
||||
public void setStopEventHandler(Consumer<Boolean> stopEventHandler);
|
||||
public void setErrorEventHandler(Consumer<String> errorEventHandler);
|
||||
}
|
141
src/android/ZipArchiveAdapterImpl.java
Normal file
141
src/android/ZipArchiveAdapterImpl.java
Normal file
@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Copyright (c) 2019, kitolog
|
||||
* All rights reserved.
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
package com.hqsoftwarelab.ziparchive;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class ZipArchiveAdapterImpl implements ZipArchiveAdapter {
|
||||
|
||||
private Consumer<String> zipEventHandler;
|
||||
private Consumer<Integer> progressHandler;
|
||||
private Consumer<Boolean> stopEventHandler;
|
||||
private Consumer<String> errorEventHandler;
|
||||
|
||||
private Handler handler = new Handler();
|
||||
private Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
invokeProgressHandler(2);
|
||||
}
|
||||
};
|
||||
|
||||
public ZipArchiveAdapterImpl() {
|
||||
}
|
||||
|
||||
private static int BUFFER_SIZE = 6 * 1024;
|
||||
|
||||
@Override
|
||||
public void zip(String zipFile, ArrayList<String> filesList) throws IOException {
|
||||
|
||||
FileOutputStream fileOutputStream = null;
|
||||
ZipOutputStream zipOutputStream = null;
|
||||
FileInputStream fileInputStream = null;
|
||||
if (filesList.isEmpty())
|
||||
invokeExceptionHandler("No files found");
|
||||
try {
|
||||
|
||||
zipFile = zipFile.replace("file:///", "/");
|
||||
|
||||
File file = new File(zipFile);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
fileOutputStream = new FileOutputStream(file, false);
|
||||
zipOutputStream = new ZipOutputStream(fileOutputStream);
|
||||
for (String filePath : filesList) {
|
||||
filePath = filePath.replace("file:///", "/");
|
||||
fileInputStream = new FileInputStream(filePath);
|
||||
ZipEntry zipEntry = new ZipEntry(filePath.substring(filePath.lastIndexOf("/") + 1));
|
||||
zipOutputStream.putNextEntry(zipEntry);
|
||||
byte[] tmp = new byte[BUFFER_SIZE];
|
||||
int size = 0;
|
||||
while ((size = fileInputStream.read(tmp)) != -1) {
|
||||
zipOutputStream.write(tmp, 0, size);
|
||||
}
|
||||
zipOutputStream.flush();
|
||||
fileInputStream.close();
|
||||
}
|
||||
zipOutputStream.close();
|
||||
fileOutputStream.close();
|
||||
invokeZipEventHandler(zipFile);
|
||||
} catch (FileNotFoundException e) {
|
||||
invokeExceptionHandler(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
invokeExceptionHandler(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
Log.d("ZipArchive", "stop");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setZipEventHandler(Consumer<String> zipEventHandler) {
|
||||
this.zipEventHandler = zipEventHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgressHandler(Consumer<Integer> progressHandler) {
|
||||
this.progressHandler = progressHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStopEventHandler(Consumer<Boolean> stopEventHandler) {
|
||||
this.stopEventHandler = stopEventHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setErrorEventHandler(Consumer<String> errorEventHandler) {
|
||||
this.errorEventHandler = errorEventHandler;
|
||||
}
|
||||
|
||||
private void invokeZipEventHandler(String path) {
|
||||
if (this.zipEventHandler != null) {
|
||||
this.zipEventHandler.accept(path);
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeProgressHandler(int data) {
|
||||
if (this.progressHandler != null) {
|
||||
this.progressHandler.accept(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeStopEventHandler(boolean hasError) {
|
||||
if (this.stopEventHandler != null) {
|
||||
this.stopEventHandler.accept(hasError);
|
||||
}
|
||||
}
|
||||
|
||||
private void invokeExceptionHandler(String errorMessage) {
|
||||
if (this.errorEventHandler != null) {
|
||||
this.errorEventHandler.accept(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
180
src/android/ZipArchivePlugin.java
Normal file
180
src/android/ZipArchivePlugin.java
Normal file
@ -0,0 +1,180 @@
|
||||
/**
|
||||
* Copyright (c) 2019, kitolog
|
||||
* All rights reserved.
|
||||
* <p>
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
package com.hqsoftwarelab.ziparchive;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaArgs;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class ZipArchivePlugin extends CordovaPlugin {
|
||||
|
||||
Map<String, ZipArchiveAdapter> zipArchiveAdapters = new HashMap<String, ZipArchiveAdapter>();
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
|
||||
if (action.equals("zip")) {
|
||||
this.zip(args, callbackContext);
|
||||
} else if (action.equals("stop")) {
|
||||
this.stop(args, callbackContext);
|
||||
} else {
|
||||
callbackContext.error(String.format("ZipArchivePlugin - invalid action:", action));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void zip(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
|
||||
String adapterKey = args.getString(0);
|
||||
String zipFile = args.getString(1);
|
||||
JSONArray jsonArray = args.getJSONArray(2);
|
||||
ArrayList<String> filesArray = new ArrayList<String>();
|
||||
for (int i = 0, count = jsonArray.length(); i < count; i++) {
|
||||
try {
|
||||
String pathString = jsonArray.getString(i);
|
||||
filesArray.add(pathString);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZipArchiveAdapter zipArchiveAdapter = new ZipArchiveAdapterImpl();
|
||||
//zipArchiveAdapter.setStopEventHandler(new StopEventHandler(adapterKey));
|
||||
//zipArchiveAdapter.setTickHandler(new TickConsumer(adapterKey));
|
||||
zipArchiveAdapter.setErrorEventHandler(new ErrorEventHandler(adapterKey));
|
||||
zipArchiveAdapter.setZipEventHandler(new ZipEventHandler(adapterKey, zipArchiveAdapter, callbackContext));
|
||||
try {
|
||||
zipArchiveAdapter.zip(zipFile, filesArray);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void stop(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
|
||||
String adapterKey = args.getString(0);
|
||||
ZipArchiveAdapter zipArchiveAdapter = this.getZipArchiveAdapter(adapterKey);
|
||||
zipArchiveAdapter.stop();
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
private ZipArchiveAdapter getZipArchiveAdapter(String adapterKey) {
|
||||
if (!this.zipArchiveAdapters.containsKey(adapterKey)) {
|
||||
throw new IllegalStateException("ZipArchive isn't connected.");
|
||||
}
|
||||
return this.zipArchiveAdapters.get(adapterKey);
|
||||
}
|
||||
|
||||
private void dispatchEvent(JSONObject jsonEventObject) {
|
||||
this.webView.sendJavascript(String.format("window.zipArchive.dispatchEvent(%s);", jsonEventObject.toString()));
|
||||
}
|
||||
|
||||
private class StopEventHandler implements Consumer<Boolean> {
|
||||
private String adapterKey;
|
||||
|
||||
public StopEventHandler(String adapterKey) {
|
||||
this.adapterKey = adapterKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Boolean hasError) {
|
||||
zipArchiveAdapters.remove(this.adapterKey);
|
||||
|
||||
try {
|
||||
JSONObject event = new JSONObject();
|
||||
event.put("type", "OnStop");
|
||||
event.put("hasError", hasError.booleanValue());
|
||||
event.put("adapterKey", this.adapterKey);
|
||||
|
||||
dispatchEvent(event);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TickConsumer implements Consumer<Integer> {
|
||||
private String adapterKey;
|
||||
|
||||
public TickConsumer(String adapterKey) {
|
||||
this.adapterKey = adapterKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Integer tick) {
|
||||
try {
|
||||
JSONObject event = new JSONObject();
|
||||
event.put("type", "OnTick");
|
||||
event.put("data", tick);
|
||||
event.put("adapterKey", adapterKey);
|
||||
|
||||
dispatchEvent(event);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ErrorEventHandler implements Consumer<String> {
|
||||
private String adapterKey;
|
||||
|
||||
public ErrorEventHandler(String adapterKey) {
|
||||
this.adapterKey = adapterKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String errorMessage) {
|
||||
try {
|
||||
JSONObject event = new JSONObject();
|
||||
event.put("type", "OnError");
|
||||
event.put("errorMessage", errorMessage);
|
||||
event.put("adapterKey", adapterKey);
|
||||
|
||||
dispatchEvent(event);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ZipEventHandler implements Consumer<String> {
|
||||
private String adapterKey;
|
||||
private ZipArchiveAdapter zipArchiveAdapter;
|
||||
private CallbackContext openCallbackContext;
|
||||
|
||||
public ZipEventHandler(String adapterKey, ZipArchiveAdapter zipArchiveAdapter, CallbackContext openCallbackContext) {
|
||||
this.adapterKey = adapterKey;
|
||||
this.zipArchiveAdapter = zipArchiveAdapter;
|
||||
this.openCallbackContext = openCallbackContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String path) {
|
||||
zipArchiveAdapters.put(adapterKey, zipArchiveAdapter);
|
||||
this.openCallbackContext.success(path);
|
||||
}
|
||||
}
|
||||
}
|
33
src/ios/ZipArchiveAdapter.h
Normal file
33
src/ios/ZipArchiveAdapter.h
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) 2018, kitolog
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ZipArchiveAdapter : NSObject <NSStreamDelegate> {
|
||||
@public
|
||||
}
|
||||
|
||||
- (void)zip:(NSString *)path files:(NSArray<NSString *> *)files;
|
||||
- (void)stop;
|
||||
|
||||
@property (copy) void (^zipEventHandler)(NSString*);
|
||||
@property (copy) void (^zipErrorEventHandler)(NSString*);
|
||||
@property (copy) void (^progressHandler)(NSNumber*);
|
||||
@property (copy) void (^stopEventHandler)(BOOL);
|
||||
@property (copy) void (^errorEventHandler)(NSString*, NSString *);
|
||||
|
||||
@end
|
50
src/ios/ZipArchiveAdapter.m
Normal file
50
src/ios/ZipArchiveAdapter.m
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2018, kitolog
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#import "ZipArchiveAdapter.h"
|
||||
#import "SSZipArchive.h"
|
||||
|
||||
@implementation ZipArchiveAdapter
|
||||
|
||||
- (void)zip:(NSString *)path files:(NSArray<NSString *> *)files {
|
||||
|
||||
NSLog(@"[ZipArchive] ZIP path: %@", path);
|
||||
|
||||
// + (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths
|
||||
BOOL success = [SSZipArchive createZipFileAtPath:path withFilesAtPaths:files];
|
||||
if (success) {
|
||||
NSLog(@"Success zip");
|
||||
self.zipEventHandler(path);
|
||||
} else {
|
||||
NSLog(@"No success zip");
|
||||
self.zipErrorEventHandler(@"Zip process error");
|
||||
}
|
||||
}
|
||||
|
||||
-(void)onProgressTick:(NSNumber *)progress {
|
||||
// tick++;
|
||||
// NSLog(@"[ZIP] On timer tick: %d", tick);
|
||||
// NSNumber* tickNumber = [NSNumber numberWithInteger:tick];
|
||||
// self.progressHandler(tickNumber);
|
||||
}
|
||||
|
||||
- (void)stop {
|
||||
NSLog(@"[ZIP] instance STOP");
|
||||
self.stopEventHandler(FALSE);
|
||||
}
|
||||
|
||||
@end
|
28
src/ios/ZipArchivePlugin.h
Normal file
28
src/ios/ZipArchivePlugin.h
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright (c) 2019, kitolog
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#import <Cordova/CDV.h>
|
||||
|
||||
@interface ZipArchivePlugin : CDVPlugin {
|
||||
NSMutableDictionary *adapterInstances;
|
||||
}
|
||||
|
||||
-(void) zip: (CDVInvokedUrlCommand *) command;
|
||||
-(void) stop: (CDVInvokedUrlCommand *) command;
|
||||
-(void) setOptions: (CDVInvokedUrlCommand *) command;
|
||||
|
||||
@end
|
159
src/ios/ZipArchivePlugin.m
Normal file
159
src/ios/ZipArchivePlugin.m
Normal file
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* Copyright (c) 2019, kitolog
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#import "ZipArchivePlugin.h"
|
||||
#import "ZipArchiveAdapter.h"
|
||||
#import <cordova/CDV.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@implementation ZipArchivePlugin : CDVPlugin
|
||||
|
||||
- (void) zip : (CDVInvokedUrlCommand*) command {
|
||||
|
||||
NSLog(@"[ZipArchive] zip call");
|
||||
NSString *adapterKey = [command.arguments objectAtIndex:0];
|
||||
NSString *path = [command.arguments objectAtIndex:1];
|
||||
NSArray<NSString *> *files = [command.arguments objectAtIndex:2];
|
||||
|
||||
NSLog(@"[ZipArchive] start %@", adapterKey);
|
||||
if (adapterInstances == nil) {
|
||||
self->adapterInstances = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
|
||||
__block ZipArchiveAdapter* adapterInstance = [[ZipArchiveAdapter alloc] init];
|
||||
|
||||
adapterInstance.zipEventHandler = ^ void (NSString *path) {
|
||||
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:path] callbackId:command.callbackId];
|
||||
|
||||
[self->adapterInstances setObject:adapterInstance forKey:adapterKey];
|
||||
|
||||
adapterInstance = nil;
|
||||
};
|
||||
|
||||
adapterInstance.zipErrorEventHandler = ^ void (NSString *error){
|
||||
NSLog(@"[ZipArchive] startErrorEventHandler");
|
||||
[self.commandDelegate
|
||||
sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error]
|
||||
callbackId:command.callbackId];
|
||||
};
|
||||
|
||||
adapterInstance.errorEventHandler = ^ void (NSString *error, NSString *errorType){
|
||||
NSMutableDictionary *errorDictionaryData = [[NSMutableDictionary alloc] init];
|
||||
[errorDictionaryData setObject:@"OnError" forKey:@"type"];
|
||||
[errorDictionaryData setObject:errorType forKey:@"errorType"];
|
||||
[errorDictionaryData setObject:error forKey:@"errorMessage"];
|
||||
[errorDictionaryData setObject:adapterKey forKey:@"adapterKey"];
|
||||
|
||||
[self dispatchEventWithDictionary:errorDictionaryData];
|
||||
};
|
||||
adapterInstance.progressHandler = ^ void (NSNumber* data) {
|
||||
NSMutableDictionary *dataDictionary = [[NSMutableDictionary alloc] init];
|
||||
[dataDictionary setObject:@"OnTick" forKey:@"type"];
|
||||
[dataDictionary setObject:data forKey:@"data"];
|
||||
[dataDictionary setObject:adapterKey forKey:@"adapterKey"];
|
||||
|
||||
[self dispatchEventWithDictionary:dataDictionary];
|
||||
};
|
||||
adapterInstance.stopEventHandler = ^ void (BOOL hasErrors) {
|
||||
NSLog(@"[ZipArchive] stopEventHandler");
|
||||
NSMutableDictionary *closeDictionaryData = [[NSMutableDictionary alloc] init];
|
||||
[closeDictionaryData setObject:@"OnStop" forKey:@"type"];
|
||||
[closeDictionaryData setObject:(hasErrors == TRUE ? @"true": @"false") forKey:@"hasError"];
|
||||
[closeDictionaryData setObject:adapterKey forKey:@"adapterKey"];
|
||||
|
||||
[self dispatchEventWithDictionary:closeDictionaryData];
|
||||
|
||||
[self removeAdapter:adapterKey];
|
||||
};
|
||||
|
||||
[self.commandDelegate runInBackground:^{
|
||||
@try {
|
||||
[adapterInstance zip:path files:files];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
[self.commandDelegate
|
||||
sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:e.reason]
|
||||
callbackId:command.callbackId];
|
||||
|
||||
adapterInstance = nil;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) stop:(CDVInvokedUrlCommand *) command {
|
||||
|
||||
NSString* adapterKey = [command.arguments objectAtIndex:0];
|
||||
|
||||
ZipArchiveAdapter *adapterInstance = [self getAdapter:adapterKey];
|
||||
|
||||
[self.commandDelegate runInBackground:^{
|
||||
@try {
|
||||
// if (adapterInstance != nil) {
|
||||
// [adapterInstance stop];
|
||||
// }else{
|
||||
// NSLog(@"[ZipArchive] Stop: adapterInstance is nil. adapterKey: %@", adapterKey);
|
||||
// }
|
||||
|
||||
[self.commandDelegate
|
||||
sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK]
|
||||
callbackId:command.callbackId];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
[self.commandDelegate
|
||||
sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:e.reason]
|
||||
callbackId:command.callbackId];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) setOptions: (CDVInvokedUrlCommand *) command {
|
||||
}
|
||||
|
||||
- (ZipArchiveAdapter*) getAdapter: (NSString*) adapterKey {
|
||||
ZipArchiveAdapter* adapterInstance = [self->adapterInstances objectForKey:adapterKey];
|
||||
if (adapterInstance == nil) {
|
||||
NSLog(@"[ZipArchive] Cannot find adapterKey: %@. Connection is probably closed.", adapterKey);
|
||||
//NSString *exceptionReason = [NSString stringWithFormat:@"Cannot find adapterKey: %@. Connection is probably closed.", adapterKey];
|
||||
|
||||
//@throw [NSException exceptionWithName:@"IllegalArgumentException" reason:exceptionReason userInfo:nil];
|
||||
}
|
||||
return adapterInstance;
|
||||
}
|
||||
|
||||
- (void) removeAdapter: (NSString*) adapterKey {
|
||||
NSLog(@"[ZipArchive] Removing adapter from storage.");
|
||||
[self->adapterInstances removeObjectForKey:adapterKey];
|
||||
}
|
||||
|
||||
- (BOOL) adapterExists: (NSString*) adapterKey {
|
||||
ZipArchiveAdapter* adapterInstance = [self->adapterInstances objectForKey:adapterKey];
|
||||
return adapterInstance != nil;
|
||||
}
|
||||
|
||||
- (void) dispatchEventWithDictionary: (NSDictionary*) dictionary {
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
|
||||
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
[self dispatchEvent:jsonString];
|
||||
}
|
||||
|
||||
- (void) dispatchEvent: (NSString *) jsonEventString {
|
||||
NSString *jsToEval = [NSString stringWithFormat : @"window.zipArchive.dispatchEvent(%@);", jsonEventString];
|
||||
[self.commandDelegate evalJs:jsToEval];
|
||||
}
|
||||
|
||||
@end
|
25
types/index.d.ts
vendored
Normal file
25
types/index.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
interface Window {
|
||||
nativeTimer: {
|
||||
start(
|
||||
delay: number,
|
||||
interval: number,
|
||||
successCallback: (status: number) => void,
|
||||
errorCallback?: (fileError: NativeTimerError) => void): void;
|
||||
stop(
|
||||
successCallback: (status: number) => void,
|
||||
errorCallback?: (fileError: NativeTimerError) => void): void;
|
||||
checkState(
|
||||
state: string,
|
||||
errorCallback?: (fileError: NativeTimerError) => void): boolean;
|
||||
onTick(): void;
|
||||
onStop(): void;
|
||||
onError(): void;
|
||||
on(eventName: string,
|
||||
callback?: (data: any) => void): void;
|
||||
}
|
||||
}
|
||||
|
||||
interface NativeTimerError {
|
||||
/** Error code */
|
||||
code: number;
|
||||
}
|
203
www/ziparchive.js
Normal file
203
www/ziparchive.js
Normal file
@ -0,0 +1,203 @@
|
||||
/**
|
||||
* Copyright (c) 2018, kitolog
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that the above copyright notice and this paragraph are
|
||||
* duplicated in all such forms and that any documentation,
|
||||
* advertising materials, and other materials related to such
|
||||
* distribution and use acknowledge that the software was developed
|
||||
* by kitolog. The name of the
|
||||
* kitolog may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var PLUGIN_EVENT = "ZIP_ARCHIVE_EVENT";
|
||||
var CORDOVA_SERVICE_NAME = "ZipArchive";
|
||||
|
||||
ZipArchive.State = {};
|
||||
ZipArchive.State[ZipArchive.State.STARTED = 1] = "STARTED";
|
||||
ZipArchive.State[ZipArchive.State.STARTING = 2] = "STARTING";
|
||||
ZipArchive.State[ZipArchive.State.STOPPING = 3] = "STOPPING";
|
||||
ZipArchive.State[ZipArchive.State.STOPPED = 0] = "STOPPED";
|
||||
|
||||
ZipArchive.ErrorType = {};
|
||||
ZipArchive.ErrorType[ZipArchive.ErrorType.GENERAL = 0] = "general";
|
||||
|
||||
function ZipArchive() {
|
||||
this._state = ZipArchive.State.STOPPED;
|
||||
this.timerKey = guid();
|
||||
this.onProgress = function () {
|
||||
console.log('On zip progress');
|
||||
};
|
||||
this.onFinish = function () {
|
||||
console.log('On zip finish');
|
||||
};
|
||||
this.onError = function (e) {
|
||||
console.error('On zip error');
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
this.on = function (eventName, callback) {
|
||||
if ((typeof eventName === 'string') && (typeof callback === 'function')) {
|
||||
switch (eventName) {
|
||||
case 'progress':
|
||||
this.onProgress = function (e) {
|
||||
callback(e);
|
||||
};
|
||||
break;
|
||||
case 'finish':
|
||||
this.onFinish = function (e) {
|
||||
callback(e);
|
||||
};
|
||||
break;
|
||||
case 'error':
|
||||
this.onError = function (e) {
|
||||
callback(e);
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
ZipArchive.prototype.zip = function (path, files, success, error) {
|
||||
success = success || function () {
|
||||
};
|
||||
error = error || function () {
|
||||
};
|
||||
|
||||
if ((typeof path === 'undefined') || path === null) {
|
||||
console.warn('[ZIP] PATH IS EMPTY');
|
||||
return;
|
||||
}
|
||||
|
||||
if ((typeof files === 'undefined') || files === null) {
|
||||
console.warn('[ZIP] FILES ARE EMPTY');
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!this.checkState(ZipArchive.State.STOPPED, error)) {
|
||||
// console.warn('STATE ');
|
||||
// return;
|
||||
// }
|
||||
|
||||
var _that = this;
|
||||
|
||||
function timerEventHandler(event) {
|
||||
var payload = event.payload;
|
||||
if (payload.timerKey !== _that.timerKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (payload.type) {
|
||||
case "OnFinish":
|
||||
_that._state = ZipArchive.State.STOPPED;
|
||||
window.document.removeEventListener(PLUGIN_EVENT, timerEventHandler);
|
||||
_that.onFinish(payload.hasError);
|
||||
break;
|
||||
case "OnProgress":
|
||||
_that.onProgress(payload.data);
|
||||
break;
|
||||
case "OnError":
|
||||
_that.onError(payload);
|
||||
break;
|
||||
default:
|
||||
console.error("ZipArchive: Unknown event type " + payload.type + ", timer key: " + payload.timerKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_that._state = ZipArchive.State.STARTING;
|
||||
|
||||
exec(
|
||||
function () {
|
||||
_that._state = ZipArchive.State.STARTED;
|
||||
window.document.addEventListener(PLUGIN_EVENT, timerEventHandler);
|
||||
success();
|
||||
},
|
||||
function (errorMessage) {
|
||||
_that._state = ZipArchive.State.STOPPED;
|
||||
error(errorMessage);
|
||||
},
|
||||
CORDOVA_SERVICE_NAME,
|
||||
"zip",
|
||||
[
|
||||
this.timerKey,
|
||||
path,
|
||||
files
|
||||
]);
|
||||
};
|
||||
|
||||
ZipArchive.prototype.stop = function (success, error) {
|
||||
|
||||
success = success || function () {
|
||||
};
|
||||
error = error || function () {
|
||||
};
|
||||
|
||||
if (!this.checkState(ZipArchive.State.STARTED, error)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._state = ZipArchive.State.STOPPING;
|
||||
|
||||
exec(
|
||||
success,
|
||||
error,
|
||||
CORDOVA_SERVICE_NAME,
|
||||
"stop",
|
||||
[this.timerKey]);
|
||||
};
|
||||
|
||||
Object.defineProperty(ZipArchive.prototype, "state", {
|
||||
get: function () {
|
||||
return this._state;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
ZipArchive.prototype.checkState = function (requiredState, errorCallback) {
|
||||
var state = this._state;
|
||||
if (state != requiredState) {
|
||||
errorCallback = errorCallback || function () {
|
||||
};
|
||||
window.setTimeout(function () {
|
||||
errorCallback("Invalid operation for this timer state: " + ZipArchive.State[state]);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
ZipArchive.dispatchEvent = function (event) {
|
||||
var eventReceive = document.createEvent('Events');
|
||||
eventReceive.initEvent(PLUGIN_EVENT, true, true);
|
||||
eventReceive.payload = event;
|
||||
|
||||
document.dispatchEvent(eventReceive);
|
||||
};
|
||||
|
||||
var guid = (function () {
|
||||
function s4() {
|
||||
return Math.floor((1 + Math.random()) * 0x10000)
|
||||
.toString(16)
|
||||
.substring(1);
|
||||
}
|
||||
|
||||
return function () {
|
||||
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
|
||||
s4() + '-' + s4() + s4() + s4();
|
||||
};
|
||||
})();
|
||||
|
||||
module.exports = ZipArchive;
|
Loading…
Reference in New Issue
Block a user