Update LICENSE, README.md, and 13 more files...
This commit is contained in:
15
LICENSE
Normal file
15
LICENSE
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
The Apache License v2.0
|
||||||
|
|
||||||
|
Copyright 2021 Incentro
|
||||||
|
|
||||||
|
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.
|
||||||
17
README.md
Normal file
17
README.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
## BackgroundTask
|
||||||
|
[Call a nanoflow when app is in background]
|
||||||
|
|
||||||
|
## Features
|
||||||
|
[feature highlights]
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
[step by step instructions]
|
||||||
|
|
||||||
|
## Demo project
|
||||||
|
[link to sandbox]
|
||||||
|
|
||||||
|
## Issues, suggestions and feature requests
|
||||||
|
[link to GitHub issues]
|
||||||
|
|
||||||
|
## Development and contribution
|
||||||
|
[specify contribute]
|
||||||
BIN
dist/1.0.0/incentro.BackgroundTask.mpk
vendored
Normal file
BIN
dist/1.0.0/incentro.BackgroundTask.mpk
vendored
Normal file
Binary file not shown.
17
dist/tmp/widgets/BackgroundTask.xml
vendored
Normal file
17
dist/tmp/widgets/BackgroundTask.xml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<widget id="incentro.backgroundtask.BackgroundTask" pluginWidget="true" needsEntityContext="true" offlineCapable="true"
|
||||||
|
supportedPlatform="Native"
|
||||||
|
xmlns="http://www.mendix.com/widget/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.mendix.com/widget/1.0/ ../node_modules/mendix/custom_widget.xsd">
|
||||||
|
<name>Background Task</name>
|
||||||
|
<description>Call a nanoflow when app is in background using the BackgroundFetch API on Android and iOS</description>
|
||||||
|
<icon/>
|
||||||
|
<properties>
|
||||||
|
<propertyGroup caption="Background Task">
|
||||||
|
<property key="backgroundFlow" type="action" required="false">
|
||||||
|
<caption>Backgroundtask</caption>
|
||||||
|
<description>Action to perform in the background (only nanoflow is allowed, no opening pages etc.)</description>
|
||||||
|
</property>
|
||||||
|
</propertyGroup>
|
||||||
|
</properties>
|
||||||
|
</widget>
|
||||||
288
dist/tmp/widgets/incentro/backgroundtask/BackgroundTask.js
vendored
Normal file
288
dist/tmp/widgets/incentro/backgroundtask/BackgroundTask.js
vendored
Normal file
@@ -0,0 +1,288 @@
|
|||||||
|
module.exports =
|
||||||
|
/******/ (function(modules) { // webpackBootstrap
|
||||||
|
/******/ // The module cache
|
||||||
|
/******/ var installedModules = {};
|
||||||
|
/******/
|
||||||
|
/******/ // The require function
|
||||||
|
/******/ function __webpack_require__(moduleId) {
|
||||||
|
/******/
|
||||||
|
/******/ // Check if module is in cache
|
||||||
|
/******/ if(installedModules[moduleId]) {
|
||||||
|
/******/ return installedModules[moduleId].exports;
|
||||||
|
/******/ }
|
||||||
|
/******/ // Create a new module (and put it into the cache)
|
||||||
|
/******/ var module = installedModules[moduleId] = {
|
||||||
|
/******/ i: moduleId,
|
||||||
|
/******/ l: false,
|
||||||
|
/******/ exports: {}
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // Execute the module function
|
||||||
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||||
|
/******/
|
||||||
|
/******/ // Flag the module as loaded
|
||||||
|
/******/ module.l = true;
|
||||||
|
/******/
|
||||||
|
/******/ // Return the exports of the module
|
||||||
|
/******/ return module.exports;
|
||||||
|
/******/ }
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ // expose the modules object (__webpack_modules__)
|
||||||
|
/******/ __webpack_require__.m = modules;
|
||||||
|
/******/
|
||||||
|
/******/ // expose the module cache
|
||||||
|
/******/ __webpack_require__.c = installedModules;
|
||||||
|
/******/
|
||||||
|
/******/ // define getter function for harmony exports
|
||||||
|
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||||
|
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||||
|
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
||||||
|
/******/ }
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // define __esModule on exports
|
||||||
|
/******/ __webpack_require__.r = function(exports) {
|
||||||
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
||||||
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||||
|
/******/ }
|
||||||
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // create a fake namespace object
|
||||||
|
/******/ // mode & 1: value is a module id, require it
|
||||||
|
/******/ // mode & 2: merge all properties of value into the ns
|
||||||
|
/******/ // mode & 4: return value when already ns object
|
||||||
|
/******/ // mode & 8|1: behave like require
|
||||||
|
/******/ __webpack_require__.t = function(value, mode) {
|
||||||
|
/******/ if(mode & 1) value = __webpack_require__(value);
|
||||||
|
/******/ if(mode & 8) return value;
|
||||||
|
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
||||||
|
/******/ var ns = Object.create(null);
|
||||||
|
/******/ __webpack_require__.r(ns);
|
||||||
|
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
||||||
|
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
||||||
|
/******/ return ns;
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||||
|
/******/ __webpack_require__.n = function(module) {
|
||||||
|
/******/ var getter = module && module.__esModule ?
|
||||||
|
/******/ function getDefault() { return module['default']; } :
|
||||||
|
/******/ function getModuleExports() { return module; };
|
||||||
|
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||||
|
/******/ return getter;
|
||||||
|
/******/ };
|
||||||
|
/******/
|
||||||
|
/******/ // Object.prototype.hasOwnProperty.call
|
||||||
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||||
|
/******/
|
||||||
|
/******/ // __webpack_public_path__
|
||||||
|
/******/ __webpack_require__.p = "";
|
||||||
|
/******/
|
||||||
|
/******/
|
||||||
|
/******/ // Load entry module and return exports
|
||||||
|
/******/ return __webpack_require__(__webpack_require__.s = "./src/BackgroundTask.tsx");
|
||||||
|
/******/ })
|
||||||
|
/************************************************************************/
|
||||||
|
/******/ ({
|
||||||
|
|
||||||
|
/***/ "./node_modules/@babel/runtime/helpers/classCallCheck.js":
|
||||||
|
/*!***************************************************************!*\
|
||||||
|
!*** ./node_modules/@babel/runtime/helpers/classCallCheck.js ***!
|
||||||
|
\***************************************************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports) {
|
||||||
|
|
||||||
|
function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}module.exports=_classCallCheck;module.exports["default"]=module.exports,module.exports.__esModule=true;
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./node_modules/@babel/runtime/helpers/createClass.js":
|
||||||
|
/*!************************************************************!*\
|
||||||
|
!*** ./node_modules/@babel/runtime/helpers/createClass.js ***!
|
||||||
|
\************************************************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports) {
|
||||||
|
|
||||||
|
function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}module.exports=_createClass;module.exports["default"]=module.exports,module.exports.__esModule=true;
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js":
|
||||||
|
/*!**********************************************************************!*\
|
||||||
|
!*** ./node_modules/@babel/runtime/helpers/interopRequireDefault.js ***!
|
||||||
|
\**********************************************************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports) {
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj};}module.exports=_interopRequireDefault;module.exports["default"]=module.exports,module.exports.__esModule=true;
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./node_modules/react-native-background-fetch/index.js":
|
||||||
|
/*!*************************************************************!*\
|
||||||
|
!*** ./node_modules/react-native-background-fetch/index.js ***!
|
||||||
|
\*************************************************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
var _interopRequireDefault=__webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _classCallCheck2=_interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js"));var _createClass2=_interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js"));var _reactNative=__webpack_require__(/*! react-native */ "react-native");var RNBackgroundFetch=_reactNative.NativeModules.RNBackgroundFetch;var EventEmitter=new _reactNative.NativeEventEmitter(RNBackgroundFetch);var EVENT_FETCH="fetch";var TAG="RNBackgroundFetch";var EVENTS=["fetch"];var STATUS_RESTRICTED=0;var STATUS_DENIED=1;var STATUS_AVAILABLE=2;var NETWORK_TYPE_NONE=0;var NETWORK_TYPE_ANY=1;var NETWORK_TYPE_UNMETERED=2;var NETWORK_TYPE_NOT_ROAMING=3;var NETWORK_TYPE_CELLULAR=4;var BackgroundFetch=function(){function BackgroundFetch(){(0,_classCallCheck2.default)(this,BackgroundFetch);}(0,_createClass2.default)(BackgroundFetch,null,[{key:"STATUS_RESTRICTED",get:function get(){return STATUS_RESTRICTED;}},{key:"STATUS_DENIED",get:function get(){return STATUS_DENIED;}},{key:"STATUS_AVAILABLE",get:function get(){return STATUS_AVAILABLE;}},{key:"NETWORK_TYPE_NONE",get:function get(){return NETWORK_TYPE_NONE;}},{key:"NETWORK_TYPE_ANY",get:function get(){return NETWORK_TYPE_ANY;}},{key:"NETWORK_TYPE_UNMETERED",get:function get(){return NETWORK_TYPE_UNMETERED;}},{key:"NETWORK_TYPE_NOT_ROAMING",get:function get(){return NETWORK_TYPE_NOT_ROAMING;}},{key:"NETWORK_TYPE_CELLULAR",get:function get(){return NETWORK_TYPE_CELLULAR;}},{key:"configure",value:function configure(config,onEvent,onTimeout){if(typeof onEvent!=='function'){throw"BackgroundFetch requires an event callback at 2nd argument";}if(typeof onTimeout!=='function'){console.warn("[BackgroundFetch] configure: You did not provide a 3rd argument onTimeout callback. This callback is a signal from the OS that your allowed background time is about to expire. Use this callback to finish what you're doing and immediately call BackgroundFetch.finish(taskId)");onTimeout=function onTimeout(taskId){console.warn('[BackgroundFetch] default onTimeout callback fired. You should provide your own onTimeout callbcak to .configure(options, onEvent, onTimeout)');BackgroundFetch.finish(taskId);};}EventEmitter.removeAllListeners(EVENT_FETCH);EventEmitter.addListener(EVENT_FETCH,function(event){if(!event.timeout){onEvent(event.taskId);}else{onTimeout(event.taskId);}});config=config||{};return new Promise(function(resolve,reject){var success=function success(status){resolve(status);};var failure=function failure(status){reject(status);};RNBackgroundFetch.configure(config,success,failure);});}},{key:"scheduleTask",value:function scheduleTask(config){return new Promise(function(resolve,reject){var success=function success(_success){resolve(_success);};var failure=function failure(error){reject(error);};RNBackgroundFetch.scheduleTask(config,success,failure);});}},{key:"registerHeadlessTask",value:function registerHeadlessTask(task){_reactNative.AppRegistry.registerHeadlessTask("BackgroundFetch",function(){return task;});}},{key:"start",value:function start(){return new Promise(function(resolve,reject){var success=function success(status){resolve(status);};var failure=function failure(error){reject(error);};RNBackgroundFetch.start(success,failure);});}},{key:"stop",value:function stop(taskId){return new Promise(function(resolve,reject){var success=function success(_success2){resolve(_success2);};var failure=function failure(error){reject(error);};RNBackgroundFetch.stop(taskId,success,failure);});}},{key:"finish",value:function finish(taskId){RNBackgroundFetch.finish(taskId);}},{key:"status",value:function status(callback){if(typeof callback==='function'){return RNBackgroundFetch.status(callback);}return new Promise(function(resolve,reject){RNBackgroundFetch.status(resolve);});}}]);return BackgroundFetch;}();exports.default=BackgroundFetch;
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./src/BackgroundTask.tsx":
|
||||||
|
/*!********************************!*\
|
||||||
|
!*** ./src/BackgroundTask.tsx ***!
|
||||||
|
\********************************/
|
||||||
|
/*! exports provided: BackgroundTask */
|
||||||
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BackgroundTask", function() { return BackgroundTask; });
|
||||||
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
|
||||||
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
||||||
|
/* harmony import */ var react_native__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-native */ "react-native");
|
||||||
|
/* harmony import */ var react_native__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_native__WEBPACK_IMPORTED_MODULE_1__);
|
||||||
|
/* harmony import */ var react_native_background_fetch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react-native-background-fetch */ "./node_modules/react-native-background-fetch/index.js");
|
||||||
|
/* harmony import */ var react_native_background_fetch__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react_native_background_fetch__WEBPACK_IMPORTED_MODULE_2__);
|
||||||
|
var __extends = (undefined && undefined.__extends) || (function () {
|
||||||
|
var extendStatics = function (d, b) {
|
||||||
|
extendStatics = Object.setPrototypeOf ||
|
||||||
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||||
|
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||||
|
return extendStatics(d, b);
|
||||||
|
};
|
||||||
|
return function (d, b) {
|
||||||
|
extendStatics(d, b);
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var BackgroundTask = /** @class */ (function (_super) {
|
||||||
|
__extends(BackgroundTask, _super);
|
||||||
|
function BackgroundTask(props) {
|
||||||
|
return _super.call(this, props) || this;
|
||||||
|
}
|
||||||
|
BackgroundTask.prototype.render = function () {
|
||||||
|
return (
|
||||||
|
//Render an empty view so widget can be used in Mendix modeler.
|
||||||
|
Object(react__WEBPACK_IMPORTED_MODULE_0__["createElement"])(react_native__WEBPACK_IMPORTED_MODULE_1__["View"], null));
|
||||||
|
};
|
||||||
|
BackgroundTask.prototype.componentDidMount = function () {
|
||||||
|
// Initialize BackgroundFetch ONLY ONCE when component mounts.
|
||||||
|
this.initBackgroundFetch();
|
||||||
|
};
|
||||||
|
BackgroundTask.prototype.initBackgroundFetch = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var onEvent, onTimeout;
|
||||||
|
var _this = this;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
console.log('Configuring BackgroundFetch');
|
||||||
|
onEvent = function (taskId) { return __awaiter(_this, void 0, void 0, function () {
|
||||||
|
var _a;
|
||||||
|
return __generator(this, function (_b) {
|
||||||
|
console.log('[BackgroundFetch] task: ', taskId);
|
||||||
|
// Execute nanoflow
|
||||||
|
(_a = this.props.backgroundFlow) === null || _a === void 0 ? void 0 : _a.execute();
|
||||||
|
// IMPORTANT: You must signal to the OS that your task is complete.
|
||||||
|
react_native_background_fetch__WEBPACK_IMPORTED_MODULE_2___default.a.finish(taskId);
|
||||||
|
return [2 /*return*/];
|
||||||
|
});
|
||||||
|
}); };
|
||||||
|
onTimeout = function (taskId) { return __awaiter(_this, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
console.warn('[BackgroundFetch] TIMEOUT task: ', taskId);
|
||||||
|
react_native_background_fetch__WEBPACK_IMPORTED_MODULE_2___default.a.finish(taskId);
|
||||||
|
return [2 /*return*/];
|
||||||
|
});
|
||||||
|
}); };
|
||||||
|
// Initialize BackgroundFetch only once when component mounts.
|
||||||
|
return [4 /*yield*/, react_native_background_fetch__WEBPACK_IMPORTED_MODULE_2___default.a.configure({
|
||||||
|
minimumFetchInterval: 30,
|
||||||
|
enableHeadless: true,
|
||||||
|
startOnBoot: true,
|
||||||
|
stopOnTerminate: false //Stop task when app is killed, Android only
|
||||||
|
}, onEvent, onTimeout)];
|
||||||
|
case 1:
|
||||||
|
// Initialize BackgroundFetch only once when component mounts.
|
||||||
|
_a.sent();
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return BackgroundTask;
|
||||||
|
}(react__WEBPACK_IMPORTED_MODULE_0__["Component"]));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "react":
|
||||||
|
/*!************************!*\
|
||||||
|
!*** external "react" ***!
|
||||||
|
\************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports) {
|
||||||
|
|
||||||
|
module.exports = require("react");
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "react-native":
|
||||||
|
/*!*******************************!*\
|
||||||
|
!*** external "react-native" ***!
|
||||||
|
\*******************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports) {
|
||||||
|
|
||||||
|
module.exports = require("react-native");
|
||||||
|
|
||||||
|
/***/ })
|
||||||
|
|
||||||
|
/******/ });
|
||||||
|
//# sourceMappingURL=BackgroundTask.js.map
|
||||||
1
dist/tmp/widgets/incentro/backgroundtask/BackgroundTask.js.map
vendored
Normal file
1
dist/tmp/widgets/incentro/backgroundtask/BackgroundTask.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
11
dist/tmp/widgets/package.xml
vendored
Normal file
11
dist/tmp/widgets/package.xml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<package xmlns="http://www.mendix.com/package/1.0/">
|
||||||
|
<clientModule name="BackgroundTask" version="1.0.0" xmlns="http://www.mendix.com/clientModule/1.0/">
|
||||||
|
<widgetFiles>
|
||||||
|
<widgetFile path="BackgroundTask.xml"/>
|
||||||
|
</widgetFiles>
|
||||||
|
<files>
|
||||||
|
<file path="incentro/backgroundtask"/>
|
||||||
|
</files>
|
||||||
|
</clientModule>
|
||||||
|
</package>
|
||||||
20623
package-lock.json
generated
Normal file
20623
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
package.json
Normal file
34
package.json
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"name": "backgroundtask",
|
||||||
|
"widgetName": "BackgroundTask",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Call a nanoflow when app is in background",
|
||||||
|
"copyright": "2021 Incentro",
|
||||||
|
"author": "Bart Onstee",
|
||||||
|
"config": {
|
||||||
|
"projectPath": "../..//"
|
||||||
|
},
|
||||||
|
"packagePath": "incentro",
|
||||||
|
"scripts": {
|
||||||
|
"start": "npm run dev",
|
||||||
|
"build": "pluggable-widgets-tools build:native",
|
||||||
|
"dev": "pluggable-widgets-tools start:native",
|
||||||
|
"lint": "pluggable-widgets-tools lint",
|
||||||
|
"lint:fix": "pluggable-widgets-tools lint:fix",
|
||||||
|
"prerelease": "npm run lint",
|
||||||
|
"release": "pluggable-widgets-tools release:native"
|
||||||
|
},
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/Bart Onstee/backgroundtask/issues"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@mendix/pluggable-widgets-tools": "^8.14.0",
|
||||||
|
"@types/big.js": "^4.0.5",
|
||||||
|
"@types/react": "~16.9.0",
|
||||||
|
"@types/react-native": "~0.61.23"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"react-native-background-fetch": "^4.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
prettier.config.js
Normal file
5
prettier.config.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
const base = require("@mendix/pluggable-widgets-tools/configs/prettier.base.json");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
...base
|
||||||
|
};
|
||||||
60
src/BackgroundTask.tsx
Normal file
60
src/BackgroundTask.tsx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import { Component, ReactNode, createElement } from "react";
|
||||||
|
import { View } from "react-native";
|
||||||
|
import BackgroundFetch from "react-native-background-fetch";
|
||||||
|
|
||||||
|
import { Style } from "@mendix/pluggable-widgets-tools";
|
||||||
|
|
||||||
|
import { BackgroundTaskProps } from "../typings/BackgroundTaskProps";
|
||||||
|
|
||||||
|
export interface CustomStyle extends Style {
|
||||||
|
}
|
||||||
|
|
||||||
|
export class BackgroundTask extends Component<BackgroundTaskProps<CustomStyle>> {
|
||||||
|
constructor(props: BackgroundTaskProps<CustomStyle>){
|
||||||
|
super(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
render(): ReactNode {
|
||||||
|
return (
|
||||||
|
//Render an empty view so widget can be used in Mendix modeler.
|
||||||
|
<View></View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
// Initialize BackgroundFetch ONLY ONCE when component mounts.
|
||||||
|
this.initBackgroundFetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
async initBackgroundFetch() {
|
||||||
|
console.log('Configuring BackgroundFetch')
|
||||||
|
// BackgroundFetch event handler.
|
||||||
|
const onEvent = async (taskId: string | undefined) => {
|
||||||
|
console.log('[BackgroundFetch] task: ', taskId);
|
||||||
|
// Execute nanoflow
|
||||||
|
this.props.backgroundFlow?.execute();
|
||||||
|
// IMPORTANT: You must signal to the OS that your task is complete.
|
||||||
|
BackgroundFetch.finish(taskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout callback is executed when your Task has exceeded its allowed running-time.
|
||||||
|
// You must stop what you're doing immediately BackgorundFetch.finish(taskId) or else fetch will never be executed again by OS.
|
||||||
|
const onTimeout = async (taskId: any) => {
|
||||||
|
console.warn('[BackgroundFetch] TIMEOUT task: ', taskId);
|
||||||
|
BackgroundFetch.finish(taskId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize BackgroundFetch only once when component mounts.
|
||||||
|
await BackgroundFetch.configure(
|
||||||
|
{
|
||||||
|
minimumFetchInterval: 30, //Minimum interval time for schedule. Can be (much) longer.
|
||||||
|
enableHeadless: true, //HeadlessJS mode for Android only
|
||||||
|
startOnBoot: true, //Start when device starts, Android only
|
||||||
|
stopOnTerminate: false //Stop task when app is killed, Android only
|
||||||
|
},
|
||||||
|
onEvent,
|
||||||
|
onTimeout,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
17
src/BackgroundTask.xml
Normal file
17
src/BackgroundTask.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<widget id="incentro.backgroundtask.BackgroundTask" pluginWidget="true" needsEntityContext="true" offlineCapable="true"
|
||||||
|
supportedPlatform="Native"
|
||||||
|
xmlns="http://www.mendix.com/widget/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.mendix.com/widget/1.0/ ../node_modules/mendix/custom_widget.xsd">
|
||||||
|
<name>Background Task</name>
|
||||||
|
<description>Call a nanoflow when app is in background using the BackgroundFetch API on Android and iOS</description>
|
||||||
|
<icon/>
|
||||||
|
<properties>
|
||||||
|
<propertyGroup caption="Background Task">
|
||||||
|
<property key="backgroundFlow" type="action" required="false">
|
||||||
|
<caption>Backgroundtask</caption>
|
||||||
|
<description>Action to perform in the background (only nanoflow is allowed, no opening pages etc.)</description>
|
||||||
|
</property>
|
||||||
|
</propertyGroup>
|
||||||
|
</properties>
|
||||||
|
</widget>
|
||||||
11
src/package.xml
Normal file
11
src/package.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<package xmlns="http://www.mendix.com/package/1.0/">
|
||||||
|
<clientModule name="BackgroundTask" version="1.0.0" xmlns="http://www.mendix.com/clientModule/1.0/">
|
||||||
|
<widgetFiles>
|
||||||
|
<widgetFile path="BackgroundTask.xml"/>
|
||||||
|
</widgetFiles>
|
||||||
|
<files>
|
||||||
|
<file path="incentro/backgroundtask"/>
|
||||||
|
</files>
|
||||||
|
</clientModule>
|
||||||
|
</package>
|
||||||
3
tsconfig.json
Normal file
3
tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "./node_modules/@mendix/pluggable-widgets-tools/configs/tsconfig.base.json"
|
||||||
|
}
|
||||||
18
typings/BackgroundTaskProps.d.ts
vendored
Normal file
18
typings/BackgroundTaskProps.d.ts
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* This file was generated from BackgroundTask.xml
|
||||||
|
* WARNING: All changes made to this file will be overwritten
|
||||||
|
* @author Mendix UI Content Team
|
||||||
|
*/
|
||||||
|
import { ActionValue } from "mendix";
|
||||||
|
|
||||||
|
export interface BackgroundTaskProps<Style> {
|
||||||
|
name: string;
|
||||||
|
style: Style[];
|
||||||
|
backgroundFlow?: ActionValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackgroundTaskPreviewProps {
|
||||||
|
class: string;
|
||||||
|
style: string;
|
||||||
|
backgroundFlow: {} | null;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user