Stefan Huber

cordova changes

node_modules/
.vscode/
.tmp/
......
......@@ -13,3 +13,12 @@ Within the main process bsync needs to be integrated an initiated.
import {Bsync} from 'bsync';
Bsync.init(ipcMain, filePath);
# Testing (Browser)
`npm test`
# Testing (Cordova)
......
......@@ -15,9 +15,9 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
'./node_modules/rxjs/bundles/Rx.min.js' ,
'./node_modules/pouchdb/dist/pouchdb.min.js' ,
'./.tmp/browser-test.js'
'../node_modules/rxjs/bundles/Rx.min.js' ,
'../node_modules/pouchdb/dist/pouchdb.min.js' ,
'../.tmp/browser-test.js'
],
......
import typescript from 'rollup-plugin-typescript';
export default {
moduleName : 'bsync',
entry: './spec/cordova-test.ts',
dest: './.tmp/cordova-test-build.js',
format: 'cjs',
plugins: [
typescript()
]
};
\ No newline at end of file
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var events = require('events');
var rxjs = require('rxjs');
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('events'), require('rxjs')) :
typeof define === 'function' && define.amd ? define(['exports', 'events', 'rxjs'], factory) :
(factory((global.bsync = global.bsync || {}),global.events,global.rxjs));
}(this, (function (exports,events,rxjs) { 'use strict';
function __extends(d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
......@@ -40,6 +39,28 @@ var ElectronFileHandler = (function () {
return ElectronFileHandler;
}());
var CordovaDownloader = (function () {
function CordovaDownloader() {
}
CordovaDownloader.prototype.download = function (source, target) {
return Rx.Observable.create(function (subscriber) {
if (!window['FileTransfer']) {
subscriber.error("Cordova FileTransfer object undefined");
}
var fileTransfer = new window['FileTransfer']();
fileTransfer.onprogress = function (progress) {
subscriber.next(progress.total / progress.loaded);
};
fileTransfer.download(source, target, function (entry) {
subscriber.complete();
}, function (error) {
subscriber.error(error);
}, true);
});
};
return CordovaDownloader;
}());
var Util = (function () {
function Util() {
}
......@@ -277,6 +298,9 @@ var ServiceLocator = (function () {
if (environment === ENV_ELECTRON) {
return new ElectronFileHandler(window['require']('electron').ipcRenderer);
}
if (environment === ENV_CORDOVA) {
return new CordovaDownloader();
}
return null;
};
ServiceLocator.getFileReplicator = function () {
......@@ -362,4 +386,8 @@ exports.ENV_ELECTRON = ENV_ELECTRON;
exports.ENV_CORDOVA = ENV_CORDOVA;
exports.ENV_UNKNOWN = ENV_UNKNOWN;
exports.ServiceLocator = ServiceLocator;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=browser-build.js.map
......
This diff is collapsed. Click to expand it.
......@@ -5,14 +5,14 @@
"main": "dist/browser-build.js",
"scripts": {
"build": "npm run build:node && npm run build:browser",
"build:node": "rollup -c ./rollup.config.node.js",
"build:browser": "rollup --config ./rollup.config.browser.js",
"build:node": "rollup -c ./config/rollup.config.node.js",
"build:browser": "rollup --config ./config/rollup.config.browser.js",
"pretest": "scripts/before-test.sh",
"posttest": "scripts/after-test.sh",
"test": "npm run test:node && npm run test:browser",
"test:node": "rollup --config ./rollup.config.node-test.js && jasmine",
"test:browser": "rollup --config ./rollup.config.browser-test.js && karma start",
"test:cordova": "npm run build:browser && scripts/prepare-cordova-test.sh"
"test:node": "rollup --config ./config/rollup.config.node-test.js && jasmine",
"test:browser": "rollup --config ./config/rollup.config.browser-test.js && karma start ./config/karma.conf.js",
"test:cordova": "./scripts/prepare-cordova-test.sh"
},
"author": "",
"license": "ISC",
......
......@@ -5,20 +5,26 @@ PLATFORM=${2:-android}
echo "cordova $COMMAND $PLATFORM"
rollup --config ./config/rollup.config.cordova-test.js
cp ./spec/cordova-plugin-test/plugin.xml .tmp/plugin.xml
cp ./node_modules/rxjs/bundles/Rx.min.js .tmp/Rx.min.js
cd ..
rm -r ./bysnc-client-test-app
./bsync-client/node_modules/.bin/cordova create bysnc-client-test-app
cd ./bysnc-client-test-app
rm -r ./bsync-client-test-app
./bsync-client/node_modules/.bin/cordova create bsync-client-test-app
cd ./bsync-client-test-app
../bsync-client/node_modules/.bin/cordova platform add $PLATFORM
../bsync-client/node_modules/.bin/cordova plugin add ../bsync-client
../bsync-client/node_modules/.bin/cordova plugin add ../bsync-client/spec/cordova
../bsync-client/node_modules/.bin/cordova plugin add ../bsync-client/.tmp
../bsync-client/node_modules/.bin/cordova plugin add cordova-plugin-test-framework
sed -i 's/index\.html/cdvtests\/index\.html/g' ./config.xml
if [ $COMMAND == "run" ]; then
../bsync-client/node_modules/.bin/cordova run $PLATFORM
cordova run $PLATFORM
else
../bsync-client/node_modules/.bin/cordova emulate $PLATFORM
cordova emulate $PLATFORM
fi
rm -R ../bsync-client/.tmp
\ No newline at end of file
......
<!doctype html>
<!--
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.
-->
<html>
<head>
<!--
Inject CSP
If not hosted in mobilespec, the injection script will likely not
exist. It would be up to the hosting app to provide the named
script to setup CSP as desired.
-->
<script type="text/javascript" src="../csp-incl.js"></script>
<title>Cordova tests</title>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<link rel="stylesheet" type="text/css" href="cdvtests/topcoat-0.7.5/css/topcoat-mobile-light.min.css">
<link rel="stylesheet" type="text/css" href="cdvtests/jasmine-2.4.1/jasmine.css" media="screen">
<link rel="stylesheet" type="text/css" href="cdvtests/main.css" media="screen">
<script type="text/javascript" src="cdvtests/jasmine-2.4.1/jasmine.js"></script>
<script type="text/javascript" src="cdvtests/jasmine-2.4.1/jasmine-html.js"></script>
<script type="text/javascript" src="cdvtests/jasmine-medic.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<!-- App scripts -->
<script type="text/javascript" src="cdvtests/main-bootstrap.js"></script>
</head>
<body>
<div id='title'></div>
<div id='middle'>
<div id='buttons'></div>
<div id='content'></div>
</div>
<div id='log'>
<div id='log--title'>Log</div>
<div id='log--content'></div>
</div>
</body>
</html>
\ No newline at end of file
......@@ -8,7 +8,11 @@
<name>bsync cordova test</name>
<license>Apache 2.0 License</license>
<js-module src="cordova-test.spec.js" name="tests">
<js-module src="Rx.min.js" name="Rx">
<clobbers target="Rx" />
</js-module>
<js-module src="cordova-test-build.js" name="tests">
</js-module>
</plugin>
\ No newline at end of file
......
exports.defineAutoTests = function() {
import { CordovaDownloader } from '../src/file-handler/cordova-file-handler';
declare var cordova;
console.log(bsync);
exports.defineAutoTests = function() {
describe("Cordova tests", () => {
/*
describe("Cordova downloader", () => {
let downloader = new CordovaDownloader();
it("should download sample image from https source and store with new name", (done) => {
let source = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/FullMoon2010.jpg/800px-FullMoon2010.jpg";
let target = "cdvfile://full-moon.jpg";
let target = cordova.file.dataDirectory + "full-moon.jpg";
let lastProgress = 0;
downloader.download(source, target)
......@@ -18,18 +20,22 @@ exports.defineAutoTests = function() {
expect(progress).toBeGreaterThan(lastProgress);
lastProgress = progress;
} ,
(error:any) => {} ,
(error:any) => {
fail();
} ,
() => {
expect(lastProgress).toEqual(1);
// expect(fs.existsSync(target)).toBeTruthy();
done();
window['resolveLocalFileSystemURL'](target, (entry:any) => {
expect(entry.isFile).toBeTruthy();
expect(entry.name).toEqual("full-moon.jpg");
done();
});
}
);
});
*/
});
});
};
\ No newline at end of file
......
......@@ -14,7 +14,7 @@ export class CordovaDownloader implements FileHandler {
let fileTransfer = new window['FileTransfer']();
fileTransfer.onprogress = (progress:ProgressEvent) => {
subscriber.next(progress.total / progress.loaded);
subscriber.next(progress.loaded / progress.total);
};
fileTransfer.download(
......
import { Observable, Subscriber } from 'rxjs';
import { Observable } from 'rxjs/Observable';
import { Subscriber } from 'rxjs/Subscriber';
import { FileHandler } from '../api/file-handler';
import * as http from 'http';
import * as https from 'https';
......
import {FileHandler} from './api/file-handler';
import {ElectronFileHandler} from './file-handler/electron-file-handler';
import {CordovaDownloader} from './file-handler/cordova-file-handler';
import {FileReplicator} from './file-replicator';
import {
Config,
......@@ -53,6 +54,10 @@ export class ServiceLocator {
if (environment === ENV_ELECTRON) {
return new ElectronFileHandler(window['require']('electron').ipcRenderer);
}
if (environment === ENV_CORDOVA) {
return new CordovaDownloader();
}
return null;
}
......